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