Home | History | Annotate | Download | only in Table
      1 ## @file

      2 # This file is used to create/update/query/erase table for inf 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 ## TableInf

     23 #

     24 # This class defined a table used for data model

     25 # 

     26 # @param object:       Inherited from object class

     27 #

     28 #

     29 class TableInf(Table):
     30     def __init__(self, Cursor):
     31         Table.__init__(self, Cursor)
     32         self.Table = 'Inf'
     33     
     34     ## Create table

     35     #

     36     # Create table Inf

     37     #

     38     # @param ID:             ID of a Inf item

     39     # @param Model:          Model of a Inf item

     40     # @param Value1:         Value1 of a Inf item

     41     # @param Value2:         Value2 of a Inf item

     42     # @param Value3:         Value3 of a Inf item

     43     # @param Value4:         Value4 of a Inf item

     44     # @param Value5:         Value5 of a Inf item

     45     # @param Arch:           Arch of a Inf item

     46     # @param BelongsToItem:  The item belongs to which another item

     47     # @param BelongsToFile:  The item belongs to which dsc file

     48     # @param StartLine:      StartLine of a Inf item

     49     # @param StartColumn:    StartColumn of a Inf item

     50     # @param EndLine:        EndLine of a Inf item

     51     # @param EndColumn:      EndColumn of a Inf item

     52     # @param Enabled:        If this item enabled

     53     #

     54     def Create(self):
     55         SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
     56                                                        Model INTEGER NOT NULL,
     57                                                        Value1 VARCHAR NOT NULL,
     58                                                        Value2 VARCHAR,
     59                                                        Value3 VARCHAR,
     60                                                        Value4 VARCHAR,
     61                                                        Value5 VARCHAR,
     62                                                        Arch VarCHAR,
     63                                                        BelongsToItem SINGLE NOT NULL,
     64                                                        BelongsToFile SINGLE NOT NULL,
     65                                                        StartLine INTEGER NOT NULL,
     66                                                        StartColumn INTEGER NOT NULL,
     67                                                        EndLine INTEGER NOT NULL,
     68                                                        EndColumn INTEGER NOT NULL,
     69                                                        Enabled INTEGER DEFAULT 0
     70                                                       )""" % self.Table
     71         Table.Create(self, SqlCommand)
     72 
     73     ## Insert table

     74     #

     75     # Insert a record into table Inf

     76     #

     77     # @param ID:             ID of a Inf item

     78     # @param Model:          Model of a Inf item

     79     # @param Value1:         Value1 of a Inf item

     80     # @param Value2:         Value2 of a Inf item

     81     # @param Value3:         Value3 of a Inf item

     82     # @param Value4:         Value4 of a Inf item

     83     # @param Value5:         Value5 of a Inf item

     84     # @param Arch:           Arch of a Inf item

     85     # @param BelongsToItem:  The item belongs to which another item

     86     # @param BelongsToFile:  The item belongs to which dsc file

     87     # @param StartLine:      StartLine of a Inf item

     88     # @param StartColumn:    StartColumn of a Inf item

     89     # @param EndLine:        EndLine of a Inf item

     90     # @param EndColumn:      EndColumn of a Inf item

     91     # @param Enabled:        If this item enabled

     92     #

     93     def Insert(self, Model, Value1, Value2, Value3, Value4, Value5, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled):
     94         self.ID = self.ID + 1
     95         (Value1, Value2, Value3, Value4, Value5, Arch) = ConvertToSqlString((Value1, Value2, Value3, Value4, Value5, Arch))
     96         SqlCommand = """insert into %s values(%s, %s, '%s', '%s', '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s)""" \
     97                      % (self.Table, self.ID, Model, Value1, Value2, Value3, Value4, Value5, Arch, BelongsToItem, BelongsToFile, StartLine, StartColumn, EndLine, EndColumn, Enabled)
     98         Table.Insert(self, SqlCommand)
     99         
    100         return self.ID
    101     
    102     ## Query table

    103     #

    104     # @param Model:  The Model of Record 

    105     #

    106     # @retval:       A recordSet of all found records 

    107     #

    108     def Query(self, Model):
    109         SqlCommand = """select ID, Value1, Value2, Value3, Arch, BelongsToItem, BelongsToFile, StartLine from %s
    110                         where Model = %s
    111                         and Enabled > -1""" % (self.Table, Model)
    112         EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand)
    113         self.Cur.execute(SqlCommand)
    114         return self.Cur.fetchall()
    115