]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Table/Table.py
2 # This file is used to create/update/query/erase a common table
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
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.
17 import Common
.EdkLogger
as EdkLogger
21 # This class defined a common table
23 # @param object: Inherited from object class
25 # @param Cursor: Cursor of the database
26 # @param TableName: Name of the table
29 def __init__(self
, Cursor
):
38 def Create(self
, SqlCommand
):
39 self
.Cur
.execute(SqlCommand
)
41 EdkLogger
.verbose(SqlCommand
+ " ... DONE!")
45 # Insert a record into a table
47 def Insert(self
, SqlCommand
):
52 # Query all records of the table
55 EdkLogger
.verbose("\nQuery tabel %s started ..." % self
.Table
)
56 SqlCommand
= """select * from %s""" % self
.Table
57 self
.Cur
.execute(SqlCommand
)
59 EdkLogger
.verbose(str(Rs
))
61 TotalCount
= self
.GetCount()
62 EdkLogger
.verbose("*** Total %s records in table %s ***" % (TotalCount
, self
.Table
) )
63 EdkLogger
.verbose("Query tabel %s DONE!" % self
.Table
)
70 SqlCommand
= """drop table IF EXISTS %s""" % self
.Table
71 self
.Cur
.execute(SqlCommand
)
72 EdkLogger
.verbose("Drop tabel %s ... DONE!" % self
.Table
)
76 # Get a count of all records of the table
78 # @retval Count: Total count of all records
81 SqlCommand
= """select count(ID) from %s""" % self
.Table
82 self
.Cur
.execute(SqlCommand
)
88 # Generate an ID if input ID is -1
92 # @retval ID: New generated ID
94 def GenerateID(self
, ID
):
100 ## Init the ID of the table
102 # Init the ID of the table
105 self
.ID
= self
.GetCount()
109 # Exec Sql Command, return result
111 # @param SqlCommand: The SqlCommand to be executed
113 # @retval RecordSet: The result after executed
115 def Exec(self
, SqlCommand
):
116 EdkLogger
.debug(4, "SqlCommand: %s" % SqlCommand
)
117 self
.Cur
.execute(SqlCommand
)
118 RecordSet
= self
.Cur
.fetchall()
119 EdkLogger
.debug(4, "RecordSet: %s" % RecordSet
)