]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableInf.py
Sync EDKII BaseTools to BaseTools project r1971
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableInf.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to create/update/query/erase table for inf datas\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
17import Common.EdkLogger as EdkLogger\r
18import CommonDataClass.DataClass as DataClass\r
19from Table import Table\r
20from Common.String import ConvertToSqlString\r
21\r
22## TableInf\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
29class TableInf(Table):\r
30 def __init__(self, Cursor):\r
31 Table.__init__(self, Cursor)\r
32 self.Table = 'Inf'\r
33 \r
34 ## Create table\r
35 #\r
36 # Create table Inf\r
37 #\r
38 # @param ID: ID of a Inf item\r
39 # @param Model: Model of a Inf item\r
40 # @param Value1: Value1 of a Inf item\r
41 # @param Value2: Value2 of a Inf item\r
42 # @param Value3: Value3 of a Inf item\r
43 # @param Value4: Value4 of a Inf item\r
44 # @param Value5: Value5 of a Inf item\r
45 # @param Arch: Arch of a Inf item\r
46 # @param BelongsToItem: The item belongs to which another item\r
47 # @param BelongsToFile: The item belongs to which dsc file\r
48 # @param StartLine: StartLine of a Inf item\r
49 # @param StartColumn: StartColumn of a Inf item\r
50 # @param EndLine: EndLine of a Inf item\r
51 # @param EndColumn: EndColumn of a Inf item\r
52 # @param Enabled: If this item enabled\r
53 #\r
54 def Create(self):\r
55 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
56 Model INTEGER NOT NULL,\r
57 Value1 VARCHAR NOT NULL,\r
58 Value2 VARCHAR,\r
59 Value3 VARCHAR,\r
60 Value4 VARCHAR,\r
61 Value5 VARCHAR,\r
62 Arch VarCHAR,\r
63 BelongsToItem SINGLE NOT NULL,\r
64 BelongsToFile SINGLE NOT NULL,\r
65 StartLine INTEGER NOT NULL,\r
66 StartColumn INTEGER NOT NULL,\r
67 EndLine INTEGER NOT NULL,\r
68 EndColumn INTEGER NOT NULL,\r
69 Enabled INTEGER DEFAULT 0\r
70 )""" % self.Table\r
71 Table.Create(self, SqlCommand)\r
72\r
73 ## Insert table\r
74 #\r
75 # Insert a record into table Inf\r
76 #\r
77 # @param ID: ID of a Inf item\r
78 # @param Model: Model of a Inf item\r
79 # @param Value1: Value1 of a Inf item\r
80 # @param Value2: Value2 of a Inf item\r
81 # @param Value3: Value3 of a Inf item\r
82 # @param Value4: Value4 of a Inf item\r
83 # @param Value5: Value5 of a Inf item\r
84 # @param Arch: Arch of a Inf item\r
85 # @param BelongsToItem: The item belongs to which another item\r
86 # @param BelongsToFile: The item belongs to which dsc file\r
87 # @param StartLine: StartLine of a Inf item\r
88 # @param StartColumn: StartColumn of a Inf item\r
89 # @param EndLine: EndLine of a Inf item\r
90 # @param EndColumn: EndColumn of a Inf item\r
91 # @param Enabled: If this item enabled\r
92 #\r
93 def Insert(self, Model, Value1, Value2, Value3, Value4, Value5, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
94 self.ID = self.ID + 1\r
95 (Value1, Value2, Value3, Value4, Value5, Arch) = ConvertToSqlString((Value1, Value2, Value3, Value4, Value5, Arch))\r
96 SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
97 % (self.Table, self.ID, Model, Value1, Value2, Value3, Value4, Value5, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
98 Table.Insert(self, SqlCommand)\r
99 \r
100 return self.ID\r
101 \r
102 ## Query table\r
103 #\r
104 # @param Model: The Model of Record \r
105 #\r
106 # @retval: A recordSet of all found records \r
107 #\r
108 def Query(self, Model):\r
109 SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s\r
110 where Model = %s\r
111 and Enabled > -1""" % (self.Table, Model)\r
112 EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
113 self.Cur.execute(SqlCommand)\r
114 return self.Cur.fetchall()\r