]>
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 - 2018, 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 from __future__
import absolute_import
19 import Common
.LongFilePathOs
as os
21 from . import EdkLogger
as EdkLogger
22 from CommonDataClass
.DataClass
import *
23 from .StringUtils
import *
24 from .DataType
import *
26 from Table
.TableDataModel
import TableDataModel
27 from Table
.TableFile
import TableFile
28 from Table
.TableInf
import TableInf
29 from Table
.TableDec
import TableDec
30 from Table
.TableDsc
import TableDsc
34 # This class defined the build databse
35 # During the phase of initialization, the database will create all tables and
36 # insert all records of table DataModel
38 # @param object: Inherited from object class
39 # @param DbPath: A string for the path of the ECC database
41 # @var Conn: Connection of the ECC database
42 # @var Cur: Cursor of the connection
43 # @var TblDataModel: Local instance for TableDataModel
45 class Database(object):
46 def __init__(self
, DbPath
):
47 if os
.path
.exists(DbPath
):
49 self
.Conn
= sqlite3
.connect(DbPath
, isolation_level
= 'DEFERRED')
50 self
.Conn
.execute("PRAGMA page_size=8192")
51 self
.Conn
.execute("PRAGMA synchronous=OFF")
52 self
.Cur
= self
.Conn
.cursor()
53 self
.TblDataModel
= TableDataModel(self
.Cur
)
54 self
.TblFile
= TableFile(self
.Cur
)
55 self
.TblInf
= TableInf(self
.Cur
)
56 self
.TblDec
= TableDec(self
.Cur
)
57 self
.TblDsc
= TableDsc(self
.Cur
)
59 ## Initialize build database
61 # 1. Delete all old existing tables
62 # 2. Create new tables
63 # 3. Initialize table DataModel
65 def InitDatabase(self
):
66 EdkLogger
.verbose("\nInitialize ECC database started ...")
68 # Drop all old existing tables
70 # self.TblDataModel.Drop()
77 self
.TblDataModel
.Create()
84 # Initialize table DataModel
86 self
.TblDataModel
.InitTable()
87 EdkLogger
.verbose("Initialize ECC database ... DONE!")
91 # @param Table: The instance of the table to be queried
93 def QueryTable(self
, Table
):
96 ## Close entire database
99 # Close the connection and cursor
108 # This acts like the main() function for the script, unless it is 'import'ed into another
111 if __name__
== '__main__':
112 EdkLogger
.Initialize()
113 EdkLogger
.SetLevel(EdkLogger
.DEBUG_0
)
115 Db
= Database(DATABASE_PATH
)
117 Db
.QueryTable(Db
.TblDataModel
)
118 Db
.QueryTable(Db
.TblFile
)
119 Db
.QueryTable(Db
.TblDsc
)