]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableDataModel.py
BaseTools: Use absolute import in Table
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableDataModel.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to create/update/query/erase table for data models\r
3#\r
f7496d71 4# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
40d841f6 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
3d872904 17from __future__ import absolute_import\r
30fdf114
LG
18import Common.EdkLogger as EdkLogger\r
19import CommonDataClass.DataClass as DataClass\r
3d872904 20from .Table import Table\r
5a57246e 21from Common.StringUtils import ConvertToSqlString\r
30fdf114
LG
22\r
23## TableDataModel\r
24#\r
25# This class defined a table used for data model\r
f7496d71 26#\r
30fdf114
LG
27# @param object: Inherited from object class\r
28#\r
29#\r
30class TableDataModel(Table):\r
31 def __init__(self, Cursor):\r
32 Table.__init__(self, Cursor)\r
33 self.Table = 'DataModel'\r
f7496d71 34\r
30fdf114
LG
35 ## Create table\r
36 #\r
37 # Create table DataModel\r
38 #\r
39 # @param ID: ID of a ModelType\r
40 # @param CrossIndex: CrossIndex of a ModelType\r
41 # @param Name: Name of a ModelType\r
42 # @param Description: Description of a ModelType\r
43 #\r
44 def Create(self):\r
45 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
46 CrossIndex INTEGER NOT NULL,\r
47 Name VARCHAR NOT NULL,\r
48 Description VARCHAR\r
49 )""" % self.Table\r
50 Table.Create(self, SqlCommand)\r
51\r
52 ## Insert table\r
53 #\r
54 # Insert a record into table DataModel\r
55 #\r
56 # @param ID: ID of a ModelType\r
57 # @param CrossIndex: CrossIndex of a ModelType\r
58 # @param Name: Name of a ModelType\r
59 # @param Description: Description of a ModelType\r
60 #\r
61 def Insert(self, CrossIndex, Name, Description):\r
62 self.ID = self.ID + 1\r
63 (Name, Description) = ConvertToSqlString((Name, Description))\r
64 SqlCommand = """insert into %s values(%s, %s, '%s', '%s')""" % (self.Table, self.ID, CrossIndex, Name, Description)\r
65 Table.Insert(self, SqlCommand)\r
f7496d71 66\r
30fdf114 67 return self.ID\r
f7496d71 68\r
30fdf114
LG
69 ## Init table\r
70 #\r
71 # Create all default records of table DataModel\r
f7496d71 72 #\r
30fdf114
LG
73 def InitTable(self):\r
74 EdkLogger.verbose("\nInitialize table DataModel started ...")\r
75 for Item in DataClass.MODEL_LIST:\r
76 CrossIndex = Item[1]\r
77 Name = Item[0]\r
78 Description = Item[0]\r
79 self.Insert(CrossIndex, Name, Description)\r
80 EdkLogger.verbose("Initialize table DataModel ... DONE!")\r
f7496d71 81\r
30fdf114
LG
82 ## Get CrossIndex\r
83 #\r
84 # Get a model's cross index from its name\r
85 #\r
86 # @param ModelName: Name of the model\r
87 # @retval CrossIndex: CrossIndex of the model\r
88 #\r
89 def GetCrossIndex(self, ModelName):\r
90 CrossIndex = -1\r
91 SqlCommand = """select CrossIndex from DataModel where name = '""" + ModelName + """'"""\r
92 self.Cur.execute(SqlCommand)\r
93 for Item in self.Cur:\r
94 CrossIndex = Item[0]\r
f7496d71 95\r
30fdf114 96 return CrossIndex\r