def InitDatabase(self, NewDatabase=True): EdkLogger.verbose("\nInitialize ECC database started ...") # # Drop all old existing tables # if NewDatabase: if os.path.exists(self.DbPath): os.remove(self.DbPath) self.Conn = sqlite3.connect(self.DbPath, isolation_level='DEFERRED') self.Conn.execute("PRAGMA page_size=4096") self.Conn.execute("PRAGMA synchronous=OFF") # 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) self.TblIdentifier = TableIdentifier(self.Cur) self.TblPcd = TablePcd(self.Cur) self.TblReport = TableReport(self.Cur) self.TblInf = TableInf(self.Cur) self.TblDec = TableDec(self.Cur) self.TblDsc = TableDsc(self.Cur) self.TblFdf = TableFdf(self.Cur) # # Create new tables # if NewDatabase: self.TblDataModel.Create() self.TblFile.Create() self.TblFunction.Create() self.TblPcd.Create() self.TblReport.Create() self.TblInf.Create() self.TblDec.Create() self.TblDsc.Create() self.TblFdf.Create() # # Init each table's ID # self.TblDataModel.InitID() self.TblFile.InitID() self.TblFunction.InitID() self.TblPcd.InitID() self.TblReport.InitID() self.TblInf.InitID() self.TblDec.InitID() self.TblDsc.InitID() self.TblFdf.InitID() # # Initialize table DataModel # if NewDatabase: self.TblDataModel.InitTable() EdkLogger.verbose("Initialize ECC database ... DONE!")
def __init__(self, DbPath): if os.path.exists(DbPath): os.remove(DbPath) self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED') self.Conn.execute("PRAGMA page_size=8192") self.Conn.execute("PRAGMA synchronous=OFF") self.Cur = self.Conn.cursor() self.TblDataModel = TableDataModel(self.Cur) self.TblFile = TableFile(self.Cur) self.TblInf = TableInf(self.Cur) self.TblDec = TableDec(self.Cur) self.TblDsc = TableDsc(self.Cur)
class Database(object): def __init__(self, DbPath): if os.path.exists(DbPath): os.remove(DbPath) self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED') self.Conn.execute("PRAGMA page_size=8192") self.Conn.execute("PRAGMA synchronous=OFF") self.Cur = self.Conn.cursor() self.TblDataModel = TableDataModel(self.Cur) self.TblFile = TableFile(self.Cur) self.TblInf = TableInf(self.Cur) self.TblDec = TableDec(self.Cur) self.TblDsc = TableDsc(self.Cur) ## Initialize build database # # 1. Delete all old existing tables # 2. Create new tables # 3. Initialize table DataModel # def InitDatabase(self): EdkLogger.verbose("\nInitialize ECC database started ...") # # Drop all old existing tables # # self.TblDataModel.Drop() # self.TblDsc.Drop() # self.TblFile.Drop() # # Create new tables # self.TblDataModel.Create() self.TblFile.Create() self.TblInf.Create() self.TblDec.Create() self.TblDsc.Create() # # Initialize table DataModel # self.TblDataModel.InitTable() EdkLogger.verbose("Initialize ECC database ... DONE!") ## Query a table # # @param Table: The instance of the table to be queried # def QueryTable(self, Table): Table.Query() ## Close entire database # # Commit all first # Close the connection and cursor # def Close(self): self.Conn.commit() self.Cur.close() self.Conn.close()
class Database(object): ## The constructor # # @param self: The object pointer # @param DbPath: The file path of the database # def __init__(self, DbPath): self.DbPath = DbPath self.Conn = None self.Cur = None self.TblDataModel = None self.TblFile = None self.TblFunction = None self.TblIdentifier = None self.TblReport = None self.TblInf = None self.TblDec = None self.TblDsc = None self.TblFdf = None self.TblQuery = None self.TblQuery2 = None ## InitDatabase() method # 1. Delete all old existing tables # 2. Create new tables # 3. Initialize table DataModel # # @param self: The object pointer # @param NewDatabase: Check if it needs to create a new database # def InitDatabase(self, NewDatabase=True): EdkLogger.verbose("\nInitialize EOT database started ...") # # Drop all old existing tables # if NewDatabase: if os.path.exists(self.DbPath): os.remove(self.DbPath) self.Conn = sqlite3.connect(self.DbPath, isolation_level='DEFERRED') self.Conn.execute("PRAGMA page_size=8192") self.Conn.execute("PRAGMA synchronous=OFF") # 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) self.TblIdentifier = TableIdentifier(self.Cur) self.TblReport = TableEotReport(self.Cur) self.TblInf = TableInf(self.Cur) self.TblDec = TableDec(self.Cur) self.TblDsc = TableDsc(self.Cur) self.TblFdf = TableFdf(self.Cur) self.TblQuery = TableQuery(self.Cur) self.TblQuery2 = TableQuery(self.Cur) self.TblQuery2.Table = 'Query2' # Create new tables if NewDatabase: self.TblDataModel.Create() self.TblFile.Create() self.TblFunction.Create() self.TblReport.Create() self.TblInf.Create() self.TblDec.Create() self.TblDsc.Create() self.TblFdf.Create() self.TblQuery.Create() self.TblQuery2.Create() # Init each table's ID self.TblDataModel.InitID() self.TblFile.InitID() self.TblFunction.InitID() self.TblReport.InitID() self.TblInf.InitID() self.TblDec.InitID() self.TblDsc.InitID() self.TblFdf.InitID() self.TblQuery.Drop() self.TblQuery.Create() self.TblQuery.InitID() self.TblQuery2.Drop() self.TblQuery2.Create() self.TblQuery2.InitID() # Initialize table DataModel if NewDatabase: self.TblDataModel.InitTable() EdkLogger.verbose("Initialize EOT database ... DONE!") ## QueryTable() method # # Query a table # # @param self: The object pointer # @param Table: The instance of the table to be queried # def QueryTable(self, Table): Table.Query() ## Close() method # # Commit all first # Close the connection and cursor # def Close(self): # Commit to file self.Conn.commit() # Close connection and cursor self.Cur.close() self.Conn.close() ## InsertOneFile() method # # Insert one file's information to the database # 1. Create a record in TableFile # 2. Create functions one by one # 2.1 Create variables of function one by one # 2.2 Create pcds of function one by one # 3. Create variables one by one # 4. Create pcds one by one # # @param self: The object pointer # @param File: The object of the file to be inserted # def InsertOneFile(self, File): # 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) # 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 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) EdkLogger.verbose("Insert information from file %s ... DONE!" % File.FullPath) ## UpdateIdentifierBelongsToFunction() method # # Update the field "BelongsToFunction" for each Indentifier # # @param self: The object pointer # def UpdateIdentifierBelongsToFunction(self): EdkLogger.verbose( "Update 'BelongsToFunction' for Identifiers started ...") SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function""" Records = self.TblFunction.Exec(SqlCommand) Data1 = [] Data2 = [] for Record in Records: FunctionID = Record[0] BelongsToFile = Record[1] StartLine = Record[2] EndLine = Record[3] SqlCommand = """Update Identifier%s set BelongsToFunction = %s where BelongsToFile = %s and StartLine > %s and EndLine < %s""" % \ (BelongsToFile, FunctionID, BelongsToFile, StartLine, EndLine) self.TblIdentifier.Exec(SqlCommand) SqlCommand = """Update Identifier%s set BelongsToFunction = %s, Model = %s where BelongsToFile = %s and Model = %s and EndLine = %s""" % \ (BelongsToFile, FunctionID, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, BelongsToFile, DataClass.MODEL_IDENTIFIER_COMMENT, StartLine - 1) self.TblIdentifier.Exec(SqlCommand)
class Database(object): def __init__(self, DbPath): self.DbPath = DbPath self.Conn = None self.Cur = None self.TblDataModel = None self.TblFile = None self.TblFunction = None self.TblIdentifier = None self.TblPcd = None self.TblReport = None self.TblInf = None self.TblDec = None self.TblDsc = None self.TblFdf = None ## Initialize ECC database # # 1. Delete all old existing tables # 2. Create new tables # 3. Initialize table DataModel # def InitDatabase(self, NewDatabase=True): EdkLogger.verbose("\nInitialize ECC database started ...") # # Drop all old existing tables # if NewDatabase: if os.path.exists(self.DbPath): os.remove(self.DbPath) self.Conn = sqlite3.connect(self.DbPath, isolation_level='DEFERRED') self.Conn.execute("PRAGMA page_size=4096") self.Conn.execute("PRAGMA synchronous=OFF") # 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) self.TblIdentifier = TableIdentifier(self.Cur) self.TblPcd = TablePcd(self.Cur) self.TblReport = TableReport(self.Cur) self.TblInf = TableInf(self.Cur) self.TblDec = TableDec(self.Cur) self.TblDsc = TableDsc(self.Cur) self.TblFdf = TableFdf(self.Cur) # # Create new tables # if NewDatabase: self.TblDataModel.Create() self.TblFile.Create() self.TblFunction.Create() self.TblPcd.Create() self.TblReport.Create() self.TblInf.Create() self.TblDec.Create() self.TblDsc.Create() self.TblFdf.Create() # # Init each table's ID # self.TblDataModel.InitID() self.TblFile.InitID() self.TblFunction.InitID() self.TblPcd.InitID() self.TblReport.InitID() self.TblInf.InitID() 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 # # @param Table: The instance of the table to be queried # def QueryTable(self, Table): Table.Query() ## Close entire database # # Commit all first # Close the connection and cursor # 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 # 1. Create a record in TableFile # 2. Create functions one by one # 2.1 Create variables of function one by one # 2.2 Create pcds of function one by one # 3. Create variables one by one # 4. Create pcds one by one # def InsertOneFile(self, File): # # 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) # # 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 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) EdkLogger.verbose("Insert information from file %s ... DONE!" % File.FullPath) ## UpdateIdentifierBelongsToFunction # # Update the field "BelongsToFunction" for each Indentifier # # 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) Records = self.Cur.fetchall() for Record in Records: IdentifierID = Record[0] BelongsToFile = Record[1] StartLine = Record[2] EndLine = Record[3] Model = Record[4] # # Check whether an identifier belongs to a function # EdkLogger.debug(4, "For common identifiers ... ") SqlCommand = """select ID from Function where StartLine < %s and EndLine > %s and BelongsToFile = %s""" % (StartLine, EndLine, BelongsToFile) EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) IDs = self.Cur.fetchall() for ID in IDs: 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 ... ") if Model == DataClass.MODEL_IDENTIFIER_COMMENT: SqlCommand = """select ID from Function where StartLine = %s + 1 and BelongsToFile = %s""" % (EndLine, BelongsToFile) EdkLogger.debug(4, "SqlCommand: %s" % SqlCommand) self.Cur.execute(SqlCommand) IDs = self.Cur.fetchall() for ID in IDs: 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") ## UpdateIdentifierBelongsToFunction # # Update the field "BelongsToFunction" for each Indentifier # # def UpdateIdentifierBelongsToFunction(self): EdkLogger.verbose( "Update 'BelongsToFunction' for Identifiers started ...") SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function""" Records = self.TblFunction.Exec(SqlCommand) Data1 = [] Data2 = [] for Record in Records: FunctionID = Record[0] BelongsToFile = Record[1] StartLine = Record[2] EndLine = Record[3] #Data1.append(("'file%s'" % BelongsToFile, FunctionID, BelongsToFile, StartLine, EndLine)) #Data2.append(("'file%s'" % BelongsToFile, FunctionID, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, BelongsToFile, DataClass.MODEL_IDENTIFIER_COMMENT, StartLine - 1)) SqlCommand = """Update Identifier%s set BelongsToFunction = %s where BelongsToFile = %s and StartLine > %s and EndLine < %s""" % \ (BelongsToFile, FunctionID, BelongsToFile, StartLine, EndLine) self.TblIdentifier.Exec(SqlCommand) SqlCommand = """Update Identifier%s set BelongsToFunction = %s, Model = %s where BelongsToFile = %s and Model = %s and EndLine = %s""" % \ (BelongsToFile, FunctionID, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, BelongsToFile, DataClass.MODEL_IDENTIFIER_COMMENT, StartLine - 1) self.TblIdentifier.Exec(SqlCommand)