]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Table/TableDataModel.py
Check In tool source code based on Build tool project revision r1655.
[mirror_edk2.git] / BaseTools / Source / Python / Table / TableDataModel.py
diff --git a/BaseTools/Source/Python/Table/TableDataModel.py b/BaseTools/Source/Python/Table/TableDataModel.py
new file mode 100644 (file)
index 0000000..1e5fe47
--- /dev/null
@@ -0,0 +1,95 @@
+## @file\r
+# This file is used to create/update/query/erase table for data models\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
+## TableDataModel\r
+#\r
+# This class defined a table used for data model\r
+# \r
+# @param object:       Inherited from object class\r
+#\r
+#\r
+class TableDataModel(Table):\r
+    def __init__(self, Cursor):\r
+        Table.__init__(self, Cursor)\r
+        self.Table = 'DataModel'\r
+    \r
+    ## Create table\r
+    #\r
+    # Create table DataModel\r
+    #\r
+    # @param ID:           ID of a ModelType\r
+    # @param CrossIndex:   CrossIndex of a ModelType\r
+    # @param Name:         Name of a ModelType\r
+    # @param Description:  Description of a ModelType\r
+    #\r
+    def Create(self):\r
+        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r
+                                                       CrossIndex INTEGER NOT NULL,\r
+                                                       Name VARCHAR NOT NULL,\r
+                                                       Description VARCHAR\r
+                                                      )""" % self.Table\r
+        Table.Create(self, SqlCommand)\r
+\r
+    ## Insert table\r
+    #\r
+    # Insert a record into table DataModel\r
+    #\r
+    # @param ID:           ID of a ModelType\r
+    # @param CrossIndex:   CrossIndex of a ModelType\r
+    # @param Name:         Name of a ModelType\r
+    # @param Description:  Description of a ModelType\r
+    #\r
+    def Insert(self, CrossIndex, Name, Description):\r
+        self.ID = self.ID + 1\r
+        (Name, Description) = ConvertToSqlString((Name, Description))\r
+        SqlCommand = """insert into %s values(%s, %s, '%s', '%s')""" % (self.Table, self.ID, CrossIndex, Name, Description)\r
+        Table.Insert(self, SqlCommand)\r
+        \r
+        return self.ID\r
+    \r
+    ## Init table\r
+    #\r
+    # Create all default records of table DataModel\r
+    #  \r
+    def InitTable(self):\r
+        EdkLogger.verbose("\nInitialize table DataModel started ...")\r
+        for Item in DataClass.MODEL_LIST:\r
+            CrossIndex = Item[1]\r
+            Name = Item[0]\r
+            Description = Item[0]\r
+            self.Insert(CrossIndex, Name, Description)\r
+        EdkLogger.verbose("Initialize table DataModel ... DONE!")\r
+    \r
+    ## Get CrossIndex\r
+    #\r
+    # Get a model's cross index from its name\r
+    #\r
+    # @param ModelName:    Name of the model\r
+    # @retval CrossIndex:  CrossIndex of the model\r
+    #\r
+    def GetCrossIndex(self, ModelName):\r
+        CrossIndex = -1\r
+        SqlCommand = """select CrossIndex from DataModel where name = '""" + ModelName + """'"""\r
+        self.Cur.execute(SqlCommand)\r
+        for Item in self.Cur:\r
+            CrossIndex = Item[0]\r
+        \r
+        return CrossIndex\r