]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Workspace/MetaFileTable.py
MdeModulePkg:
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / MetaFileTable.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to create/update/query/erase a meta file table\r
3#\r
4# Copyright (c) 2008, Intel Corporation\r
5# All rights reserved. This program and the accompanying materials\r
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
17import Common.EdkLogger as EdkLogger\r
18from MetaDataTable import Table\r
19from MetaDataTable import ConvertToSqlString\r
20\r
21## Python class representation of table storing module data\r
22class ModuleTable(Table):\r
23 # TRICK: use file ID as the part before '.'\r
24 _ID_STEP_ = 0.00000001\r
25 _ID_MAX_ = 0.99999999\r
26 _COLUMN_ = '''\r
27 ID REAL PRIMARY KEY,\r
28 Model INTEGER NOT NULL,\r
29 Value1 TEXT NOT NULL,\r
30 Value2 TEXT,\r
31 Value3 TEXT,\r
32 Scope1 TEXT,\r
33 Scope2 TEXT,\r
34 BelongsToItem REAL NOT NULL,\r
35 StartLine INTEGER NOT NULL,\r
36 StartColumn INTEGER NOT NULL,\r
37 EndLine INTEGER NOT NULL,\r
38 EndColumn INTEGER NOT NULL,\r
39 Enabled INTEGER DEFAULT 0\r
40 '''\r
41 # used as table end flag, in case the changes to database is not committed to db file\r
42 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1"\r
43\r
44 ## Constructor\r
45 def __init__(self, Cursor, Name='Inf', IdBase=0, Temporary=False):\r
46 Table.__init__(self, Cursor, Name, IdBase, Temporary)\r
47\r
48 ## Insert a record into table Inf\r
49 #\r
50 # @param Model: Model of a Inf item\r
51 # @param Value1: Value1 of a Inf item\r
52 # @param Value2: Value2 of a Inf item\r
53 # @param Value3: Value3 of a Inf item\r
54 # @param Scope1: Arch of a Inf item\r
55 # @param Scope2 Platform os a Inf item\r
56 # @param BelongsToItem: The item belongs to which another item\r
57 # @param StartLine: StartLine of a Inf item\r
58 # @param StartColumn: StartColumn of a Inf item\r
59 # @param EndLine: EndLine of a Inf item\r
60 # @param EndColumn: EndColumn of a Inf item\r
61 # @param Enabled: If this item enabled\r
62 #\r
63 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r
64 BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r
65 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
66 return Table.Insert(\r
67 self, \r
68 Model, \r
69 Value1, \r
70 Value2, \r
71 Value3, \r
72 Scope1, \r
73 Scope2,\r
74 BelongsToItem, \r
75 StartLine, \r
76 StartColumn, \r
77 EndLine, \r
78 EndColumn, \r
79 Enabled\r
80 )\r
81\r
82 ## Query table\r
83 #\r
84 # @param Model: The Model of Record \r
85 # @param Arch: The Arch attribute of Record \r
86 # @param Platform The Platform attribute of Record \r
87 #\r
88 # @retval: A recordSet of all found records \r
89 #\r
90 def Query(self, Model, Arch=None, Platform=None):\r
91 ConditionString = "Model=%s AND Enabled>=0" % Model\r
92 ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r
93\r
94 if Arch != None and Arch != 'COMMON':\r
95 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r
96 if Platform != None and Platform != 'COMMON':\r
97 ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform\r
98\r
99 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
100 return self.Exec(SqlCommand)\r
101\r
102## Python class representation of table storing package data\r
103class PackageTable(Table):\r
104 _ID_STEP_ = 0.00000001\r
105 _ID_MAX_ = 0.99999999\r
106 _COLUMN_ = '''\r
107 ID REAL PRIMARY KEY,\r
108 Model INTEGER NOT NULL,\r
109 Value1 TEXT NOT NULL,\r
110 Value2 TEXT,\r
111 Value3 TEXT,\r
112 Scope1 TEXT,\r
113 Scope2 TEXT,\r
114 BelongsToItem REAL NOT NULL,\r
115 StartLine INTEGER NOT NULL,\r
116 StartColumn INTEGER NOT NULL,\r
117 EndLine INTEGER NOT NULL,\r
118 EndColumn INTEGER NOT NULL,\r
119 Enabled INTEGER DEFAULT 0\r
120 '''\r
121 # used as table end flag, in case the changes to database is not committed to db file\r
122 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1"\r
123\r
124 ## Constructor\r
125 def __init__(self, Cursor, Name='Dec', IdBase=0, Temporary=False):\r
126 Table.__init__(self, Cursor, Name, IdBase, Temporary)\r
127\r
128 ## Insert table\r
129 #\r
130 # Insert a record into table Dec\r
131 #\r
132 # @param Model: Model of a Dec item\r
133 # @param Value1: Value1 of a Dec item\r
134 # @param Value2: Value2 of a Dec item\r
135 # @param Value3: Value3 of a Dec item\r
136 # @param Scope1: Arch of a Dec item\r
137 # @param Scope2: Module type of a Dec item\r
138 # @param BelongsToItem: The item belongs to which another item\r
139 # @param StartLine: StartLine of a Dec item\r
140 # @param StartColumn: StartColumn of a Dec item\r
141 # @param EndLine: EndLine of a Dec item\r
142 # @param EndColumn: EndColumn of a Dec item\r
143 # @param Enabled: If this item enabled\r
144 #\r
145 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',\r
146 BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):\r
147 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
148 return Table.Insert(\r
149 self, \r
150 Model, \r
151 Value1, \r
152 Value2, \r
153 Value3, \r
154 Scope1, \r
155 Scope2,\r
156 BelongsToItem, \r
157 StartLine, \r
158 StartColumn, \r
159 EndLine, \r
160 EndColumn, \r
161 Enabled\r
162 )\r
163\r
164 ## Query table\r
165 #\r
166 # @param Model: The Model of Record \r
167 # @param Arch: The Arch attribute of Record \r
168 #\r
169 # @retval: A recordSet of all found records \r
170 #\r
171 def Query(self, Model, Arch=None):\r
172 ConditionString = "Model=%s AND Enabled>=0" % Model\r
173 ValueString = "Value1,Value2,Value3,Scope1,ID,StartLine"\r
174\r
175 if Arch != None and Arch != 'COMMON':\r
176 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch\r
177\r
178 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
179 return self.Exec(SqlCommand)\r
180\r
181## Python class representation of table storing platform data\r
182class PlatformTable(Table):\r
183 _ID_STEP_ = 0.00000001\r
184 _ID_MAX_ = 0.99999999\r
185 _COLUMN_ = '''\r
186 ID REAL PRIMARY KEY,\r
187 Model INTEGER NOT NULL,\r
188 Value1 TEXT NOT NULL,\r
189 Value2 TEXT,\r
190 Value3 TEXT,\r
191 Scope1 TEXT,\r
192 Scope2 TEXT,\r
193 BelongsToItem REAL NOT NULL,\r
194 FromItem REAL NOT NULL,\r
195 StartLine INTEGER NOT NULL,\r
196 StartColumn INTEGER NOT NULL,\r
197 EndLine INTEGER NOT NULL,\r
198 EndColumn INTEGER NOT NULL,\r
199 Enabled INTEGER DEFAULT 0\r
200 '''\r
201 # used as table end flag, in case the changes to database is not committed to db file\r
202 _DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"\r
203\r
204 ## Constructor\r
205 def __init__(self, Cursor, Name='Dsc', IdBase=0, Temporary=False):\r
206 Table.__init__(self, Cursor, Name, IdBase, Temporary)\r
207\r
208 ## Insert table\r
209 #\r
210 # Insert a record into table Dsc\r
211 #\r
212 # @param Model: Model of a Dsc item\r
213 # @param Value1: Value1 of a Dsc item\r
214 # @param Value2: Value2 of a Dsc item\r
215 # @param Value3: Value3 of a Dsc item\r
216 # @param Scope1: Arch of a Dsc item\r
217 # @param Scope2: Module type of a Dsc item\r
218 # @param BelongsToItem: The item belongs to which another item\r
219 # @param FromItem: The item belongs to which dsc file\r
220 # @param StartLine: StartLine of a Dsc item\r
221 # @param StartColumn: StartColumn of a Dsc item\r
222 # @param EndLine: EndLine of a Dsc item\r
223 # @param EndColumn: EndColumn of a Dsc item\r
224 # @param Enabled: If this item enabled\r
225 #\r
226 def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', BelongsToItem=-1, \r
227 FromItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=1):\r
228 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
229 return Table.Insert(\r
230 self, \r
231 Model, \r
232 Value1, \r
233 Value2, \r
234 Value3, \r
235 Scope1, \r
236 Scope2,\r
237 BelongsToItem, \r
238 FromItem,\r
239 StartLine, \r
240 StartColumn, \r
241 EndLine, \r
242 EndColumn, \r
243 Enabled\r
244 )\r
245\r
246 ## Query table\r
247 #\r
248 # @param Model: The Model of Record \r
249 # @param Scope1: Arch of a Dsc item\r
250 # @param Scope2: Module type of a Dsc item\r
251 # @param BelongsToItem: The item belongs to which another item\r
252 # @param FromItem: The item belongs to which dsc file\r
253 #\r
254 # @retval: A recordSet of all found records \r
255 #\r
256 def Query(self, Model, Scope1=None, Scope2=None, BelongsToItem=None, FromItem=None):\r
257 ConditionString = "Model=%s AND Enabled>=0" % Model\r
258 ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"\r
259\r
260 if Scope1 != None and Scope1 != 'COMMON':\r
261 ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1\r
262 if Scope2 != None and Scope2 != 'COMMON':\r
263 ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2\r
264\r
265 if BelongsToItem != None:\r
266 ConditionString += " AND BelongsToItem=%s" % BelongsToItem\r
267 else:\r
268 ConditionString += " AND BelongsToItem<0"\r
269\r
270 if FromItem != None:\r
271 ConditionString += " AND FromItem=%s" % FromItem\r
272\r
273 SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)\r
274 return self.Exec(SqlCommand)\r
275\r