]>
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 - 2018, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 from __future__
import absolute_import
12 import Common
.EdkLogger
as EdkLogger
13 import CommonDataClass
.DataClass
as DataClass
14 from Table
.Table
import Table
15 from Common
.StringUtils
import ConvertToSqlString
19 # This class defined a table used for data model
21 # @param object: Inherited from object class
24 class TableDataModel(Table
):
25 def __init__(self
, Cursor
):
26 Table
.__init
__(self
, Cursor
)
27 self
.Table
= 'DataModel'
31 # Create table DataModel
33 # @param ID: ID of a ModelType
34 # @param CrossIndex: CrossIndex of a ModelType
35 # @param Name: Name of a ModelType
36 # @param Description: Description of a ModelType
39 SqlCommand
= """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
40 CrossIndex INTEGER NOT NULL,
41 Name VARCHAR NOT NULL,
44 Table
.Create(self
, SqlCommand
)
48 # Insert a record into table DataModel
50 # @param ID: ID of a ModelType
51 # @param CrossIndex: CrossIndex of a ModelType
52 # @param Name: Name of a ModelType
53 # @param Description: Description of a ModelType
55 def Insert(self
, CrossIndex
, Name
, Description
):
57 (Name
, Description
) = ConvertToSqlString((Name
, Description
))
58 SqlCommand
= """insert into %s values(%s, %s, '%s', '%s')""" % (self
.Table
, self
.ID
, CrossIndex
, Name
, Description
)
59 Table
.Insert(self
, SqlCommand
)
65 # Create all default records of table DataModel
68 EdkLogger
.verbose("\nInitialize table DataModel started ...")
69 for Item
in DataClass
.MODEL_LIST
:
73 self
.Insert(CrossIndex
, Name
, Description
)
74 EdkLogger
.verbose("Initialize table DataModel ... DONE!")
78 # Get a model's cross index from its name
80 # @param ModelName: Name of the model
81 # @retval CrossIndex: CrossIndex of the model
83 def GetCrossIndex(self
, ModelName
):
85 SqlCommand
= """select CrossIndex from DataModel where name = '""" + ModelName
+ """'"""
86 self
.Cur
.execute(SqlCommand
)