1## @file
2# This file is used to create/update/query/erase table for functions
3#
4# Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
5# This program and the accompanying materials
6# are licensed and made available under the terms and conditions of the BSD License
7# which accompanies this distribution.  The full text of the license may be found at
8# http://opensource.org/licenses/bsd-license.php
9#
10# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12#
13
14##
15# Import Modules
16#
17import Common.EdkLogger as EdkLogger
18from Table import Table
19from Common.String import ConvertToSqlString
20
21## TableFunction
22#
23# This class defined a table used for function
24#
25# @param Table:       Inherited from Table class
26#
27class TableFunction(Table):
28    def __init__(self, Cursor):
29        Table.__init__(self, Cursor)
30        self.Table = 'Function'
31
32    ## Create table
33    #
34    # Create table Function
35    #
36    # @param ID:                  ID of a Function
37    # @param Header:              Header of a Function
38    # @param Modifier:            Modifier of a Function
39    # @param Name:                Name of a Function
40    # @param ReturnStatement:     ReturnStatement of a Funciont
41    # @param StartLine:           StartLine of a Function
42    # @param StartColumn:         StartColumn of a Function
43    # @param EndLine:             EndLine of a Function
44    # @param EndColumn:           EndColumn of a Function
45    # @param BodyStartLine:       StartLine of a Function body
46    # @param BodyStartColumn:     StartColumn of a Function body
47    # @param BelongsToFile:       The Function belongs to which file
48    # @param FunNameStartLine:    StartLine of a Function name
49    # @param FunNameStartColumn:  StartColumn of a Function name
50    #
51    def Create(self):
52        SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
53                                                       Header TEXT,
54                                                       Modifier VARCHAR,
55                                                       Name VARCHAR NOT NULL,
56                                                       ReturnStatement VARCHAR,
57                                                       StartLine INTEGER NOT NULL,
58                                                       StartColumn INTEGER NOT NULL,
59                                                       EndLine INTEGER NOT NULL,
60                                                       EndColumn INTEGER NOT NULL,
61                                                       BodyStartLine INTEGER NOT NULL,
62                                                       BodyStartColumn INTEGER NOT NULL,
63                                                       BelongsToFile SINGLE NOT NULL,
64                                                       FunNameStartLine INTEGER NOT NULL,
65                                                       FunNameStartColumn INTEGER NOT NULL
66                                                      )""" % self.Table
67        Table.Create(self, SqlCommand)
68
69    ## Insert table
70    #
71    # Insert a record into table Function
72    #
73    # @param ID:                  ID of a Function
74    # @param Header:              Header of a Function
75    # @param Modifier:            Modifier of a Function
76    # @param Name:                Name of a Function
77    # @param ReturnStatement:     ReturnStatement of a Funciont
78    # @param StartLine:           StartLine of a Function
79    # @param StartColumn:         StartColumn of a Function
80    # @param EndLine:             EndLine of a Function
81    # @param EndColumn:           EndColumn of a Function
82    # @param BodyStartLine:       StartLine of a Function body
83    # @param BodyStartColumn:     StartColumn of a Function body
84    # @param BelongsToFile:       The Function belongs to which file
85    # @param FunNameStartLine:    StartLine of a Function name
86    # @param FunNameStartColumn:  StartColumn of a Function name
87    #
88    def Insert(self, Header, Modifier, Name, ReturnStatement, StartLine, StartColumn, EndLine, EndColumn, BodyStartLine, BodyStartColumn, BelongsToFile, FunNameStartLine, FunNameStartColumn):
89        self.ID = self.ID + 1
90        (Header, Modifier, Name, ReturnStatement) = ConvertToSqlString((Header, Modifier, Name, ReturnStatement))
91        SqlCommand = """insert into %s values(%s, '%s', '%s', '%s', '%s', %s, %s, %s, %s, %s, %s, %s, %s, %s)""" \
92                                    % (self.Table, self.ID, Header, Modifier, Name, ReturnStatement, StartLine, StartColumn, EndLine, EndColumn, BodyStartLine, BodyStartColumn, BelongsToFile, FunNameStartLine, FunNameStartColumn)
93        Table.Insert(self, SqlCommand)
94
95        return self.ID
96