]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableDsc.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableDsc.py
CommitLineData
1ccc4d89 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
2e351cbe 6# SPDX-License-Identifier: BSD-2-Clause-Patent\r
30fdf114
LG
7#\r
8\r
9##\r
10# Import Modules\r
11#\r
12import Common.EdkLogger as EdkLogger\r
13import CommonDataClass.DataClass as DataClass\r
855698fb 14from Table.Table import Table\r
5a57246e 15from Common.StringUtils import ConvertToSqlString\r
30fdf114
LG
16\r
17## TableDsc\r
18#\r
19# This class defined a table used for data model\r
f7496d71 20#\r
30fdf114
LG
21# @param object: Inherited from object class\r
22#\r
23#\r
24class TableDsc(Table):\r
25 def __init__(self, Cursor):\r
26 Table.__init__(self, Cursor)\r
27 self.Table = 'Dsc'\r
f7496d71 28\r
30fdf114
LG
29 ## Create table\r
30 #\r
31 # Create table Dsc\r
32 #\r
33 # @param ID: ID of a Dsc item\r
34 # @param Model: Model of a Dsc item\r
35 # @param Value1: Value1 of a Dsc item\r
36 # @param Value2: Value2 of a Dsc item\r
37 # @param Value3: Value3 of a Dsc item\r
38 # @param Arch: Arch of a Dsc item\r
39 # @param BelongsToItem: The item belongs to which another item\r
40 # @param BelongsToFile: The item belongs to which dsc file\r
41 # @param StartLine: StartLine of a Dsc item\r
42 # @param StartColumn: StartColumn of a Dsc item\r
43 # @param EndLine: EndLine of a Dsc item\r
44 # @param EndColumn: EndColumn of a Dsc item\r
45 # @param Enabled: If this item enabled\r
46 #\r
47 def Create(self):\r
48 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
49 Model INTEGER NOT NULL,\r
50 Value1 VARCHAR NOT NULL,\r
51 Value2 VARCHAR,\r
52 Value3 VARCHAR,\r
53 Arch VarCHAR,\r
54 BelongsToItem SINGLE NOT NULL,\r
55 BelongsToFile SINGLE NOT NULL,\r
56 StartLine INTEGER NOT NULL,\r
57 StartColumn INTEGER NOT NULL,\r
58 EndLine INTEGER NOT NULL,\r
59 EndColumn INTEGER NOT NULL,\r
60 Enabled INTEGER DEFAULT 0\r
61 )""" % self.Table\r
62 Table.Create(self, SqlCommand)\r
63\r
64 ## Insert table\r
65 #\r
66 # Insert a record into table Dsc\r
67 #\r
68 # @param ID: ID of a Dsc item\r
69 # @param Model: Model of a Dsc item\r
70 # @param Value1: Value1 of a Dsc item\r
71 # @param Value2: Value2 of a Dsc item\r
72 # @param Value3: Value3 of a Dsc item\r
73 # @param Arch: Arch of a Dsc item\r
74 # @param BelongsToItem: The item belongs to which another item\r
75 # @param BelongsToFile: The item belongs to which dsc file\r
76 # @param StartLine: StartLine of a Dsc item\r
77 # @param StartColumn: StartColumn of a Dsc item\r
78 # @param EndLine: EndLine of a Dsc item\r
79 # @param EndColumn: EndColumn of a Dsc item\r
80 # @param Enabled: If this item enabled\r
81 #\r
82 def Insert(self, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
83 self.ID = self.ID + 1\r
84 (Value1, Value2, Value3, Arch) = ConvertToSqlString((Value1, Value2, Value3, Arch))\r
85 SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
86 % (self.Table, self.ID, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
87 Table.Insert(self, SqlCommand)\r
f7496d71 88\r
30fdf114 89 return self.ID\r
f7496d71 90\r
30fdf114
LG
91 ## Query table\r
92 #\r
f7496d71 93 # @param Model: The Model of Record\r
30fdf114 94 #\r
f7496d71 95 # @retval: A recordSet of all found records\r
30fdf114
LG
96 #\r
97 def Query(self, Model):\r
98 SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s\r
99 where Model = %s\r
100 and Enabled > -1""" % (self.Table, Model)\r
101 EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
102 self.Cur.execute(SqlCommand)\r
103 return self.Cur.fetchall()\r