forked from pyscripter/python4delphi
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathExample1.py
65 lines (54 loc) · 1.43 KB
/
Example1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import DBFireDac
# Create and open the table
T = DBFireDac.TFDTable(None)
T.ConnectionDefName = "SQLite_DB"
T.TableName = "Customer"
T.Active = True #or use T.Open()
# Display columns
print ("Columns: ", T.FieldNamesAsTuple())
LastInvoiceDate = T.FieldByName("LastInvoiceDate")
# For each record of the table
T.First()
while not T.EOF:
# Get all the fields in a list
A = []
for i in range( 0, T.FieldCount ):
A.append( T.Fields(i).Value )
# Print the current record number and the list
print ("Rec.", T.RecNo, ":", A)
# Edit record
T.Edit()
T.FieldByName("TaxRate").Value = 2.5
# Increments date by one day
D = LastInvoiceDate.Value
if D[2] < 28:
D2 = D[:2]+(D[2]+1,)+D[3:] # this is tuple arithmetic !
else:
D2 = D[:2]+(1,)+D[3:] # this is tuple arithmetic !
LastInvoiceDate.Value = D2
T.Post()
# Get next record
T.Next()
# Print some fields by their names
F = T.FieldByName("Company")
print (F, F.FieldName, "=", F.Value)
# Use the TFields and print the list of companies
T.First()
while not T.EOF:
print (F.AsString)
T.Next()
# Print the fields as a dictionary
D = T.FieldsAsDict()
print (D)
print ("COMPANY:", D["COMPANY"]) # <- case-sensitive
T.Close()
T.TableName = "Dummy"
try:
T.Open()
except DBFireDac.DBError:
print ("could not open table ", T.TableName)
#delete fields
del F
del LastInvoiceDate
# delete the table
del T