Repository navigation
Expand file tree
/
Copy pathREADME.txt
More file actions
executable file
·77 lines (52 loc) · 2.09 KB
/
Copy pathREADME.txt
File metadata and controls
executable file
·77 lines (52 loc) · 2.09 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
A Pure Python DB-API 2.0 compliant interface to ThinkSQL
Copyright © 2000-2012 Greg Gaughan
http://www.thinksql.co.uk
========================================================
Installation
------------
Unpack the file to a temporary directory and run:
python setup.py install
Usage
-----
Import the module into a Python program and create connections and cursors e.g.
import ThinkSQL
test=ThinkSQL.connect(host='localhost', user='RESTAURANT')
results1=test.cursor()
results1.execute("SELECT * FROM MENU_ITEM_GROUP")
print [col[0] for col in results1.description] #display the column headers
for row in results1:
print row
results1.close()
test.close()
Notes
-----
cursor.fetchmany(size) with a size>1 is much more efficient than repeated
calls to fetchone() because the server returns multiple result rows at once.
cursor.executemany() with a sequence of parameter lists is much more
efficient than repeated calls to execute() because the SQL statement is
automatically prepared once (parsed, security checked, optimised etc.) and
then subsequent executions just involve parameter passing.
Use ThinkSQL.Binary(bdata) to pass bdata as a BLOB parameter, e.g.
...
bdata=open('image.jpg','rb').read()
s1.execute("INSERT INTO picture_table (image) VALUES (?)", (ThinkSQL.Binary(bdata),))
You can use the standard type objects to check the column type, e.g.
if results1.description[0][1]==ThinkSQL.NUMBER:
#column 0 is numeric...
Ensure the fixedpoint module <http://fixedpoint.sourceforge.net/> is installed
for accurate NUMERIC/DECIMAL results.
History
-------
01.03.01
Increased default timeout to 30 seconds
01.03.00
Initial release included with ThinkSQL server
01.02.03:
Return numeric/decimals as FixedPoint if the module is available.
Return date/time/timestamps as datetime.date/time/datetimes
01.02.02:
Fix bug with column count
01.02.01:
Fix blob buffer read/write
01.02.00
Initial release