]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Table/TableDataModel.py
2 # This file is used to create/update/query/erase table for data models
4 # Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
5 # This program and the accompanying materials
6 # are licensed and made available under the terms and conditions of the BSD License
7 # which accompanies this distribution. The full text of the license may be found at
8 # http://opensource.org/licenses/bsd-license.php
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 import Common
.EdkLogger
as EdkLogger
18 import CommonDataClass
.DataClass
as DataClass
19 from Table
import Table
20 from Common
.String
import ConvertToSqlString
24 # This class defined a table used for data model
26 # @param object: Inherited from object class
29 class TableDataModel(Table
):
30 def __init__(self
, Cursor
):
31 Table
.__init
__(self
, Cursor
)
32 self
.Table
= 'DataModel'
36 # Create table DataModel
38 # @param ID: ID of a ModelType
39 # @param CrossIndex: CrossIndex of a ModelType
40 # @param Name: Name of a ModelType
41 # @param Description: Description of a ModelType
44 SqlCommand
= """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
45 CrossIndex INTEGER NOT NULL,
46 Name VARCHAR NOT NULL,
49 Table
.Create(self
, SqlCommand
)
53 # Insert a record into table DataModel
55 # @param ID: ID of a ModelType
56 # @param CrossIndex: CrossIndex of a ModelType
57 # @param Name: Name of a ModelType
58 # @param Description: Description of a ModelType
60 def Insert(self
, CrossIndex
, Name
, Description
):
62 (Name
, Description
) = ConvertToSqlString((Name
, Description
))
63 SqlCommand
= """insert into %s values(%s, %s, '%s', '%s')""" % (self
.Table
, self
.ID
, CrossIndex
, Name
, Description
)
64 Table
.Insert(self
, SqlCommand
)
70 # Create all default records of table DataModel
73 EdkLogger
.verbose("\nInitialize table DataModel started ...")
74 for Item
in DataClass
.MODEL_LIST
:
78 self
.Insert(CrossIndex
, Name
, Description
)
79 EdkLogger
.verbose("Initialize table DataModel ... DONE!")
83 # Get a model's cross index from its name
85 # @param ModelName: Name of the model
86 # @retval CrossIndex: CrossIndex of the model
88 def GetCrossIndex(self
, ModelName
):
90 SqlCommand
= """select CrossIndex from DataModel where name = '""" + ModelName
+ """'"""
91 self
.Cur
.execute(SqlCommand
)