]>
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 # SPDX-License-Identifier: BSD-2-Clause-Patent
11 from __future__
import absolute_import
12 import Common
.EdkLogger
as EdkLogger
13 from Table
.Table
import Table
14 from Common
.StringUtils
import ConvertToSqlString
15 import Common
.LongFilePathOs
as os
16 from CommonDataClass
.DataClass
import FileClass
20 # This class defined a table used for file
22 # @param object: Inherited from object class
24 class TableFile(Table
):
25 def __init__(self
, Cursor
):
26 Table
.__init
__(self
, Cursor
)
33 # @param ID: ID of a File
34 # @param Name: Name of a File
35 # @param ExtName: ExtName of a File
36 # @param Path: Path of a File
37 # @param FullPath: FullPath of a File
38 # @param Model: Model of a File
39 # @param TimeStamp: TimeStamp of a File
42 SqlCommand
= """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,
43 Name VARCHAR NOT NULL,
46 FullPath VARCHAR NOT NULL,
47 Model INTEGER DEFAULT 0,
48 TimeStamp VARCHAR NOT NULL
50 Table
.Create(self
, SqlCommand
)
54 # Insert a record into table File
56 # @param ID: ID of a File
57 # @param Name: Name of a File
58 # @param ExtName: ExtName of a File
59 # @param Path: Path of a File
60 # @param FullPath: FullPath of a File
61 # @param Model: Model of a File
62 # @param TimeStamp: TimeStamp of a File
64 def Insert(self
, Name
, ExtName
, Path
, FullPath
, Model
, TimeStamp
):
66 (Name
, ExtName
, Path
, FullPath
) = ConvertToSqlString((Name
, ExtName
, Path
, FullPath
))
67 SqlCommand
= """insert into %s values(%s, '%s', '%s', '%s', '%s', %s, '%s')""" \
68 % (self
.Table
, self
.ID
, Name
, ExtName
, Path
, FullPath
, Model
, TimeStamp
)
69 Table
.Insert(self
, SqlCommand
)
74 # Insert one file to table
76 # @param FileFullPath: The full path of the file
77 # @param Model: The model of the file
79 # @retval FileID: The ID after record is inserted
81 def InsertFile(self
, FileFullPath
, Model
):
82 (Filepath
, Name
) = os
.path
.split(FileFullPath
)
83 (Root
, Ext
) = os
.path
.splitext(FileFullPath
)
84 TimeStamp
= os
.stat(FileFullPath
)[8]
85 File
= FileClass(-1, Name
, Ext
, Filepath
, FileFullPath
, Model
, '', [], [], [])
86 return self
.Insert(File
.Name
, File
.ExtName
, File
.Path
, File
.FullPath
, File
.Model
, TimeStamp
)
88 ## Get ID of a given file
90 # @param FilePath Path of file
92 # @retval ID ID value of given file in the table
94 def GetFileId(self
, File
):
95 QueryScript
= "select ID from %s where FullPath = '%s'" % (self
.Table
, str(File
))
96 RecordList
= self
.Exec(QueryScript
)
97 if len(RecordList
) == 0:
99 return RecordList
[0][0]