]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # This file is used to create/update/query/erase table for data models\r | |
3 | #\r | |
40d841f6 LG |
4 | # Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>\r |
5 | # This program and the accompanying materials\r | |
30fdf114 LG |
6 | # are licensed and made available under the terms and conditions of the BSD License\r |
7 | # which accompanies this distribution. The full text of the license may be found at\r | |
8 | # http://opensource.org/licenses/bsd-license.php\r | |
9 | #\r | |
10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | #\r | |
13 | \r | |
14 | ##\r | |
15 | # Import Modules\r | |
16 | #\r | |
17 | import Common.EdkLogger as EdkLogger\r | |
18 | import CommonDataClass.DataClass as DataClass\r | |
19 | from Table import Table\r | |
20 | from Common.String import ConvertToSqlString\r | |
21 | \r | |
22 | ## TableDataModel\r | |
23 | #\r | |
24 | # This class defined a table used for data model\r | |
25 | # \r | |
26 | # @param object: Inherited from object class\r | |
27 | #\r | |
28 | #\r | |
29 | class TableDataModel(Table):\r | |
30 | def __init__(self, Cursor):\r | |
31 | Table.__init__(self, Cursor)\r | |
32 | self.Table = 'DataModel'\r | |
33 | \r | |
34 | ## Create table\r | |
35 | #\r | |
36 | # Create table DataModel\r | |
37 | #\r | |
38 | # @param ID: ID of a ModelType\r | |
39 | # @param CrossIndex: CrossIndex of a ModelType\r | |
40 | # @param Name: Name of a ModelType\r | |
41 | # @param Description: Description of a ModelType\r | |
42 | #\r | |
43 | def Create(self):\r | |
44 | SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r | |
45 | CrossIndex INTEGER NOT NULL,\r | |
46 | Name VARCHAR NOT NULL,\r | |
47 | Description VARCHAR\r | |
48 | )""" % self.Table\r | |
49 | Table.Create(self, SqlCommand)\r | |
50 | \r | |
51 | ## Insert table\r | |
52 | #\r | |
53 | # Insert a record into table DataModel\r | |
54 | #\r | |
55 | # @param ID: ID of a ModelType\r | |
56 | # @param CrossIndex: CrossIndex of a ModelType\r | |
57 | # @param Name: Name of a ModelType\r | |
58 | # @param Description: Description of a ModelType\r | |
59 | #\r | |
60 | def Insert(self, CrossIndex, Name, Description):\r | |
61 | self.ID = self.ID + 1\r | |
62 | (Name, Description) = ConvertToSqlString((Name, Description))\r | |
63 | SqlCommand = """insert into %s values(%s, %s, '%s', '%s')""" % (self.Table, self.ID, CrossIndex, Name, Description)\r | |
64 | Table.Insert(self, SqlCommand)\r | |
65 | \r | |
66 | return self.ID\r | |
67 | \r | |
68 | ## Init table\r | |
69 | #\r | |
70 | # Create all default records of table DataModel\r | |
71 | # \r | |
72 | def InitTable(self):\r | |
73 | EdkLogger.verbose("\nInitialize table DataModel started ...")\r | |
74 | for Item in DataClass.MODEL_LIST:\r | |
75 | CrossIndex = Item[1]\r | |
76 | Name = Item[0]\r | |
77 | Description = Item[0]\r | |
78 | self.Insert(CrossIndex, Name, Description)\r | |
79 | EdkLogger.verbose("Initialize table DataModel ... DONE!")\r | |
80 | \r | |
81 | ## Get CrossIndex\r | |
82 | #\r | |
83 | # Get a model's cross index from its name\r | |
84 | #\r | |
85 | # @param ModelName: Name of the model\r | |
86 | # @retval CrossIndex: CrossIndex of the model\r | |
87 | #\r | |
88 | def GetCrossIndex(self, ModelName):\r | |
89 | CrossIndex = -1\r | |
90 | SqlCommand = """select CrossIndex from DataModel where name = '""" + ModelName + """'"""\r | |
91 | self.Cur.execute(SqlCommand)\r | |
92 | for Item in self.Cur:\r | |
93 | CrossIndex = Item[0]\r | |
94 | \r | |
95 | return CrossIndex\r |