]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Table/TableInf.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableInf.py
diff --git a/BaseTools/Source/Python/Table/TableInf.py b/BaseTools/Source/Python/Table/TableInf.py
new file mode 100644 (file)
index 0000000..65ca1ce
--- /dev/null
@@ -0,0 +1,114 @@
+## @file\r
+# This file is used to create/update/query/erase table for inf 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
+## TableInf\r
+#\r
+# This class defined a table used for data model\r
+# \r
+# @param object:       Inherited from object class\r
+#\r
+#\r
+class TableInf(Table):\r
+    def __init__(self, Cursor):\r
+        Table.__init__(self, Cursor)\r
+        self.Table = 'Inf'\r
+    \r
+    ## Create table\r
+    #\r
+    # Create table Inf\r
+    #\r
+    # @param ID:             ID of a Inf item\r
+    # @param Model:          Model of a Inf item\r
+    # @param Value1:         Value1 of a Inf item\r
+    # @param Value2:         Value2 of a Inf item\r
+    # @param Value3:         Value3 of a Inf item\r
+    # @param Value4:         Value4 of a Inf item\r
+    # @param Value5:         Value5 of a Inf item\r
+    # @param Arch:           Arch of a Inf item\r
+    # @param BelongsToItem:  The item belongs to which another item\r
+    # @param BelongsToFile:  The item belongs to which dsc file\r
+    # @param StartLine:      StartLine of a Inf item\r
+    # @param StartColumn:    StartColumn of a Inf item\r
+    # @param EndLine:        EndLine of a Inf item\r
+    # @param EndColumn:      EndColumn of a Inf 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
+                                                       Value4 VARCHAR,\r
+                                                       Value5 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 Inf\r
+    #\r
+    # @param ID:             ID of a Inf item\r
+    # @param Model:          Model of a Inf item\r
+    # @param Value1:         Value1 of a Inf item\r
+    # @param Value2:         Value2 of a Inf item\r
+    # @param Value3:         Value3 of a Inf item\r
+    # @param Value4:         Value4 of a Inf item\r
+    # @param Value5:         Value5 of a Inf item\r
+    # @param Arch:           Arch of a Inf item\r
+    # @param BelongsToItem:  The item belongs to which another item\r
+    # @param BelongsToFile:  The item belongs to which dsc file\r
+    # @param StartLine:      StartLine of a Inf item\r
+    # @param StartColumn:    StartColumn of a Inf item\r
+    # @param EndLine:        EndLine of a Inf item\r
+    # @param EndColumn:      EndColumn of a Inf item\r
+    # @param Enabled:        If this item enabled\r
+    #\r
+    def Insert(self, Model, Value1, Value2, Value3, Value4, Value5, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):\r
+        self.ID = self.ID + 1\r
+        (Value1, Value2, Value3, Value4, Value5, Arch) = ConvertToSqlString((Value1, Value2, Value3, Value4, Value5, Arch))\r
+        SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \\r
+                     % (self.Table, self.ID, Model, Value1, Value2, Value3, Value4, Value5, 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