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

      2 # This file is used to create/update/query/erase table for pcds

      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 from Table import Table
     19 from Common.String import ConvertToSqlString
     20 
     21 ## TablePcd

     22 #

     23 # This class defined a table used for pcds

     24 # 

     25 # @param object:       Inherited from object class

     26 #

     27 #

     28 class TablePcd(Table):
     29     def __init__(self, Cursor):
     30         Table.__init__(self, Cursor)
     31         self.Table = 'Pcd'
     32     
     33     ## Create table

     34     #

     35     # Create table Pcd

     36     #

     37     # @param ID:                   ID of a Pcd

     38     # @param CName:                CName of a Pcd

     39     # @param TokenSpaceGuidCName:  TokenSpaceGuidCName of a Pcd

     40     # @param Token:                Token of a Pcd

     41     # @param DatumType:            DatumType of a Pcd

     42     # @param Model:                Model of a Pcd

     43     # @param BelongsToFile:        The Pcd belongs to which file

     44     # @param BelongsToFunction:    The Pcd belongs to which function

     45     # @param StartLine:            StartLine of a Pcd

     46     # @param StartColumn:          StartColumn of a Pcd

     47     # @param EndLine:              EndLine of a Pcd

     48     # @param EndColumn:            EndColumn of a Pcd

     49     #

     50     def Create(self):
     51         SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
     52                                                        CName VARCHAR NOT NULL,
     53                                                        TokenSpaceGuidCName VARCHAR NOT NULL,
     54                                                        Token INTEGER,
     55                                                        DatumType VARCHAR,
     56                                                        Model INTEGER NOT NULL,
     57                                                        BelongsToFile SINGLE NOT NULL,
     58                                                        BelongsToFunction SINGLE DEFAULT -1,
     59                                                        StartLine INTEGER NOT NULL,
     60                                                        StartColumn INTEGER NOT NULL,
     61                                                        EndLine INTEGER NOT NULL,
     62                                                        EndColumn INTEGER NOT NULL
     63                                                       )""" % self.Table
     64         Table.Create(self, SqlCommand)
     65 
     66     ## Insert table

     67     #

     68     # Insert a record into table Pcd

     69     #

     70     # @param ID:                   ID of a Pcd

     71     # @param CName:                CName of a Pcd

     72     # @param TokenSpaceGuidCName:  TokenSpaceGuidCName of a Pcd

     73     # @param Token:                Token of a Pcd

     74     # @param DatumType:            DatumType of a Pcd

     75     # @param Model:                Model of a Pcd

     76     # @param BelongsToFile:        The Pcd belongs to which file

     77     # @param BelongsToFunction:    The Pcd belongs to which function

     78     # @param StartLine:            StartLine of a Pcd

     79     # @param StartColumn:          StartColumn of a Pcd

     80     # @param EndLine:              EndLine of a Pcd

     81     # @param EndColumn:            EndColumn of a Pcd

     82     #

     83     def Insert(self, CName, TokenSpaceGuidCName, Token, DatumType, Model, BelongsToFile, BelongsToFunction, StartLine, StartColumn, EndLine, EndColumn):
     84         self.ID = self.ID + 1
     85         (CName, TokenSpaceGuidCName, DatumType) = ConvertToSqlString((CName, TokenSpaceGuidCName, DatumType))
     86         SqlCommand = """insert into %s values(%s, '%s', '%s', %s, '%s', %s, %s, %s, %s, %s, %s, %s)""" \
     87                                            % (self.Table, self.ID, CName, TokenSpaceGuidCName, Token, DatumType, Model, BelongsToFile, BelongsToFunction, StartLine, StartColumn, EndLine, EndColumn)
     88         Table.Insert(self, SqlCommand)
     89 
     90         return self.ID