]>
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 # 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 from __future__
import absolute_import
18 import Common
.EdkLogger
as EdkLogger
19 import CommonDataClass
.DataClass
as DataClass
20 from Table
.Table
import Table
21 from Common
.StringUtils
import ConvertToSqlString
25 # This class defined a table used for data model
27 # @param object: Inherited from object class
30 class TableDataModel(Table
):
31 def __init__(self
, Cursor
):
32 Table
.__init
__(self
, Cursor
)
33 self
.Table
= 'DataModel'
37 # Create table DataModel
39 # @param ID: ID of a ModelType
40 # @param CrossIndex: CrossIndex of a ModelType
41 # @param Name: Name of a ModelType
42 # @param Description: Description of a ModelType
45 SqlCommand
= """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
46 CrossIndex INTEGER NOT NULL,
47 Name VARCHAR NOT NULL,
50 Table
.Create(self
, SqlCommand
)
54 # Insert a record into table DataModel
56 # @param ID: ID of a ModelType
57 # @param CrossIndex: CrossIndex of a ModelType
58 # @param Name: Name of a ModelType
59 # @param Description: Description of a ModelType
61 def Insert(self
, CrossIndex
, Name
, Description
):
63 (Name
, Description
) = ConvertToSqlString((Name
, Description
))
64 SqlCommand
= """insert into %s values(%s, %s, '%s', '%s')""" % (self
.Table
, self
.ID
, CrossIndex
, Name
, Description
)
65 Table
.Insert(self
, SqlCommand
)
71 # Create all default records of table DataModel
74 EdkLogger
.verbose("\nInitialize table DataModel started ...")
75 for Item
in DataClass
.MODEL_LIST
:
79 self
.Insert(CrossIndex
, Name
, Description
)
80 EdkLogger
.verbose("Initialize table DataModel ... DONE!")
84 # Get a model's cross index from its name
86 # @param ModelName: Name of the model
87 # @retval CrossIndex: CrossIndex of the model
89 def GetCrossIndex(self
, ModelName
):
91 SqlCommand
= """select CrossIndex from DataModel where name = '""" + ModelName
+ """'"""
92 self
.Cur
.execute(SqlCommand
)