]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableDec.py
BaseTools: Use absolute import in Table
[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
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
3d872904 17from __future__ import absolute_import\r
30fdf114
LG
18import Common.EdkLogger as EdkLogger\r
19import CommonDataClass.DataClass as DataClass\r
3d872904 20from .Table import Table\r
5a57246e 21from Common.StringUtils import ConvertToSqlString\r
30fdf114
LG
22\r
23## TableDec\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 TableDec(Table):\r
31 def __init__(self, Cursor):\r
32 Table.__init__(self, Cursor)\r
33 self.Table = 'Dec'\r
f7496d71 34\r
30fdf114
LG
35 ## Create table\r
36 #\r
37 # Create table Dec\r
38 #\r
39 # @param ID: ID of a Dec item\r
40 # @param Model: Model of a Dec item\r
41 # @param Value1: Value1 of a Dec item\r
42 # @param Value2: Value2 of a Dec item\r
43 # @param Value3: Value3 of a Dec item\r
44 # @param Arch: Arch of a Dec 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 Dec item\r
48 # @param StartColumn: StartColumn of a Dec item\r
49 # @param EndLine: EndLine of a Dec item\r
50 # @param EndColumn: EndColumn of a Dec 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 Dec\r
73 #\r
74 # @param ID: ID of a Dec item\r
75 # @param Model: Model of a Dec item\r
76 # @param Value1: Value1 of a Dec item\r
77 # @param Value2: Value2 of a Dec item\r
78 # @param Value3: Value3 of a Dec item\r
79 # @param Arch: Arch of a Dec 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 Dec item\r
83 # @param StartColumn: StartColumn of a Dec item\r
84 # @param EndLine: EndLine of a Dec item\r
85 # @param EndColumn: EndColumn of a Dec item\r
86 # @param Enabled: If this item enabled\r
87 #\r
88 def Insert(self, Model, Value1, Value2, Value3, Value4, Value5, 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