]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/Database.py
2 # This file is used to create a database used by ECC tool
4 # Copyright (c) 2007 - 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.
20 import EdkLogger
as EdkLogger
21 from CommonDataClass
.DataClass
import *
23 from DataType
import *
25 from Table
.TableDataModel
import TableDataModel
26 from Table
.TableFile
import TableFile
27 from Table
.TableInf
import TableInf
28 from Table
.TableDec
import TableDec
29 from Table
.TableDsc
import TableDsc
33 # This class defined the build databse
34 # During the phase of initialization, the database will create all tables and
35 # insert all records of table DataModel
37 # @param object: Inherited from object class
38 # @param DbPath: A string for the path of the ECC database
40 # @var Conn: Connection of the ECC database
41 # @var Cur: Cursor of the connection
42 # @var TblDataModel: Local instance for TableDataModel
44 class Database(object):
45 def __init__(self
, DbPath
):
46 if os
.path
.exists(DbPath
):
48 self
.Conn
= sqlite3
.connect(DbPath
, isolation_level
= 'DEFERRED')
49 self
.Conn
.execute("PRAGMA page_size=8192")
50 self
.Conn
.execute("PRAGMA synchronous=OFF")
51 self
.Cur
= self
.Conn
.cursor()
52 self
.TblDataModel
= TableDataModel(self
.Cur
)
53 self
.TblFile
= TableFile(self
.Cur
)
54 self
.TblInf
= TableInf(self
.Cur
)
55 self
.TblDec
= TableDec(self
.Cur
)
56 self
.TblDsc
= TableDsc(self
.Cur
)
58 ## Initialize build database
60 # 1. Delete all old existing tables
61 # 2. Create new tables
62 # 3. Initialize table DataModel
64 def InitDatabase(self
):
65 EdkLogger
.verbose("\nInitialize ECC database started ...")
67 # Drop all old existing tables
69 # self.TblDataModel.Drop()
76 self
.TblDataModel
.Create()
83 # Initialize table DataModel
85 self
.TblDataModel
.InitTable()
86 EdkLogger
.verbose("Initialize ECC database ... DONE!")
90 # @param Table: The instance of the table to be queried
92 def QueryTable(self
, Table
):
95 ## Close entire database
98 # Close the connection and cursor
107 # This acts like the main() function for the script, unless it is 'import'ed into another
110 if __name__
== '__main__':
111 EdkLogger
.Initialize()
112 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
114 Db
= Database(DATABASE_PATH
)
116 Db
.QueryTable(Db
.TblDataModel
)
117 Db
.QueryTable(Db
.TblFile
)
118 Db
.QueryTable(Db
.TblDsc
)