]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/Table/TableFdf.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableFdf.py
CommitLineData
30fdf114
LG
1## @file\r
2# This file is used to create/update/query/erase table for fdf datas\r
3#\r
f7496d71 4# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
2e351cbe 5# SPDX-License-Identifier: BSD-2-Clause-Patent\r
30fdf114
LG
6#\r
7\r
8##\r
9# Import Modules\r
10#\r
1ccc4d89 11from __future__ import absolute_import\r
30fdf114
LG
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## TableFdf\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 TableFdf(Table):\r
25 def __init__(self, Cursor):\r
26 Table.__init__(self, Cursor)\r
27 self.Table = 'Fdf'\r
f7496d71 28\r
30fdf114
LG
29 ## Create table\r
30 #\r
31 # Create table Fdf\r
32 #\r
33 # @param ID: ID of a Fdf item\r
34 # @param Model: Model of a Fdf item\r
35 # @param Value1: Value1 of a Fdf item\r
36 # @param Value2: Value2 of a Fdf item\r
37 # @param Value3: Value3 of a Fdf item\r
38 # @param Arch: Arch of a Fdf item\r
39 # @param BelongsToItem: The item belongs to which another item\r
40 # @param BelongsToFile: The item belongs to which fdf file\r
41 # @param StartLine: StartLine of a Fdf item\r
42 # @param StartColumn: StartColumn of a Fdf item\r
43 # @param EndLine: EndLine of a Fdf item\r
44 # @param EndColumn: EndColumn of a Fdf 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
d0acc87a
LG
53 Scope1 VarCHAR,\r
54 Scope2 VarCHAR,\r
30fdf114
LG
55 BelongsToItem SINGLE NOT NULL,\r
56 BelongsToFile SINGLE NOT NULL,\r
57 StartLine INTEGER NOT NULL,\r
58 StartColumn INTEGER NOT NULL,\r
59 EndLine INTEGER NOT NULL,\r
60 EndColumn INTEGER NOT NULL,\r
61 Enabled INTEGER DEFAULT 0\r
62 )""" % self.Table\r
63 Table.Create(self, SqlCommand)\r
64\r
65 ## Insert table\r
66 #\r
67 # Insert a record into table Fdf\r
68 #\r
69 # @param ID: ID of a Fdf item\r
70 # @param Model: Model of a Fdf item\r
71 # @param Value1: Value1 of a Fdf item\r
72 # @param Value2: Value2 of a Fdf item\r
73 # @param Value3: Value3 of a Fdf item\r
74 # @param Arch: Arch of a Fdf item\r
75 # @param BelongsToItem: The item belongs to which another item\r
76 # @param BelongsToFile: The item belongs to which fdf file\r
77 # @param StartLine: StartLine of a Fdf item\r
78 # @param StartColumn: StartColumn of a Fdf item\r
79 # @param EndLine: EndLine of a Fdf item\r
80 # @param EndColumn: EndColumn of a Fdf item\r
81 # @param Enabled: If this item enabled\r
82 #\r
d0acc87a 83 def Insert(self, Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
30fdf114 84 self.ID = self.ID + 1\r
d0acc87a
LG
85 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r
86 SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
87 % (self.Table, self.ID, Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
30fdf114 88 Table.Insert(self, SqlCommand)\r
f7496d71 89\r
30fdf114 90 return self.ID\r
f7496d71 91\r
30fdf114
LG
92 ## Query table\r
93 #\r
f7496d71 94 # @param Model: The Model of Record\r
30fdf114 95 #\r
f7496d71 96 # @retval: A recordSet of all found records\r
30fdf114
LG
97 #\r
98 def Query(self, Model):\r
d0acc87a 99 SqlCommand = """select ID, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine from %s\r
30fdf114
LG
100 where Model = %s\r
101 and Enabled > -1""" % (self.Table, Model)\r
102 EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
103 self.Cur.execute(SqlCommand)\r
104 return self.Cur.fetchall()\r