ceODBC on 64 bit Linux - fixing stack smashing
My original attempts to use ceODBC on 64 bit Linux were thwarted. I was able to install it okay by using pip, but when I went to actually execute a query, the module would fail claiming a “stack smash” error. This occured even with a simple select.
And then I went down the rabbit hole. I never really wanted to learn how to debug Python libraries, but now I know where to start. I’ll spare you the details though. If you have the same error let’s check a few things first.
I’m using unixODBC. You should check if yours was built for 64 or 32 bit data types. To do this run “odbcinst -j” if the SQLULEN and SQLLEN sizes report 4, then you have a 32 bit unixODBC install and this document won’t help you. If your unixODBC install reports 8 here, you have a 64 bit install and the issue is ceODBC.
If you built ceODBC using pip or even with setup.py the default install includes a flag in the build called BUILD_LEGACY_64_BIT_MODE if you are not on the windows 32-bit platform. This is the issue. unixODBC and your 64 bit odbc drivers are returning types longer than the variables that ceODBC was being built to handle... hence the stack smash.
How do I fix this? Download the ceODBC sources, untar the file (tar -xvzf ceODBC*), change to the base directory and find the setup.py file. In my version 2.01 the line we want is located at Line 160. It reads: “defineMacros.append(("BUILD_LEGACY_64_BIT_MODE", None))”
Comment this out by adding a # in front of it. Now run your install of ceODBC
In my case I wanted it for Python3.2 so my command was... “sudo python3.2 setup.py install”
ceODBC will be built and installed with 64 bit types. Now when you import ceODBC into your software, you’ll be able to execute a SQL statement that returns data without smashing your stack. *HULK SMASH!*








