]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Table/TableFile.py
2 # This file is used to create/update/query/erase table for files
4 # Copyright (c) 2008 - 2014, 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
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.
17 import Common
.EdkLogger
as EdkLogger
18 from Table
import Table
19 from Common
.StringUtils
import ConvertToSqlString
20 import Common
.LongFilePathOs
as os
21 from CommonDataClass
.DataClass
import FileClass
25 # This class defined a table used for file
27 # @param object: Inherited from object class
29 class TableFile(Table
):
30 def __init__(self
, Cursor
):
31 Table
.__init
__(self
, Cursor
)
38 # @param ID: ID of a File
39 # @param Name: Name of a File
40 # @param ExtName: ExtName of a File
41 # @param Path: Path of a File
42 # @param FullPath: FullPath of a File
43 # @param Model: Model of a File
44 # @param TimeStamp: TimeStamp of a File
47 SqlCommand
= """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
48 Name VARCHAR NOT NULL,
51 FullPath VARCHAR NOT NULL,
52 Model INTEGER DEFAULT 0,
53 TimeStamp VARCHAR NOT NULL
55 Table
.Create(self
, SqlCommand
)
59 # Insert a record into table File
61 # @param ID: ID of a File
62 # @param Name: Name of a File
63 # @param ExtName: ExtName of a File
64 # @param Path: Path of a File
65 # @param FullPath: FullPath of a File
66 # @param Model: Model of a File
67 # @param TimeStamp: TimeStamp of a File
69 def Insert(self
, Name
, ExtName
, Path
, FullPath
, Model
, TimeStamp
):
71 (Name
, ExtName
, Path
, FullPath
) = ConvertToSqlString((Name
, ExtName
, Path
, FullPath
))
72 SqlCommand
= """insert into %s values(%s, '%s', '%s', '%s', '%s', %s, '%s')""" \
73 % (self
.Table
, self
.ID
, Name
, ExtName
, Path
, FullPath
, Model
, TimeStamp
)
74 Table
.Insert(self
, SqlCommand
)
79 # Insert one file to table
81 # @param FileFullPath: The full path of the file
82 # @param Model: The model of the file
84 # @retval FileID: The ID after record is inserted
86 def InsertFile(self
, FileFullPath
, Model
):
87 (Filepath
, Name
) = os
.path
.split(FileFullPath
)
88 (Root
, Ext
) = os
.path
.splitext(FileFullPath
)
89 TimeStamp
= os
.stat(FileFullPath
)[8]
90 File
= FileClass(-1, Name
, Ext
, Filepath
, FileFullPath
, Model
, '', [], [], [])
91 return self
.Insert(File
.Name
, File
.ExtName
, File
.Path
, File
.FullPath
, File
.Model
, TimeStamp
)
93 ## Get ID of a given file
95 # @param FilePath Path of file
97 # @retval ID ID value of given file in the table
99 def GetFileId(self
, File
):
100 QueryScript
= "select ID from %s where FullPath = '%s'" % (self
.Table
, str(File
))
101 RecordList
= self
.Exec(QueryScript
)
102 if len(RecordList
) == 0:
104 return RecordList
[0][0]