## @file
#
# Copyright (c) 2008 - 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
#
## TableReport
#
# This class defined a table used for data model
#
# @param object: Inherited from object class
#
#
## Create table
#
# Create table report
#
# @param ID: ID of an Error
# @param ErrorID: ID of an Error TypeModel of a Report item
# @param OtherMsg: Other error message besides the standard error message
# @param BelongsToItem: The error belongs to which item
# @param Enabled: If this error enabled
# @param Corrected: if this error corrected
#
SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
ErrorID INTEGER NOT NULL,
OtherMsg TEXT,
BelongsToTable TEXT NOT NULL,
BelongsToItem SINGLE NOT NULL,
Enabled INTEGER DEFAULT 0,
Corrected INTEGER DEFAULT -1
## Insert table
#
# Insert a record into table report
#
# @param ID: ID of an Error
# @param ErrorID: ID of an Error TypeModel of a report item
# @param OtherMsg: Other error message besides the standard error message
# @param BelongsToTable: The error item belongs to which table
# @param BelongsToItem: The error belongs to which item
# @param Enabled: If this error enabled
# @param Corrected: if this error corrected
#
def Insert(self, ErrorID, OtherMsg = '', BelongsToTable = '', BelongsToItem = -1, Enabled = 0, Corrected = -1):
SqlCommand = """insert into %s values(%s, %s, '%s', '%s', %s, %s, %s)""" \
% (self.Table, self.ID, ErrorID, ConvertToSqlString2(OtherMsg), BelongsToTable, BelongsToItem, Enabled, Corrected)
## Query table
#
# @retval: A recordSet of all found records
#
SqlCommand = """select ID, ErrorID, OtherMsg, BelongsToTable, BelongsToItem, Corrected from %s
## Convert to CSV
#
# Get all enabled records from table report and save them to a .csv file
#
# @param Filename: To filename to save the report content
#
try:
Index = 0
SqlCommand = ''
if BelongsToTable == 'File':
SqlCommand = """select 1, FullPath from %s where ID = %s
else:
SqlCommand = """select A.StartLine, B.FullPath from %s as A, File as B
where A.ID = %s and B.ID = A.BelongsToFile
if NewRecord != []:
File.write("""%s,%s,"%s",%s,%s,"%s"\n""" % (Index, ErrorID, EccToolError.gEccErrorMessage[ErrorID], NewRecord[0][1], NewRecord[0][0], OtherMsg))
EdkLogger.quiet("%s(%s): [%s]%s %s" % (NewRecord[0][1], NewRecord[0][0], ErrorID, EccToolError.gEccErrorMessage[ErrorID], OtherMsg))
except IOError:
EdkLogger.warn("ECC", "The report file %s is locked by other progress, use %s instead!" % (Filename, NewFilename))