]>
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 - 2018, Intel Corporation. All rights reserved.<BR>
5 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 import Common
.EdkLogger
as EdkLogger
15 # This class defined a common table
17 # @param object: Inherited from object class
19 # @param Cursor: Cursor of the database
20 # @param TableName: Name of the table
23 def __init__(self
, Cursor
):
32 def Create(self
, SqlCommand
):
33 self
.Cur
.execute(SqlCommand
)
35 EdkLogger
.verbose(SqlCommand
+ " ... DONE!")
39 # Insert a record into a table
41 def Insert(self
, SqlCommand
):
46 # Query all records of the table
49 EdkLogger
.verbose("\nQuery table %s started ..." % self
.Table
)
50 SqlCommand
= """select * from %s""" % self
.Table
51 self
.Cur
.execute(SqlCommand
)
53 EdkLogger
.verbose(str(Rs
))
55 TotalCount
= self
.GetCount()
56 EdkLogger
.verbose("*** Total %s records in table %s ***" % (TotalCount
, self
.Table
) )
57 EdkLogger
.verbose("Query tabel %s DONE!" % self
.Table
)
64 SqlCommand
= """drop table IF EXISTS %s""" % self
.Table
65 self
.Cur
.execute(SqlCommand
)
66 EdkLogger
.verbose("Drop tabel %s ... DONE!" % self
.Table
)
70 # Get a count of all records of the table
72 # @retval Count: Total count of all records
75 SqlCommand
= """select count(ID) from %s""" % self
.Table
76 self
.Cur
.execute(SqlCommand
)
82 # Generate an ID if input ID is -1
86 # @retval ID: New generated ID
88 def GenerateID(self
, ID
):
94 ## Init the ID of the table
96 # Init the ID of the table
99 self
.ID
= self
.GetCount()
103 # Exec Sql Command, return result
105 # @param SqlCommand: The SqlCommand to be executed
107 # @retval RecordSet: The result after executed
109 def Exec(self
, SqlCommand
):
110 EdkLogger
.debug(4, "SqlCommand: %s" % SqlCommand
)
111 self
.Cur
.execute(SqlCommand
)
112 RecordSet
= self
.Cur
.fetchall()
113 EdkLogger
.debug(4, "RecordSet: %s" % RecordSet
)