My favorites
▼
|
Sign in
pyodbc
Python ODBC library
Project Home
Downloads
Wiki
READ-ONLY: This project has been
archived
. For more information see
this post
.
Search
Search within:
All issues
Open issues
New issues
Issues to verify
for
Advanced search
Search tips
Subscriptions
Issue
320
attachment: pyodbc_test.py
(1.3 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
import pyodbc
DSN = """Driver={Firebird/InterBase(r) driver};
Uid=SYSDBA;Pwd=masterkey;
DbName=localhost/3050:D:\TESTING\PYODBC.FDB;
"""
conn = pyodbc.connect(DSN)
cursor = conn.cursor()
sql = """CREATE TABLE T1
(
ID INTEGER NOT NULL,
COL1 DECIMAL(9,5),
COL2 DECIMAL(9,4),
PRIMARY KEY(ID)
);
"""
cursor.execute(sql)
conn.commit()
sql = """INSERT INTO T1 (id, col1, col2) VALUES (?, ?, ?)"""
cursor.execute(sql, (1, 20000.0, 30000.0))
conn.commit()
sql = """SELECT col1, col2 FROM T1 where id=1"""
cursor.execute(sql)
row = cursor.fetchone()
for col in row:
print col,
print
# output is as expected:
# 20000.00000 30000.0000
sql = """INSERT INTO T1 (id, col1, col2) VALUES (?, ?, ?)"""
# the next line should raise the Exception:
# SQL Message : -802
# Arithmetic overflow or division by zero has occurred.
#cursor.execute(sql, (2, 21474.83647, 214748.3647) # max allowed values
cursor.execute(sql, (2, 30000.0, 30000.0))
# it doesn't, and row with id 2 now contains:
# (id = 2, col1 = -21474.83648, col2 = 30000.0000)
conn.commit()
sql = """SELECT col1, col2 FROM T1 where id=2"""
cursor.execute(sql)
# and now, the fetch operation fails with the Exception:
# InvalidOperation: Invalid literal for Decimal: u'-..-'
row = cursor.fetchone()
for col in row:
print col,
print
Powered by
Google Project Hosting