1## @file
2# This file is used to create/update/query/erase table for Queries
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#
17import Common.EdkLogger as EdkLogger
18from Common.String import ConvertToSqlString
19from Table import Table
20
21## TableQuery
22#
23# This class defined a table used for Query
24#
25# @param object:       Inherited from object class
26#
27#
28class TableQuery(Table):
29    def __init__(self, Cursor):
30        Table.__init__(self, Cursor)
31        self.Table = 'Query'
32
33    ## Create table
34    #
35    # Create table Query
36    #
37    # @param ID:                 ID of a Query
38    # @param Name:               Name of a Query
39    # @param Modifer:            Modifier of a Query
40    # @param Value:              Type of a Query
41    # @param Model:              Model of a Query
42    #
43    def Create(self):
44        SqlCommand = """create table IF NOT EXISTS %s(ID INTEGER PRIMARY KEY,
45                                                      Name TEXT DEFAULT '',
46                                                      Modifier TEXT DEFAULT '',
47                                                      Value TEXT DEFAULT '',
48                                                      Model INTEGER DEFAULT 0
49                                                     )""" % self.Table
50        Table.Create(self, SqlCommand)
51
52    ## Insert table
53    #
54    # Insert a record into table Query
55    #
56    # @param ID:                 ID of a Query
57    # @param Name:               Name of a Query
58    # @param Modifier:           Modifier of a Query
59    # @param Value:              Value of a Query
60    # @param Model:              Model of a Query
61    #
62    def Insert(self, Name, Modifier, Value, Model):
63        self.ID = self.ID + 1
64        SqlCommand = """insert into %s values(%s, '%s', '%s', '%s', %s)""" \
65                                           % (self.Table, self.ID, Name, Modifier, Value, Model)
66        Table.Insert(self, SqlCommand)
67
68        return self.ID
69