473,396 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

pyodbc.Error Crash

I believe this bug is also related to the other problem I just reported.

OS = Windows XP SP2
DB = Microsoft Access XP

PROBLEM:

When you use + (or &) to concatenation columns together and the columns are
of type text and the combined length exceed 255 this causes pyodbc to fail
and python to crash.

Basically

select c2 + ' ' + c3 from test_concat where c1 = 1

will cause the problem if c2 and c3 are text columns and their combined
length is 255.

I also encountered this problem years ago with mxODBC and I believe the
problem may actually be an underlying bug in odbc.

When I contacted Marc-André Lemburg,the author of mxODBC he patched it to
fix the problem and I believe the workaround was to allocate a larger
buffer.

If the columns that are concatenated are memo columns I also believe the
problem occurs.

# pyodbc.Error: ('HY090', '[HY090] [Microsoft][ODBC Driver Manager]
Invalid string
# or buffer length (0)')

To recreate the problem create an Access db named test and create a DSN
named test.

Run the createtable.py script to create the table and then run the broke.py
to demonstrate the problem.

The broke.py script has 4 select statements but only one is executed.
Change line number 34 to specify which one you want to test.

#
# createtable.py script
#

import pyodbc

dbs = pyodbc.connect('dsn=test')

c = dbs.cursor()

try:
sql = 'drop table test_concat'

c.execute(sql)

dbs.commit()
except:
# ignore drop table failure
pass

sql = 'create table test_concat (c1 int not null, c2 text not null, c3 text
not null)'

c.execute(sql)

dbs.commit()

sql = 'insert into test_concat values(1, ?, ?)'

c2_value = '1' * 251

c2_value = '%sJOE1' % (c2_value)

c3_value = '1' * 251

c3_value = '%sJOE2' % (c3_value)

c.execute(sql, (c2_value, c3_value))

dbs.commit()

c.close()
dbs.close()

#
# broke.py script
#
import pyodbc

dbs = pyodbc.connect('dsn=test')

c = dbs.cursor()
sql1 = "select c2 from test_concat where c1 = 1"
sql2 = "select c2, c3 from test_concat where c1 = 1"
sql3 = "select c2 + ' ' + c3 from test_concat where c1 = 1"
sql4 = "select c2 + ' ' + c3 as a from test_concat where c1 = 1"

#
# 1: Works fine
#
# 2: Works fine
#
# 3: Errors and python crashes
#
# Traceback (most recent call last):
# File "H:\1-pyodbc-bug\concat-bug\broke.py", line 36, in ?
# row = c.fetchone()
# pyodbc.Error: ('HY090', '[HY090] [Microsoft][ODBC Driver Manager]
Invalid string
# or buffer length (0)')
#
# 4: Errors and python crashes
#
# Traceback (most recent call last):
# File "H:\1-pyodbc-bug\concat-bug\broke.py", line 36, in ?
# row = c.fetchone()
# pyodbc.Error: ('HY090', '[HY090] [Microsoft][ODBC Driver Manager]
Invalid string
# or buffer length (0)')
#

c.execute(sql4)

row = c.fetchone()

print row[0]

if len(row) 1: print row[1]

c.close()
dbs.close()

May 18 '07 #1
2 5308
En Fri, 18 May 2007 20:48:49 -0300, Joe Salmeri <Jo********@hotmail.com>
escribió:
I believe this bug is also related to the other problem I just reported.
I think you'll get best results reporting them to the author(s) directly:
http://pyodbc.sourceforge.net/ and click on "Bug tracker"

--
Gabriel Genellina

May 19 '07 #2

Thanks, I reported them there first and then posted here in case they
monitor the forum more frequently and so others would be aware of the
problems found.

Joe
"Gabriel Genellina" <ga*******@yahoo.com.arwrote in message
news:ma***************************************@pyt hon.org...
En Fri, 18 May 2007 20:48:49 -0300, Joe Salmeri <Jo********@hotmail.com>
escribió:
>I believe this bug is also related to the other problem I just reported.

I think you'll get best results reporting them to the author(s) directly:
http://pyodbc.sourceforge.net/ and click on "Bug tracker"

--
Gabriel Genellina

May 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: timw.google | last post by:
I just downloaded the pyodbc source to try and install on my Linux FC3 box. I see that there is a setup.py file, but when I try to do a 'python setup.py build' (or just 'python setup.py') I get ...
1
by: king kikapu | last post by:
Hi to all, can anyone give me a jump-start about how to call Stored Procedures from PyODBC ?? I want to execute a very simple testing Stored Procedure on an Sql Server database. I started...
0
by: timw.google | last post by:
How do I get a list of datasources with pyodbc? I know that with mx.ODBC.Windows I can use the DataSources method to get a dictionay containing the datasources. Is there a similar way to do this...
3
by: Joe Salmeri | last post by:
I have found a data corruption problem with pyodbc. OS = Windows XP SP2 DB = Microsoft Access XP PROBLEM: When selecting columns from a table that are of type Memo the value returned is...
3
by: Rajendran | last post by:
Hi all, I've installed pyodbc module to access my database (MS Access). I've setup a User level DSN to the database.mdb file. When I run my python code in the command prompt it is retrieving the...
2
by: Sean Davis | last post by:
I have read a couple of blogs suggesting that pyodbc is buildable under linux. I am running suse 10.2 on a 64-bit intel machine with unixODBC installed. Upon building, I get a slew of pretty...
0
bartonc
by: bartonc | last post by:
This is a work in progress (current and active). There are some issues to resolve in supporting multiple connection types and I plan to add PySQLite to the mix. The this update is due to my...
0
by: john.goodleaf | last post by:
I've just built pyodbc 2.0.58 against freetds and unixodbc. When I attempt to invoke it, either from the test script or from the interpreter, I get: ImportError:...
0
by: dj | last post by:
Hello, I have just started working with minimock in doctest. I want to create a mock pyodbc object which returns a string value when the method execute is called. Here is my doctest: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.