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