]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableDataModel.py
BaseTools: Replace BSD License with BSD+Patent License
[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
2e351cbe 5# SPDX-License-Identifier: BSD-2-Clause-Patent\r
30fdf114
LG
6#\r
7\r
8##\r
9# Import Modules\r
10#\r
1ccc4d89 11from __future__ import absolute_import\r
30fdf114
LG
12import Common.EdkLogger as EdkLogger\r
13import CommonDataClass.DataClass as DataClass\r
855698fb 14from Table.Table import Table\r
5a57246e 15from Common.StringUtils import ConvertToSqlString\r
30fdf114
LG
16\r
17## TableDataModel\r
18#\r
19# This class defined a table used for data model\r
f7496d71 20#\r
30fdf114
LG
21# @param object: Inherited from object class\r
22#\r
23#\r
24class TableDataModel(Table):\r
25 def __init__(self, Cursor):\r
26 Table.__init__(self, Cursor)\r
27 self.Table = 'DataModel'\r
f7496d71 28\r
30fdf114
LG
29 ## Create table\r
30 #\r
31 # Create table DataModel\r
32 #\r
33 # @param ID: ID of a ModelType\r
34 # @param CrossIndex: CrossIndex of a ModelType\r
35 # @param Name: Name of a ModelType\r
36 # @param Description: Description of a ModelType\r
37 #\r
38 def Create(self):\r
39 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
40 CrossIndex INTEGER NOT NULL,\r
41 Name VARCHAR NOT NULL,\r
42 Description VARCHAR\r
43 )""" % self.Table\r
44 Table.Create(self, SqlCommand)\r
45\r
46 ## Insert table\r
47 #\r
48 # Insert a record into table DataModel\r
49 #\r
50 # @param ID: ID of a ModelType\r
51 # @param CrossIndex: CrossIndex of a ModelType\r
52 # @param Name: Name of a ModelType\r
53 # @param Description: Description of a ModelType\r
54 #\r
55 def Insert(self, CrossIndex, Name, Description):\r
56 self.ID = self.ID + 1\r
57 (Name, Description) = ConvertToSqlString((Name, Description))\r
58 SqlCommand = """insert into %s values(%s, %s, '%s', '%s')""" % (self.Table, self.ID, CrossIndex, Name, Description)\r
59 Table.Insert(self, SqlCommand)\r
f7496d71 60\r
30fdf114 61 return self.ID\r
f7496d71 62\r
30fdf114
LG
63 ## Init table\r
64 #\r
65 # Create all default records of table DataModel\r
f7496d71 66 #\r
30fdf114
LG
67 def InitTable(self):\r
68 EdkLogger.verbose("\nInitialize table DataModel started ...")\r
69 for Item in DataClass.MODEL_LIST:\r
70 CrossIndex = Item[1]\r
71 Name = Item[0]\r
72 Description = Item[0]\r
73 self.Insert(CrossIndex, Name, Description)\r
74 EdkLogger.verbose("Initialize table DataModel ... DONE!")\r
f7496d71 75\r
30fdf114
LG
76 ## Get CrossIndex\r
77 #\r
78 # Get a model's cross index from its name\r
79 #\r
80 # @param ModelName: Name of the model\r
81 # @retval CrossIndex: CrossIndex of the model\r
82 #\r
83 def GetCrossIndex(self, ModelName):\r
84 CrossIndex = -1\r
85 SqlCommand = """select CrossIndex from DataModel where name = '""" + ModelName + """'"""\r
86 self.Cur.execute(SqlCommand)\r
87 for Item in self.Cur:\r
88 CrossIndex = Item[0]\r
f7496d71 89\r
30fdf114 90 return CrossIndex\r