130fdf1140b8d1ce93f3821d986fa165552023440lgao## @file 230fdf1140b8d1ce93f3821d986fa165552023440lgao# This file is used to create/update/query/erase table for fdf datas 330fdf1140b8d1ce93f3821d986fa165552023440lgao# 440d841f6a8f84e75409178e19e69b95e01bada0flgao# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR> 540d841f6a8f84e75409178e19e69b95e01bada0flgao# This program and the accompanying materials 630fdf1140b8d1ce93f3821d986fa165552023440lgao# are licensed and made available under the terms and conditions of the BSD License 730fdf1140b8d1ce93f3821d986fa165552023440lgao# which accompanies this distribution. The full text of the license may be found at 830fdf1140b8d1ce93f3821d986fa165552023440lgao# http://opensource.org/licenses/bsd-license.php 930fdf1140b8d1ce93f3821d986fa165552023440lgao# 1030fdf1140b8d1ce93f3821d986fa165552023440lgao# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 1130fdf1140b8d1ce93f3821d986fa165552023440lgao# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 1230fdf1140b8d1ce93f3821d986fa165552023440lgao# 1330fdf1140b8d1ce93f3821d986fa165552023440lgao 1430fdf1140b8d1ce93f3821d986fa165552023440lgao## 1530fdf1140b8d1ce93f3821d986fa165552023440lgao# Import Modules 1630fdf1140b8d1ce93f3821d986fa165552023440lgao# 1730fdf1140b8d1ce93f3821d986fa165552023440lgaoimport Common.EdkLogger as EdkLogger 1830fdf1140b8d1ce93f3821d986fa165552023440lgaoimport CommonDataClass.DataClass as DataClass 1930fdf1140b8d1ce93f3821d986fa165552023440lgaofrom Table import Table 2030fdf1140b8d1ce93f3821d986fa165552023440lgaofrom Common.String import ConvertToSqlString 2130fdf1140b8d1ce93f3821d986fa165552023440lgao 2230fdf1140b8d1ce93f3821d986fa165552023440lgao## TableFdf 2330fdf1140b8d1ce93f3821d986fa165552023440lgao# 2430fdf1140b8d1ce93f3821d986fa165552023440lgao# This class defined a table used for data model 2530fdf1140b8d1ce93f3821d986fa165552023440lgao# 2630fdf1140b8d1ce93f3821d986fa165552023440lgao# @param object: Inherited from object class 2730fdf1140b8d1ce93f3821d986fa165552023440lgao# 2830fdf1140b8d1ce93f3821d986fa165552023440lgao# 2930fdf1140b8d1ce93f3821d986fa165552023440lgaoclass TableFdf(Table): 3030fdf1140b8d1ce93f3821d986fa165552023440lgao def __init__(self, Cursor): 3130fdf1140b8d1ce93f3821d986fa165552023440lgao Table.__init__(self, Cursor) 3230fdf1140b8d1ce93f3821d986fa165552023440lgao self.Table = 'Fdf' 3330fdf1140b8d1ce93f3821d986fa165552023440lgao 3430fdf1140b8d1ce93f3821d986fa165552023440lgao ## Create table 3530fdf1140b8d1ce93f3821d986fa165552023440lgao # 3630fdf1140b8d1ce93f3821d986fa165552023440lgao # Create table Fdf 3730fdf1140b8d1ce93f3821d986fa165552023440lgao # 3830fdf1140b8d1ce93f3821d986fa165552023440lgao # @param ID: ID of a Fdf item 3930fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Model: Model of a Fdf item 4030fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Value1: Value1 of a Fdf item 4130fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Value2: Value2 of a Fdf item 4230fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Value3: Value3 of a Fdf item 4330fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Arch: Arch of a Fdf item 4430fdf1140b8d1ce93f3821d986fa165552023440lgao # @param BelongsToItem: The item belongs to which another item 4530fdf1140b8d1ce93f3821d986fa165552023440lgao # @param BelongsToFile: The item belongs to which fdf file 4630fdf1140b8d1ce93f3821d986fa165552023440lgao # @param StartLine: StartLine of a Fdf item 4730fdf1140b8d1ce93f3821d986fa165552023440lgao # @param StartColumn: StartColumn of a Fdf item 4830fdf1140b8d1ce93f3821d986fa165552023440lgao # @param EndLine: EndLine of a Fdf item 4930fdf1140b8d1ce93f3821d986fa165552023440lgao # @param EndColumn: EndColumn of a Fdf item 5030fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Enabled: If this item enabled 5130fdf1140b8d1ce93f3821d986fa165552023440lgao # 5230fdf1140b8d1ce93f3821d986fa165552023440lgao def Create(self): 5330fdf1140b8d1ce93f3821d986fa165552023440lgao SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY, 5430fdf1140b8d1ce93f3821d986fa165552023440lgao Model INTEGER NOT NULL, 5530fdf1140b8d1ce93f3821d986fa165552023440lgao Value1 VARCHAR NOT NULL, 5630fdf1140b8d1ce93f3821d986fa165552023440lgao Value2 VARCHAR, 5730fdf1140b8d1ce93f3821d986fa165552023440lgao Value3 VARCHAR, 58d0acc87a41d9aa25fe87eb096efa62afacd1f865lgao Scope1 VarCHAR, 59d0acc87a41d9aa25fe87eb096efa62afacd1f865lgao Scope2 VarCHAR, 6030fdf1140b8d1ce93f3821d986fa165552023440lgao BelongsToItem SINGLE NOT NULL, 6130fdf1140b8d1ce93f3821d986fa165552023440lgao BelongsToFile SINGLE NOT NULL, 6230fdf1140b8d1ce93f3821d986fa165552023440lgao StartLine INTEGER NOT NULL, 6330fdf1140b8d1ce93f3821d986fa165552023440lgao StartColumn INTEGER NOT NULL, 6430fdf1140b8d1ce93f3821d986fa165552023440lgao EndLine INTEGER NOT NULL, 6530fdf1140b8d1ce93f3821d986fa165552023440lgao EndColumn INTEGER NOT NULL, 6630fdf1140b8d1ce93f3821d986fa165552023440lgao Enabled INTEGER DEFAULT 0 6730fdf1140b8d1ce93f3821d986fa165552023440lgao )""" % self.Table 6830fdf1140b8d1ce93f3821d986fa165552023440lgao Table.Create(self, SqlCommand) 6930fdf1140b8d1ce93f3821d986fa165552023440lgao 7030fdf1140b8d1ce93f3821d986fa165552023440lgao ## Insert table 7130fdf1140b8d1ce93f3821d986fa165552023440lgao # 7230fdf1140b8d1ce93f3821d986fa165552023440lgao # Insert a record into table Fdf 7330fdf1140b8d1ce93f3821d986fa165552023440lgao # 7430fdf1140b8d1ce93f3821d986fa165552023440lgao # @param ID: ID of a Fdf item 7530fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Model: Model of a Fdf item 7630fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Value1: Value1 of a Fdf item 7730fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Value2: Value2 of a Fdf item 7830fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Value3: Value3 of a Fdf item 7930fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Arch: Arch of a Fdf item 8030fdf1140b8d1ce93f3821d986fa165552023440lgao # @param BelongsToItem: The item belongs to which another item 8130fdf1140b8d1ce93f3821d986fa165552023440lgao # @param BelongsToFile: The item belongs to which fdf file 8230fdf1140b8d1ce93f3821d986fa165552023440lgao # @param StartLine: StartLine of a Fdf item 8330fdf1140b8d1ce93f3821d986fa165552023440lgao # @param StartColumn: StartColumn of a Fdf item 8430fdf1140b8d1ce93f3821d986fa165552023440lgao # @param EndLine: EndLine of a Fdf item 8530fdf1140b8d1ce93f3821d986fa165552023440lgao # @param EndColumn: EndColumn of a Fdf item 8630fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Enabled: If this item enabled 8730fdf1140b8d1ce93f3821d986fa165552023440lgao # 88d0acc87a41d9aa25fe87eb096efa62afacd1f865lgao def Insert(self, Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled): 8930fdf1140b8d1ce93f3821d986fa165552023440lgao self.ID = self.ID + 1 90d0acc87a41d9aa25fe87eb096efa62afacd1f865lgao (Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2)) 91d0acc87a41d9aa25fe87eb096efa62afacd1f865lgao SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \ 92d0acc87a41d9aa25fe87eb096efa62afacd1f865lgao % (self.Table, self.ID, Model, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled) 9330fdf1140b8d1ce93f3821d986fa165552023440lgao Table.Insert(self, SqlCommand) 9430fdf1140b8d1ce93f3821d986fa165552023440lgao 9530fdf1140b8d1ce93f3821d986fa165552023440lgao return self.ID 9630fdf1140b8d1ce93f3821d986fa165552023440lgao 9730fdf1140b8d1ce93f3821d986fa165552023440lgao ## Query table 9830fdf1140b8d1ce93f3821d986fa165552023440lgao # 9930fdf1140b8d1ce93f3821d986fa165552023440lgao # @param Model: The Model of Record 10030fdf1140b8d1ce93f3821d986fa165552023440lgao # 10130fdf1140b8d1ce93f3821d986fa165552023440lgao # @retval: A recordSet of all found records 10230fdf1140b8d1ce93f3821d986fa165552023440lgao # 10330fdf1140b8d1ce93f3821d986fa165552023440lgao def Query(self, Model): 104d0acc87a41d9aa25fe87eb096efa62afacd1f865lgao SqlCommand = """select ID, Value1, Value2, Value3, Scope1, Scope2, BelongsToItem, BelongsToFile, StartLine from %s 10530fdf1140b8d1ce93f3821d986fa165552023440lgao where Model = %s 10630fdf1140b8d1ce93f3821d986fa165552023440lgao and Enabled > -1""" % (self.Table, Model) 10730fdf1140b8d1ce93f3821d986fa165552023440lgao EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) 10830fdf1140b8d1ce93f3821d986fa165552023440lgao self.Cur.execute(SqlCommand) 10930fdf1140b8d1ce93f3821d986fa165552023440lgao return self.Cur.fetchall() 110