]>
Commit | Line | Data |
---|---|---|
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 |
40d841f6 | 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 | |
3d872904 | 17 | from __future__ import absolute_import\r |
30fdf114 LG |
18 | import Common.EdkLogger as EdkLogger\r |
19 | import CommonDataClass.DataClass as DataClass\r | |
855698fb | 20 | from Table.Table import Table\r |
5a57246e | 21 | from Common.StringUtils import ConvertToSqlString\r |
30fdf114 LG |
22 | \r |
23 | ## TableFdf\r | |
24 | #\r | |
25 | # This class defined a table used for data model\r | |
f7496d71 | 26 | #\r |
30fdf114 LG |
27 | # @param object: Inherited from object class\r |
28 | #\r | |
29 | #\r | |
30 | class TableFdf(Table):\r | |
31 | def __init__(self, Cursor):\r | |
32 | Table.__init__(self, Cursor)\r | |
33 | self.Table = 'Fdf'\r | |
f7496d71 | 34 | \r |
30fdf114 LG |
35 | ## Create table\r |
36 | #\r | |
37 | # Create table Fdf\r | |
38 | #\r | |
39 | # @param ID: ID of a Fdf item\r | |
40 | # @param Model: Model of a Fdf item\r | |
41 | # @param Value1: Value1 of a Fdf item\r | |
42 | # @param Value2: Value2 of a Fdf item\r | |
43 | # @param Value3: Value3 of a Fdf item\r | |
44 | # @param Arch: Arch of a Fdf item\r | |
45 | # @param BelongsToItem: The item belongs to which another item\r | |
46 | # @param BelongsToFile: The item belongs to which fdf file\r | |
47 | # @param StartLine: StartLine of a Fdf item\r | |
48 | # @param StartColumn: StartColumn of a Fdf item\r | |
49 | # @param EndLine: EndLine of a Fdf item\r | |
50 | # @param EndColumn: EndColumn of a Fdf item\r | |
51 | # @param Enabled: If this item enabled\r | |
52 | #\r | |
53 | def Create(self):\r | |
54 | SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r | |
55 | Model INTEGER NOT NULL,\r | |
56 | Value1 VARCHAR NOT NULL,\r | |
57 | Value2 VARCHAR,\r | |
58 | Value3 VARCHAR,\r | |
d0acc87a LG |
59 | Scope1 VarCHAR,\r |
60 | Scope2 VarCHAR,\r | |
30fdf114 LG |
61 | BelongsToItem SINGLE NOT NULL,\r |
62 | BelongsToFile SINGLE NOT NULL,\r | |
63 | StartLine INTEGER NOT NULL,\r | |
64 | StartColumn INTEGER NOT NULL,\r | |
65 | EndLine INTEGER NOT NULL,\r | |
66 | EndColumn INTEGER NOT NULL,\r | |
67 | Enabled INTEGER DEFAULT 0\r | |
68 | )""" % self.Table\r | |
69 | Table.Create(self, SqlCommand)\r | |
70 | \r | |
71 | ## Insert table\r | |
72 | #\r | |
73 | # Insert a record into table Fdf\r | |
74 | #\r | |
75 | # @param ID: ID of a Fdf item\r | |
76 | # @param Model: Model of a Fdf item\r | |
77 | # @param Value1: Value1 of a Fdf item\r | |
78 | # @param Value2: Value2 of a Fdf item\r | |
79 | # @param Value3: Value3 of a Fdf item\r | |
80 | # @param Arch: Arch of a Fdf item\r | |
81 | # @param BelongsToItem: The item belongs to which another item\r | |
82 | # @param BelongsToFile: The item belongs to which fdf file\r | |
83 | # @param StartLine: StartLine of a Fdf item\r | |
84 | # @param StartColumn: StartColumn of a Fdf item\r | |
85 | # @param EndLine: EndLine of a Fdf item\r | |
86 | # @param EndColumn: EndColumn of a Fdf item\r | |
87 | # @param Enabled: If this item enabled\r | |
88 | #\r | |
d0acc87a | 89 | def Insert(self, Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r |
30fdf114 | 90 | self.ID = self.ID + 1\r |
d0acc87a LG |
91 | (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))\r |
92 | SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r | |
93 | % (self.Table, self.ID, Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r | |
30fdf114 | 94 | Table.Insert(self, SqlCommand)\r |
f7496d71 | 95 | \r |
30fdf114 | 96 | return self.ID\r |
f7496d71 | 97 | \r |
30fdf114 LG |
98 | ## Query table\r |
99 | #\r | |
f7496d71 | 100 | # @param Model: The Model of Record\r |
30fdf114 | 101 | #\r |
f7496d71 | 102 | # @retval: A recordSet of all found records\r |
30fdf114 LG |
103 | #\r |
104 | def Query(self, Model):\r | |
d0acc87a | 105 | SqlCommand = """select ID, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine from %s\r |
30fdf114 LG |
106 | where Model = %s\r |
107 | and Enabled > -1""" % (self.Table, Model)\r | |
108 | EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r | |
109 | self.Cur.execute(SqlCommand)\r | |
110 | return self.Cur.fetchall()\r |