]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableDsc.py
BaseTools/Ecc: Fix import issues
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableDsc.py
CommitLineData
3d872904 1from __future__ import absolute_import\r
30fdf114
LG
2## @file\r
3# This file is used to create/update/query/erase table for dsc datas\r
4#\r
f7496d71 5# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
40d841f6 6# This program and the accompanying materials\r
30fdf114
LG
7# are licensed and made available under the terms and conditions of the BSD License\r
8# which accompanies this distribution. The full text of the license may be found at\r
9# http://opensource.org/licenses/bsd-license.php\r
10#\r
11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13#\r
14\r
15##\r
16# Import Modules\r
17#\r
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## TableDsc\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 TableDsc(Table):\r
31 def __init__(self, Cursor):\r
32 Table.__init__(self, Cursor)\r
33 self.Table = 'Dsc'\r
f7496d71 34\r
30fdf114
LG
35 ## Create table\r
36 #\r
37 # Create table Dsc\r
38 #\r
39 # @param ID: ID of a Dsc item\r
40 # @param Model: Model of a Dsc item\r
41 # @param Value1: Value1 of a Dsc item\r
42 # @param Value2: Value2 of a Dsc item\r
43 # @param Value3: Value3 of a Dsc item\r
44 # @param Arch: Arch of a Dsc item\r
45 # @param BelongsToItem: The item belongs to which another item\r
46 # @param BelongsToFile: The item belongs to which dsc file\r
47 # @param StartLine: StartLine of a Dsc item\r
48 # @param StartColumn: StartColumn of a Dsc item\r
49 # @param EndLine: EndLine of a Dsc item\r
50 # @param EndColumn: EndColumn of a Dsc item\r
51 # @param Enabled: If this item enabled\r
52 #\r
53 def Create(self):\r
54 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
55 Model INTEGER NOT NULL,\r
56 Value1 VARCHAR NOT NULL,\r
57 Value2 VARCHAR,\r
58 Value3 VARCHAR,\r
59 Arch VarCHAR,\r
60 BelongsToItem SINGLE NOT NULL,\r
61 BelongsToFile SINGLE NOT NULL,\r
62 StartLine INTEGER NOT NULL,\r
63 StartColumn INTEGER NOT NULL,\r
64 EndLine INTEGER NOT NULL,\r
65 EndColumn INTEGER NOT NULL,\r
66 Enabled INTEGER DEFAULT 0\r
67 )""" % self.Table\r
68 Table.Create(self, SqlCommand)\r
69\r
70 ## Insert table\r
71 #\r
72 # Insert a record into table Dsc\r
73 #\r
74 # @param ID: ID of a Dsc item\r
75 # @param Model: Model of a Dsc item\r
76 # @param Value1: Value1 of a Dsc item\r
77 # @param Value2: Value2 of a Dsc item\r
78 # @param Value3: Value3 of a Dsc item\r
79 # @param Arch: Arch of a Dsc item\r
80 # @param BelongsToItem: The item belongs to which another item\r
81 # @param BelongsToFile: The item belongs to which dsc file\r
82 # @param StartLine: StartLine of a Dsc item\r
83 # @param StartColumn: StartColumn of a Dsc item\r
84 # @param EndLine: EndLine of a Dsc item\r
85 # @param EndColumn: EndColumn of a Dsc item\r
86 # @param Enabled: If this item enabled\r
87 #\r
88 def Insert(self, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
89 self.ID = self.ID + 1\r
90 (Value1, Value2, Value3, Arch) = ConvertToSqlString((Value1, Value2, Value3, Arch))\r
91 SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
92 % (self.Table, self.ID, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
93 Table.Insert(self, SqlCommand)\r
f7496d71 94\r
30fdf114 95 return self.ID\r
f7496d71 96\r
30fdf114
LG
97 ## Query table\r
98 #\r
f7496d71 99 # @param Model: The Model of Record\r
30fdf114 100 #\r
f7496d71 101 # @retval: A recordSet of all found records\r
30fdf114
LG
102 #\r
103 def Query(self, Model):\r
104 SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s\r
105 where Model = %s\r
106 and Enabled > -1""" % (self.Table, Model)\r
107 EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
108 self.Cur.execute(SqlCommand)\r
109 return self.Cur.fetchall()\r