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