summaryrefslogtreecommitdiffstats
path: root/BaseTools/Source/Python/Ecc/Database.py
diff options
context:
space:
mode:
Diffstat (limited to 'BaseTools/Source/Python/Ecc/Database.py')
-rw-r--r--BaseTools/Source/Python/Ecc/Database.py109
1 files changed, 55 insertions, 54 deletions
diff --git a/BaseTools/Source/Python/Ecc/Database.py b/BaseTools/Source/Python/Ecc/Database.py
index 9520be4345..4b79cb708f 100644
--- a/BaseTools/Source/Python/Ecc/Database.py
+++ b/BaseTools/Source/Python/Ecc/Database.py
@@ -41,7 +41,7 @@ DATABASE_PATH = "Ecc.db"
# This class defined the ECC databse
# During the phase of initialization, the database will create all tables and
# insert all records of table DataModel
-#
+#
# @param object: Inherited from object class
# @param DbPath: A string for the path of the ECC database
#
@@ -64,7 +64,7 @@ class Database(object):
self.TblDec = None
self.TblDsc = None
self.TblFdf = None
-
+
## Initialize ECC database
#
# 1. Delete all old existing tables
@@ -85,7 +85,7 @@ class Database(object):
# to avoid non-ascii charater conversion error
self.Conn.text_factory = str
self.Cur = self.Conn.cursor()
-
+
self.TblDataModel = TableDataModel(self.Cur)
self.TblFile = TableFile(self.Cur)
self.TblFunction = TableFunction(self.Cur)
@@ -96,7 +96,7 @@ class Database(object):
self.TblDec = TableDec(self.Cur)
self.TblDsc = TableDsc(self.Cur)
self.TblFdf = TableFdf(self.Cur)
-
+
#
# Create new tables
#
@@ -110,7 +110,7 @@ class Database(object):
self.TblDec.Create()
self.TblDsc.Create()
self.TblFdf.Create()
-
+
#
# Init each table's ID
#
@@ -123,13 +123,13 @@ class Database(object):
self.TblDec.InitID()
self.TblDsc.InitID()
self.TblFdf.InitID()
-
+
#
# Initialize table DataModel
#
if NewDatabase:
self.TblDataModel.InitTable()
-
+
EdkLogger.verbose("Initialize ECC database ... DONE!")
## Query a table
@@ -138,7 +138,7 @@ class Database(object):
#
def QueryTable(self, Table):
Table.Query()
-
+
## Close entire database
#
# Commit all first
@@ -147,15 +147,15 @@ class Database(object):
def Close(self):
#
# Commit to file
- #
+ #
self.Conn.commit()
-
+
#
# Close connection and cursor
#
self.Cur.close()
self.Conn.close()
-
+
## Insert one file information
#
# Insert one file's information to the database
@@ -171,43 +171,44 @@ class Database(object):
# Insert a record for file
#
FileID = self.TblFile.Insert(File.Name, File.ExtName, File.Path, File.FullPath, Model = File.Model, TimeStamp = File.TimeStamp)
- IdTable = TableIdentifier(self.Cur)
- IdTable.Table = "Identifier%s" % FileID
- IdTable.Create()
- #
- # Insert function of file
- #
- for Function in File.FunctionList:
- FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \
- Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \
- Function.BodyStartLine, Function.BodyStartColumn, FileID, \
- Function.FunNameStartLine, Function.FunNameStartColumn)
+ if File.Model == DataClass.MODEL_FILE_C or File.Model == DataClass.MODEL_FILE_H:
+ IdTable = TableIdentifier(self.Cur)
+ IdTable.Table = "Identifier%s" % FileID
+ IdTable.Create()
+ #
+ # Insert function of file
+ #
+ for Function in File.FunctionList:
+ FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \
+ Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \
+ Function.BodyStartLine, Function.BodyStartColumn, FileID, \
+ Function.FunNameStartLine, Function.FunNameStartColumn)
+ #
+ # Insert Identifier of function
+ #
+ for Identifier in Function.IdentifierList:
+ IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
+ FileID, FunctionID, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
+ #
+ # Insert Pcd of function
+ #
+ for Pcd in Function.PcdList:
+ PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \
+ FileID, FunctionID, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)
#
- # Insert Identifier of function
+ # Insert Identifier of file
#
- for Identifier in Function.IdentifierList:
+ for Identifier in File.IdentifierList:
IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
- FileID, FunctionID, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
+ FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
#
- # Insert Pcd of function
+ # Insert Pcd of file
#
- for Pcd in Function.PcdList:
+ for Pcd in File.PcdList:
PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \
- FileID, FunctionID, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)
- #
- # Insert Identifier of file
- #
- for Identifier in File.IdentifierList:
- IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
- FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
- #
- # Insert Pcd of file
- #
- for Pcd in File.PcdList:
- PcdID = self.TblPcd.Insert(Pcd.CName, Pcd.TokenSpaceGuidCName, Pcd.Token, Pcd.DatumType, Pcd.Model, \
- FileID, -1, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)
-
+ FileID, -1, Pcd.StartLine, Pcd.StartColumn, Pcd.EndLine, Pcd.EndColumn)
+
EdkLogger.verbose("Insert information from file %s ... DONE!" % File.FullPath)
## UpdateIdentifierBelongsToFunction
@@ -217,7 +218,7 @@ class Database(object):
#
def UpdateIdentifierBelongsToFunction_disabled(self):
EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")
-
+
SqlCommand = """select ID, BelongsToFile, StartLine, EndLine, Model from Identifier"""
EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
self.Cur.execute(SqlCommand)
@@ -233,7 +234,7 @@ class Database(object):
# Check whether an identifier belongs to a function
#
EdkLogger.debug(4, "For common identifiers ... ")
- SqlCommand = """select ID from Function
+ SqlCommand = """select ID from Function
where StartLine < %s and EndLine > %s
and BelongsToFile = %s""" % (StartLine, EndLine, BelongsToFile)
EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
@@ -243,13 +244,13 @@ class Database(object):
SqlCommand = """Update Identifier set BelongsToFunction = %s where ID = %s""" % (ID[0], IdentifierID)
EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
self.Cur.execute(SqlCommand)
-
+
#
# Check whether the identifier is a function header
#
- EdkLogger.debug(4, "For function headers ... ")
+ EdkLogger.debug(4, "For function headers ... ")
if Model == DataClass.MODEL_IDENTIFIER_COMMENT:
- SqlCommand = """select ID from Function
+ SqlCommand = """select ID from Function
where StartLine = %s + 1
and BelongsToFile = %s""" % (EndLine, BelongsToFile)
EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
@@ -259,7 +260,7 @@ class Database(object):
SqlCommand = """Update Identifier set BelongsToFunction = %s, Model = %s where ID = %s""" % (ID[0], DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, IdentifierID)
EdkLogger.debug(4, "SqlCommand: %s" %SqlCommand)
self.Cur.execute(SqlCommand)
-
+
EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")
@@ -270,7 +271,7 @@ class Database(object):
#
def UpdateIdentifierBelongsToFunction(self):
EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")
-
+
SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function"""
Records = self.TblFunction.Exec(SqlCommand)
Data1 = []
@@ -308,7 +309,7 @@ class Database(object):
# self.Cur.executemany(SqlCommand, Data2)
#
# EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers ... DONE")
-
+
##
#
@@ -320,11 +321,11 @@ if __name__ == '__main__':
#EdkLogger.SetLevel(EdkLogger.VERBOSE)
EdkLogger.SetLevel(EdkLogger.DEBUG_0)
EdkLogger.verbose("Start at " + time.strftime('%H:%M:%S', time.localtime()))
-
+
Db = Database(DATABASE_PATH)
Db.InitDatabase()
Db.QueryTable(Db.TblDataModel)
-
+
identifier1 = DataClass.IdentifierClass(-1, '', '', "i''1", 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 32, 43, 54, 43)
identifier2 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 15, 43, 20, 43)
identifier3 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 55, 43, 58, 43)
@@ -333,12 +334,12 @@ if __name__ == '__main__':
file = DataClass.FileClass(-1, 'F1', 'c', 'C:\\', 'C:\\F1.exe', DataClass.MODEL_FILE_C, '2007-12-28', [fun1], [identifier1, identifier2, identifier3, identifier4], [])
Db.InsertOneFile(file)
Db.UpdateIdentifierBelongsToFunction()
-
+
Db.QueryTable(Db.TblFile)
Db.QueryTable(Db.TblFunction)
Db.QueryTable(Db.TblPcd)
Db.QueryTable(Db.TblIdentifier)
-
+
Db.Close()
EdkLogger.verbose("End at " + time.strftime('%H:%M:%S', time.localtime()))
-
+