]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # This file is used to create/update/query/erase table for files\r | |
3 | #\r | |
f7496d71 | 4 | # Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r |
2e351cbe | 5 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
30fdf114 LG |
6 | #\r |
7 | \r | |
8 | ##\r | |
9 | # Import Modules\r | |
10 | #\r | |
1ccc4d89 | 11 | from __future__ import absolute_import\r |
30fdf114 | 12 | import Common.EdkLogger as EdkLogger\r |
855698fb | 13 | from Table.Table import Table\r |
5a57246e | 14 | from Common.StringUtils import ConvertToSqlString\r |
1be2ed90 | 15 | import Common.LongFilePathOs as os\r |
30fdf114 LG |
16 | from CommonDataClass.DataClass import FileClass\r |
17 | \r | |
18 | ## TableFile\r | |
19 | #\r | |
20 | # This class defined a table used for file\r | |
f7496d71 | 21 | #\r |
30fdf114 LG |
22 | # @param object: Inherited from object class\r |
23 | #\r | |
24 | class TableFile(Table):\r | |
25 | def __init__(self, Cursor):\r | |
26 | Table.__init__(self, Cursor)\r | |
27 | self.Table = 'File'\r | |
f7496d71 | 28 | \r |
30fdf114 LG |
29 | ## Create table\r |
30 | #\r | |
31 | # Create table File\r | |
32 | #\r | |
33 | # @param ID: ID of a File\r | |
34 | # @param Name: Name of a File\r | |
35 | # @param ExtName: ExtName of a File\r | |
36 | # @param Path: Path of a File\r | |
37 | # @param FullPath: FullPath of a File\r | |
38 | # @param Model: Model of a File\r | |
39 | # @param TimeStamp: TimeStamp of a File\r | |
40 | #\r | |
41 | def Create(self):\r | |
42 | SqlCommand = """create table IF NOT EXISTS %s (ID INTEGER PRIMARY KEY,\r | |
43 | Name VARCHAR NOT NULL,\r | |
44 | ExtName VARCHAR,\r | |
45 | Path VARCHAR,\r | |
46 | FullPath VARCHAR NOT NULL,\r | |
47 | Model INTEGER DEFAULT 0,\r | |
48 | TimeStamp VARCHAR NOT NULL\r | |
49 | )""" % self.Table\r | |
50 | Table.Create(self, SqlCommand)\r | |
51 | \r | |
52 | ## Insert table\r | |
53 | #\r | |
54 | # Insert a record into table File\r | |
55 | #\r | |
56 | # @param ID: ID of a File\r | |
57 | # @param Name: Name of a File\r | |
58 | # @param ExtName: ExtName of a File\r | |
59 | # @param Path: Path of a File\r | |
60 | # @param FullPath: FullPath of a File\r | |
61 | # @param Model: Model of a File\r | |
62 | # @param TimeStamp: TimeStamp of a File\r | |
63 | #\r | |
64 | def Insert(self, Name, ExtName, Path, FullPath, Model, TimeStamp):\r | |
65 | self.ID = self.ID + 1\r | |
66 | (Name, ExtName, Path, FullPath) = ConvertToSqlString((Name, ExtName, Path, FullPath))\r | |
67 | SqlCommand = """insert into %s values(%s, '%s', '%s', '%s', '%s', %s, '%s')""" \\r | |
68 | % (self.Table, self.ID, Name, ExtName, Path, FullPath, Model, TimeStamp)\r | |
69 | Table.Insert(self, SqlCommand)\r | |
f7496d71 | 70 | \r |
30fdf114 LG |
71 | return self.ID\r |
72 | ## InsertFile\r | |
73 | #\r | |
74 | # Insert one file to table\r | |
75 | #\r | |
76 | # @param FileFullPath: The full path of the file\r | |
f7496d71 LG |
77 | # @param Model: The model of the file\r |
78 | #\r | |
30fdf114 LG |
79 | # @retval FileID: The ID after record is inserted\r |
80 | #\r | |
81 | def InsertFile(self, FileFullPath, Model):\r | |
82 | (Filepath, Name) = os.path.split(FileFullPath)\r | |
83 | (Root, Ext) = os.path.splitext(FileFullPath)\r | |
84 | TimeStamp = os.stat(FileFullPath)[8]\r | |
85 | File = FileClass(-1, Name, Ext, Filepath, FileFullPath, Model, '', [], [], [])\r | |
86 | return self.Insert(File.Name, File.ExtName, File.Path, File.FullPath, File.Model, TimeStamp)\r | |
f7496d71 | 87 | \r |
d0acc87a LG |
88 | ## Get ID of a given file\r |
89 | #\r | |
90 | # @param FilePath Path of file\r | |
91 | #\r | |
92 | # @retval ID ID value of given file in the table\r | |
93 | #\r | |
94 | def GetFileId(self, File):\r | |
95 | QueryScript = "select ID from %s where FullPath = '%s'" % (self.Table, str(File))\r | |
96 | RecordList = self.Exec(QueryScript)\r | |
97 | if len(RecordList) == 0:\r | |
98 | return None\r | |
99 | return RecordList[0][0]\r |