My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 23 attachment: pyodbc-bus-error.py (1.5 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
"""
Create table for testing:

create table TestNullDecimals(
id integer primary key identity(1,1),
sample_dec decimal(18,3) null
);

insert into TestNullDecimals (sample_dec)
Values (NULL);
insert into TestNullDecimals (sample_dec)
VALUES (1.5);
insert into TestNullDecimals (sample_dec)
VALUES (0);
insert into TestNullDecimals (sample_dec)
VALUES (2);

This is what happens when I run the script below:

>>>
>>>
>>> import pyodbc
>>>
>>> def create_bus_error(connection):
... qry = u"SELECT id, sample_dec FROM TestNullDecimals;"
... cursor = connection.cursor()
... result = cursor.execute(qry)
... return result.fetchall()
...
>>> def avoid_bus_error(connection):
... qry = u"SELECT id FROM TestNullDecimals;"
... cursor = connection.cursor()
... result = cursor.execute(qry)
... return result.fetchall()
...
>>>
>>> conn = pyodbc.connect(initialization values here)
>>>
>>> avoid_bus_error(conn)
[(1, ), (2, ), (3, ), (4, )]
>>> create_bus_error(conn)
Bus error


"""

import pyodbc

def create_bus_error(connection):
qry = u"SELECT id, sample_dec FROM TestNullDecimals;"
cursor = connection.cursor()
result = cursor.execute(qry)
return result.fetchall()

def avoid_bus_error(connection):
qry = u"SELECT id FROM TestNullDecimals;"
cursor = connection.cursor()
result = cursor.execute(qry)
return result.fetchall()


conn = pyodbc.connect(initialization values here)

avoid_bus_error(conn)
create_bus_error(conn)
Powered by Google Project Hosting