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