]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/Table/TableDsc.py
BaseTools: Use absolute import in Table
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableDsc.py
... / ...
CommitLineData
1from __future__ import absolute_import\r
2## @file\r
3# This file is used to create/update/query/erase table for dsc datas\r
4#\r
5# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
6# This program and the accompanying materials\r
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
20from .Table import Table\r
21from Common.StringUtils import ConvertToSqlString\r
22\r
23## TableDsc\r
24#\r
25# This class defined a table used for data model\r
26#\r
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
34\r
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
94\r
95 return self.ID\r
96\r
97 ## Query table\r
98 #\r
99 # @param Model: The Model of Record\r
100 #\r
101 # @retval: A recordSet of all found records\r
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