2 # This file is used to create/update/query/erase a common table
\r
4 # Copyright (c) 2008, Intel Corporation
\r
5 # All rights reserved. This program and the accompanying materials
\r
6 # are licensed and made available under the terms and conditions of the BSD License
\r
7 # which accompanies this distribution. The full text of the license may be found at
\r
8 # http://opensource.org/licenses/bsd-license.php
\r
10 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
11 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
17 import Common.EdkLogger as EdkLogger
\r
21 # This class defined a common table
\r
23 # @param object: Inherited from object class
\r
25 # @param Cursor: Cursor of the database
\r
26 # @param TableName: Name of the table
\r
28 class Table(object):
\r
29 def __init__(self, Cursor):
\r
37 def Create(self, SqlCommand):
\r
38 self.Cur.execute(SqlCommand)
\r
39 EdkLogger.verbose(SqlCommand + " ... DONE!")
\r
43 # Insert a record into a table
\r
45 def Insert(self, SqlCommand):
\r
46 self.Cur.execute(SqlCommand)
\r
47 EdkLogger.debug(4, SqlCommand + " ... DONE!")
\r
51 # Query all records of the table
\r
54 EdkLogger.verbose("\nQuery tabel %s started ..." % self.Table)
\r
55 SqlCommand = """select * from %s""" % self.Table
\r
56 self.Cur.execute(SqlCommand)
\r
58 EdkLogger.verbose(Rs)
\r
60 TotalCount = self.GetCount()
\r
61 EdkLogger.verbose("*** Total %s records in table %s ***" % (TotalCount, self.Table) )
\r
62 EdkLogger.verbose("Query tabel %s DONE!" % self.Table)
\r
69 SqlCommand = """drop table IF EXISTS %s""" % self.Table
\r
70 self.Cur.execute(SqlCommand)
\r
71 EdkLogger.verbose("Drop tabel %s ... DONE!" % self.Table)
\r
75 # Get a count of all records of the table
\r
77 # @retval Count: Total count of all records
\r
80 SqlCommand = """select count(*) as Count from %s""" % self.Table
\r
81 self.Cur.execute(SqlCommand)
\r
82 for Item in self.Cur:
\r