]>
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 - 2018, 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 from __future__
import absolute_import
18 import Common
.EdkLogger
as EdkLogger
19 from Table
.Table
import Table
20 from Common
.StringUtils
import ConvertToSqlString
21 import Common
.LongFilePathOs
as os
22 from CommonDataClass
.DataClass
import FileClass
26 # This class defined a table used for file
28 # @param object: Inherited from object class
30 class TableFile(Table
):
31 def __init__(self
, Cursor
):
32 Table
.__init
__(self
, Cursor
)
39 # @param ID: ID of a File
40 # @param Name: Name of a File
41 # @param ExtName: ExtName of a File
42 # @param Path: Path of a File
43 # @param FullPath: FullPath of a File
44 # @param Model: Model of a File
45 # @param TimeStamp: TimeStamp of a File
48 SqlCommand
= """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
49 Name VARCHAR NOT NULL,
52 FullPath VARCHAR NOT NULL,
53 Model INTEGER DEFAULT 0,
54 TimeStamp VARCHAR NOT NULL
56 Table
.Create(self
, SqlCommand
)
60 # Insert a record into table File
62 # @param ID: ID of a File
63 # @param Name: Name of a File
64 # @param ExtName: ExtName of a File
65 # @param Path: Path of a File
66 # @param FullPath: FullPath of a File
67 # @param Model: Model of a File
68 # @param TimeStamp: TimeStamp of a File
70 def Insert(self
, Name
, ExtName
, Path
, FullPath
, Model
, TimeStamp
):
72 (Name
, ExtName
, Path
, FullPath
) = ConvertToSqlString((Name
, ExtName
, Path
, FullPath
))
73 SqlCommand
= """insert into %s values(%s, '%s', '%s', '%s', '%s', %s, '%s')""" \
74 % (self
.Table
, self
.ID
, Name
, ExtName
, Path
, FullPath
, Model
, TimeStamp
)
75 Table
.Insert(self
, SqlCommand
)
80 # Insert one file to table
82 # @param FileFullPath: The full path of the file
83 # @param Model: The model of the file
85 # @retval FileID: The ID after record is inserted
87 def InsertFile(self
, FileFullPath
, Model
):
88 (Filepath
, Name
) = os
.path
.split(FileFullPath
)
89 (Root
, Ext
) = os
.path
.splitext(FileFullPath
)
90 TimeStamp
= os
.stat(FileFullPath
)[8]
91 File
= FileClass(-1, Name
, Ext
, Filepath
, FileFullPath
, Model
, '', [], [], [])
92 return self
.Insert(File
.Name
, File
.ExtName
, File
.Path
, File
.FullPath
, File
.Model
, TimeStamp
)
94 ## Get ID of a given file
96 # @param FilePath Path of file
98 # @retval ID ID value of given file in the table
100 def GetFileId(self
, File
):
101 QueryScript
= "select ID from %s where FullPath = '%s'" % (self
.Table
, str(File
))
102 RecordList
= self
.Exec(QueryScript
)
103 if len(RecordList
) == 0:
105 return RecordList
[0][0]