1 ## @file 2 # This file is used to create/update/query/erase table for dec datas 3 # 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 9 # 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. 12 # 13 14 ## 15 # Import Modules 16 # 17 import Common.EdkLogger as EdkLogger 18 import CommonDataClass.DataClass as DataClass 19 from Table import Table 20 from Common.String import ConvertToSqlString 21 22 ## TableDec 23 # 24 # This class defined a table used for data model 25 # 26 # @param object: Inherited from object class 27 # 28 # 29 class TableDec(Table): 30 def __init__(self, Cursor): 31 Table.__init__(self, Cursor) 32 self.Table = 'Dec' 33 34 ## Create table 35 # 36 # Create table Dec 37 # 38 # @param ID: ID of a Dec item 39 # @param Model: Model of a Dec item 40 # @param Value1: Value1 of a Dec item 41 # @param Value2: Value2 of a Dec item 42 # @param Value3: Value3 of a Dec item 43 # @param Arch: Arch of a Dec item 44 # @param BelongsToItem: The item belongs to which another item 45 # @param BelongsToFile: The item belongs to which dsc file 46 # @param StartLine: StartLine of a Dec item 47 # @param StartColumn: StartColumn of a Dec item 48 # @param EndLine: EndLine of a Dec item 49 # @param EndColumn: EndColumn of a Dec item 50 # @param Enabled: If this item enabled 51 # 52 def Create(self): 53 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY, 54 Model INTEGER NOT NULL, 55 Value1 VARCHAR NOT NULL, 56 Value2 VARCHAR, 57 Value3 VARCHAR, 58 Arch VarCHAR, 59 BelongsToItem SINGLE NOT NULL, 60 BelongsToFile SINGLE NOT NULL, 61 StartLine INTEGER NOT NULL, 62 StartColumn INTEGER NOT NULL, 63 EndLine INTEGER NOT NULL, 64 EndColumn INTEGER NOT NULL, 65 Enabled INTEGER DEFAULT 0 66 )""" % self.Table 67 Table.Create(self, SqlCommand) 68 69 ## Insert table 70 # 71 # Insert a record into table Dec 72 # 73 # @param ID: ID of a Dec item 74 # @param Model: Model of a Dec item 75 # @param Value1: Value1 of a Dec item 76 # @param Value2: Value2 of a Dec item 77 # @param Value3: Value3 of a Dec item 78 # @param Arch: Arch of a Dec item 79 # @param BelongsToItem: The item belongs to which another item 80 # @param BelongsToFile: The item belongs to which dsc file 81 # @param StartLine: StartLine of a Dec item 82 # @param StartColumn: StartColumn of a Dec item 83 # @param EndLine: EndLine of a Dec item 84 # @param EndColumn: EndColumn of a Dec item 85 # @param Enabled: If this item enabled 86 # 87 def Insert(self, Model, Value1, Value2, Value3, Value4, Value5, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled): 88 self.ID = self.ID + 1 89 (Value1, Value2, Value3, Arch) = ConvertToSqlString((Value1, Value2, Value3, Arch)) 90 SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \ 91 % (self.Table, self.ID, Model, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled) 92 Table.Insert(self, SqlCommand) 93 94 return self.ID 95 96 ## Query table 97 # 98 # @param Model: The Model of Record 99 # 100 # @retval: A recordSet of all found records 101 # 102 def Query(self, Model): 103 SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s 104 where Model = %s 105 and Enabled > -1""" % (self.Table, Model) 106 EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) 107 self.Cur.execute(SqlCommand) 108 return self.Cur.fetchall() 109