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