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