## @file
# This file is used to create a database used by EOT tool
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
# which accompanies this distribution. The full text of the license may be found at
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
##
# Import Modules
#
import sqlite3
##
# Static definitions
#
## Database class
#
# This class defined the EOT databse
# During the phase of initialization, the database will create all tables and
# insert all records of table DataModel
#
## The constructor
#
# @param self: The object pointer
# @param DbPath: The file path of the database
#
self.TblDataModel = None
self.TblFunction = None
self.TblIdentifier = 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
#
#
# Drop all old existing tables
#
if NewDatabase:
# to avoid non-ascii charater conversion error
# Create new tables
if NewDatabase:
# Init each table's ID
# Initialize table DataModel
if NewDatabase:
## QueryTable() method
#
# Query a table
#
# @param self: The object pointer
# @param Table: The instance of the table to be queried
#
## Close() method
#
# Commit all first
# Close the connection and cursor
#
# Commit to file
# Close connection and cursor
## 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
#
# Insert a record for file
FileID = self.TblFile.Insert(File.Name, File.ExtName, File.Path, File.FullPath, Model = File.Model, TimeStamp = File.TimeStamp)
# Insert function of file
FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \
# Insert Identifier of function
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
IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
## UpdateIdentifierBelongsToFunction() method
#
# Update the field "BelongsToFunction" for each Indentifier
#
# @param self: The object pointer
#
SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function"""
Data1 = []
Data2 = []
SqlCommand = """Update Identifier%s set BelongsToFunction = %s where BelongsToFile = %s and StartLine > %s and EndLine < %s""" % \
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)
##
#
# This acts like the main() function for the script, unless it is 'import'ed into another
# script.
#
if __name__ == '__main__':
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)
identifier4 = DataClass.IdentifierClass(-1, '', '', "i1'", 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 77, 43, 88, 43)
file = DataClass.FileClass(-1, 'F1', 'c', 'C:\\', 'C:\\F1.exe', DataClass.MODEL_FILE_C, '2007-12-28', [fun1], [identifier1, identifier2, identifier3, identifier4], [])