BaseTools: Use absolute import in Table
[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 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
9 #
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 #
13
14 ##
15 # Import Modules
16 #
17 from __future__ import absolute_import
18 import Common.EdkLogger as EdkLogger
19 import CommonDataClass.DataClass as DataClass
20 from .Table import Table
21 from Common.StringUtils import ConvertToSqlString
22
23 ## TableFdf
24 #
25 # This class defined a table used for data model
26 #
27 # @param object: Inherited from object class
28 #
29 #
30 class TableFdf(Table):
31 def __init__(self, Cursor):
32 Table.__init__(self, Cursor)
33 self.Table = 'Fdf'
34
35 ## Create table
36 #
37 # Create table Fdf
38 #
39 # @param ID: ID of a Fdf item
40 # @param Model: Model of a Fdf item
41 # @param Value1: Value1 of a Fdf item
42 # @param Value2: Value2 of a Fdf item
43 # @param Value3: Value3 of a Fdf item
44 # @param Arch: Arch of a Fdf item
45 # @param BelongsToItem: The item belongs to which another item
46 # @param BelongsToFile: The item belongs to which fdf file
47 # @param StartLine: StartLine of a Fdf item
48 # @param StartColumn: StartColumn of a Fdf item
49 # @param EndLine: EndLine of a Fdf item
50 # @param EndColumn: EndColumn of a Fdf item
51 # @param Enabled: If this item enabled
52 #
53 def Create(self):
54 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
55 Model INTEGER NOT NULL,
56 Value1 VARCHAR NOT NULL,
57 Value2 VARCHAR,
58 Value3 VARCHAR,
59 Scope1 VarCHAR,
60 Scope2 VarCHAR,
61 BelongsToItem SINGLE NOT NULL,
62 BelongsToFile SINGLE NOT NULL,
63 StartLine INTEGER NOT NULL,
64 StartColumn INTEGER NOT NULL,
65 EndLine INTEGER NOT NULL,
66 EndColumn INTEGER NOT NULL,
67 Enabled INTEGER DEFAULT 0
68 )""" % self.Table
69 Table.Create(self, SqlCommand)
70
71 ## Insert table
72 #
73 # Insert a record into table Fdf
74 #
75 # @param ID: ID of a Fdf item
76 # @param Model: Model of a Fdf item
77 # @param Value1: Value1 of a Fdf item
78 # @param Value2: Value2 of a Fdf item
79 # @param Value3: Value3 of a Fdf item
80 # @param Arch: Arch of a Fdf item
81 # @param BelongsToItem: The item belongs to which another item
82 # @param BelongsToFile: The item belongs to which fdf file
83 # @param StartLine: StartLine of a Fdf item
84 # @param StartColumn: StartColumn of a Fdf item
85 # @param EndLine: EndLine of a Fdf item
86 # @param EndColumn: EndColumn of a Fdf item
87 # @param Enabled: If this item enabled
88 #
89 def Insert(self, Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):
90 self.ID = self.ID + 1
91 (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))
92 SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \
93 % (self.Table, self.ID, Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)
94 Table.Insert(self, SqlCommand)
95
96 return self.ID
97
98 ## Query table
99 #
100 # @param Model: The Model of Record
101 #
102 # @retval: A recordSet of all found records
103 #
104 def Query(self, Model):
105 SqlCommand = """select ID, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine from %s
106 where Model = %s
107 and Enabled > -1""" % (self.Table, Model)
108 EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)
109 self.Cur.execute(SqlCommand)
110 return self.Cur.fetchall()