1## @file 2# This file is used to create/update/query/erase table for functions 3# 4# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR> 5# SPDX-License-Identifier: BSD-2-Clause-Patent 6# 7 8## 9# Import Modules 10# 11from __future__ import absolute_import 12import Common.EdkLogger as EdkLogger 13from Table.Table import Table 14from Common.StringUtils import ConvertToSqlString 15 16## TableFunction 17# 18# This class defined a table used for function 19# 20# @param Table: Inherited from Table class 21# 22class TableFunction(Table): 23 def __init__(self, Cursor): 24 Table.__init__(self, Cursor) 25 self.Table = 'Function' 26 27 ## Create table 28 # 29 # Create table Function 30 # 31 # @param ID: ID of a Function 32 # @param Header: Header of a Function 33 # @param Modifier: Modifier of a Function 34 # @param Name: Name of a Function 35 # @param ReturnStatement: ReturnStatement of a Function 36 # @param StartLine: StartLine of a Function 37 # @param StartColumn: StartColumn of a Function 38 # @param EndLine: EndLine of a Function 39 # @param EndColumn: EndColumn of a Function 40 # @param BodyStartLine: StartLine of a Function body 41 # @param BodyStartColumn: StartColumn of a Function body 42 # @param BelongsToFile: The Function belongs to which file 43 # @param FunNameStartLine: StartLine of a Function name 44 # @param FunNameStartColumn: StartColumn of a Function name 45 # 46 def Create(self): 47 SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY, 48 Header TEXT, 49 Modifier VARCHAR, 50 Name VARCHAR NOT NULL, 51 ReturnStatement VARCHAR, 52 StartLine INTEGER NOT NULL, 53 StartColumn INTEGER NOT NULL, 54 EndLine INTEGER NOT NULL, 55 EndColumn INTEGER NOT NULL, 56 BodyStartLine INTEGER NOT NULL, 57 BodyStartColumn INTEGER NOT NULL, 58 BelongsToFile SINGLE NOT NULL, 59 FunNameStartLine INTEGER NOT NULL, 60 FunNameStartColumn INTEGER NOT NULL 61 )""" % self.Table 62 Table.Create(self, SqlCommand) 63 64 ## Insert table 65 # 66 # Insert a record into table Function 67 # 68 # @param ID: ID of a Function 69 # @param Header: Header of a Function 70 # @param Modifier: Modifier of a Function 71 # @param Name: Name of a Function 72 # @param ReturnStatement: ReturnStatement of a Function 73 # @param StartLine: StartLine of a Function 74 # @param StartColumn: StartColumn of a Function 75 # @param EndLine: EndLine of a Function 76 # @param EndColumn: EndColumn of a Function 77 # @param BodyStartLine: StartLine of a Function body 78 # @param BodyStartColumn: StartColumn of a Function body 79 # @param BelongsToFile: The Function belongs to which file 80 # @param FunNameStartLine: StartLine of a Function name 81 # @param FunNameStartColumn: StartColumn of a Function name 82 # 83 def Insert(self, Header, Modifier, Name, ReturnStatement, StartLine, StartColumn, EndLine, EndColumn, BodyStartLine, BodyStartColumn, BelongsToFile, FunNameStartLine, FunNameStartColumn): 84 self.ID = self.ID + 1 85 (Header, Modifier, Name, ReturnStatement) = ConvertToSqlString((Header, Modifier, Name, ReturnStatement)) 86 SqlCommand = """insert into %s values(%s, '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s, %s, %s)""" \ 87 % (self.Table, self.ID, Header, Modifier, Name, ReturnStatement, StartLine, StartColumn, EndLine, EndColumn, BodyStartLine, BodyStartColumn, BelongsToFile, FunNameStartLine, FunNameStartColumn) 88 Table.Insert(self, SqlCommand) 89 90 return self.ID 91