--- /dev/null
+## @file\r
+# This file is used to create/update/query/erase table for fdf datas\r
+#\r
+# Copyright (c) 2008, Intel Corporation\r
+# All rights reserved. This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this distribution. The full text of the license may be found at\r
+# http://opensource.org/licenses/bsd-license.php\r
+#\r
+# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+\r
+##\r
+# Import Modules\r
+#\r
+import Common.EdkLogger as EdkLogger\r
+import CommonDataClass.DataClass as DataClass\r
+from Table import Table\r
+from Common.String import ConvertToSqlString\r
+\r
+## TableFdf\r
+#\r
+# This class defined a table used for data model\r
+# \r
+# @param object: Inherited from object class\r
+#\r
+#\r
+class TableFdf(Table):\r
+ def __init__(self, Cursor):\r
+ Table.__init__(self, Cursor)\r
+ self.Table = 'Fdf'\r
+ \r
+ ## Create table\r
+ #\r
+ # Create table Fdf\r
+ #\r
+ # @param ID: ID of a Fdf item\r
+ # @param Model: Model of a Fdf item\r
+ # @param Value1: Value1 of a Fdf item\r
+ # @param Value2: Value2 of a Fdf item\r
+ # @param Value3: Value3 of a Fdf item\r
+ # @param Arch: Arch of a Fdf item\r
+ # @param BelongsToItem: The item belongs to which another item\r
+ # @param BelongsToFile: The item belongs to which fdf file\r
+ # @param StartLine: StartLine of a Fdf item\r
+ # @param StartColumn: StartColumn of a Fdf item\r
+ # @param EndLine: EndLine of a Fdf item\r
+ # @param EndColumn: EndColumn of a Fdf item\r
+ # @param Enabled: If this item enabled\r
+ #\r
+ def Create(self):\r
+ SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
+ Model INTEGER NOT NULL,\r
+ Value1 VARCHAR NOT NULL,\r
+ Value2 VARCHAR,\r
+ Value3 VARCHAR,\r
+ Arch VarCHAR,\r
+ BelongsToItem SINGLE NOT NULL,\r
+ BelongsToFile SINGLE NOT NULL,\r
+ StartLine INTEGER NOT NULL,\r
+ StartColumn INTEGER NOT NULL,\r
+ EndLine INTEGER NOT NULL,\r
+ EndColumn INTEGER NOT NULL,\r
+ Enabled INTEGER DEFAULT 0\r
+ )""" % self.Table\r
+ Table.Create(self, SqlCommand)\r
+\r
+ ## Insert table\r
+ #\r
+ # Insert a record into table Fdf\r
+ #\r
+ # @param ID: ID of a Fdf item\r
+ # @param Model: Model of a Fdf item\r
+ # @param Value1: Value1 of a Fdf item\r
+ # @param Value2: Value2 of a Fdf item\r
+ # @param Value3: Value3 of a Fdf item\r
+ # @param Arch: Arch of a Fdf item\r
+ # @param BelongsToItem: The item belongs to which another item\r
+ # @param BelongsToFile: The item belongs to which fdf file\r
+ # @param StartLine: StartLine of a Fdf item\r
+ # @param StartColumn: StartColumn of a Fdf item\r
+ # @param EndLine: EndLine of a Fdf item\r
+ # @param EndColumn: EndColumn of a Fdf item\r
+ # @param Enabled: If this item enabled\r
+ #\r
+ def Insert(self, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
+ self.ID = self.ID + 1\r
+ (Value1, Value2, Value3, Arch) = ConvertToSqlString((Value1, Value2, Value3, Arch))\r
+ SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
+ % (self.Table, self.ID, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)\r
+ Table.Insert(self, SqlCommand)\r
+ \r
+ return self.ID\r
+ \r
+ ## Query table\r
+ #\r
+ # @param Model: The Model of Record \r
+ #\r
+ # @retval: A recordSet of all found records \r
+ #\r
+ def Query(self, Model):\r
+ SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s\r
+ where Model = %s\r
+ and Enabled > -1""" % (self.Table, Model)\r
+ EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)\r
+ self.Cur.execute(SqlCommand)\r
+ return self.Cur.fetchall()\r