473,513 Members | 2,583 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

odbc and python

MM
Are there any other odbc packages other than the win32all and mxodbc
ones? The win32all odbc.pyd can't access table structure info like
SQLColumns, and mxobdc requires a commercial license which is
unjustifiable for this tiny project. Any other OS alternatives for
win32?. Thanks.
Jul 19 '05 #1
5 2613
MM wrote:
Are there any other odbc packages other than the win32all and mxodbc
ones? The win32all odbc.pyd can't access table structure info like
SQLColumns, and mxobdc requires a commercial license which is
unjustifiable for this tiny project.
Presumably you really mean 'are there any other Python DP API 2.0
compliant packages' ...

Try this:

http://www.python.org/pypi/adodbapi/2.0
Any other OS alternatives for
win32?


My parser failed on that one ... please rewrite and retry.
Jul 19 '05 #2
MM wrote:
Are there any other odbc packages other than the win32all and mxodbc
ones? The win32all odbc.pyd can't access table structure info like
SQLColumns, and mxobdc requires a commercial license which is
unjustifiable for this tiny project. Any other OS alternatives for
win32?. Thanks.


You could potentially make the ODBC calls using ctypes a la:

http://aspn.activestate.com/ASPN/Coo.../Recipe/303667

Not tried this myself and imagine it could be a bit tedious.

Cheers,
Giles

Jul 19 '05 #3
Giles Brown schrieb:
MM wrote:
Are there any other odbc packages other than the win32all and mxodbc
ones? The win32all odbc.pyd can't access table structure info like
SQLColumns, and mxobdc requires a commercial license which is
unjustifiable for this tiny project. Any other OS alternatives for
win32?. Thanks.

You could potentially make the ODBC calls using ctypes a la:

http://aspn.activestate.com/ASPN/Coo.../Recipe/303667

Not tried this myself and imagine it could be a bit tedious.

Cheers,
Giles

If someone wants to try this approach (personally, I don't use
databases), it seems that the tools provided with ctypes, if you have
gccxml (and MSVC) installed, should give a good start. Running

h2xml windows.h sql.h -o sql.xml -c
and
xml2py sql.xml -rSQL.* -o sql.py -lodbc32 -d

creates a 830 lines Python module, containing a lot of useful SQL stuff,
which can be hacked on. To give an impression, the file starts with the
following lines, so a lot of constants and datatypes are already defined:

# generated by 'xml2py'
# flags 'sql.xml -rSQL.* -o sql.py -lodbc32 -d -m ctypes.com'
from ctypes import *
SQL_DATETIME = 9 # Variable c_int
SQL_MAX_USER_NAME_LEN = 107 # Variable c_int
SQL_DEFAULT_TXN_ISOLATION = 26 # Variable c_int
SQL_API_SQLFREEHANDLE = 1006 # Variable c_int
SQL_ALTER_TABLE = 86 # Variable c_int
SQL_IS_DAY_TO_SECOND = 10
SQL_API_SQLCOLUMNS = 40 # Variable c_int
SQL_TXN_READ_UNCOMMITTED = 1 # Variable c_long
SQL_TRANSACTION_READ_UNCOMMITTED = SQL_TXN_READ_UNCOMMITTED # alias
SQL_DBMS_NAME = 17 # Variable c_int
SQLSMALLINT = c_short
SQLRETURN = SQLSMALLINT
SQLHANDLE = c_void_p
SQLHDBC = SQLHANDLE
SQLUSMALLINT = c_ushort

@ stdcall(SQLRETURN, 'odbc32',
[SQLHDBC, SQLUSMALLINT, POINTER(SQLUSMALLINT)])
def SQLGetFunctions(p1, p2, p3):
# C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/sql.h 735
return SQLGetFunctions._api_(p1, p2, p3)

SQL_TRUE = 1 # Variable c_int
SQLHSTMT = SQLHANDLE
SQLCHAR = c_ubyte
UDWORD = c_ulong

@ stdcall(SQLRETURN, 'odbc32',
[SQLHSTMT, SQLUSMALLINT, POINTER(SQLCHAR), SQLSMALLINT,
POINTER(SQLSMALLINT), POINTER(SQLSMALLINT),
POINTER(UDWORD),POINTER(SQLSMALLINT), POINTER(SQLSMALLINT)])
def SQLDescribeCol(p1, p2, p3, p4, p5, p6, p7, p8, p9):
# C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/sql.h 650
return SQLDescribeCol._api_(p1, p2, p3, p4, p5, p6, p7, p8, p9)

SQL_DROP = 1 # Variable c_int
SQL_DATA_SOURCE_NAME = 2 # Variable c_int
SQL_TXN_SERIALIZABLE = 8 # Variable c_long
SQL_TRANSACTION_SERIALIZABLE = SQL_TXN_SERIALIZABLE # alias

Thomas
Jul 19 '05 #4
MM wrote:
Are there any other odbc packages other than the win32all and mxodbc
ones? The win32all odbc.pyd can't access table structure info like
SQLColumns, and mxobdc requires a commercial license which is
unjustifiable for this tiny project. Any other OS alternatives for
win32?. Thanks.


The mxODBC package contains a lot of grunt work making access to
metadata work smoothly for many targets. I never found the license
too expensive for the work (and thought) that it saved me. If you
are targeting a single DBMS, or already have a strong understanding
of your DB's schema, some other solution may do you as well. I'd be
careful you don't spend far more effort getting corner cases to work
right with a cobbled-together system than you'll save by using mxODBC.

I am not connected to mxODBC other than as a very satisfied customer.

--Scott David Daniels
Sc***********@Acm.Org
Jul 19 '05 #5
Giles Brown wrote:
MM wrote:
Are there any other odbc packages other than the win32all and mxodbc
ones? The win32all odbc.pyd can't access table structure info like
SQLColumns, and mxobdc requires a commercial license which is
unjustifiable for this tiny project. Any other OS alternatives for
win32?. Thanks.

You could potentially make the ODBC calls using ctypes a la:

http://aspn.activestate.com/ASPN/Coo.../Recipe/303667

Not tried this myself and imagine it could be a bit tedious.

Cheers,
Giles


This is the new version that work very well into my projects:

http://unipex.it/vario/RealPyOdbc.py

This can work on all the platforms where ctypes work.
In the future I'll make it db-api 2.0 compliant.
If you have some question, email me directly.

Bye,
Michele
Jul 19 '05 #6

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

Similar topics

0
2228
by: Marco Aschwanden | last post by:
Hi - Win2000 - Python 2.3.3 - py2exe 0.5.0 - eGenix Comercial & Base Package I am developing an app using mxODBC. On the home page they say ...
7
1875
by: Chris | last post by:
Hello, I posted a while back about a newbie database question and got a lot of great help here. My script that I am creating has come a long way (For me!) and almost does what I need it too. I...
1
1637
by: Erwin S. Andreasen | last post by:
I have a Python application server that manages several different data sets, permits various reports to be run on them and the data to be downloaded as tab-delimetered files, all via a web...
3
1824
by: Joe | last post by:
Python 2.4 Windows XP SP2 MS Access 2000 mx.ODBC 2.0.7 Problem data truncation occuring (here's the actual error message): mxODBC.Warning: ('01004', 5, ' String data, right truncated on...
13
4923
by: Graham | last post by:
I need a SQL Server or ODBC package for Python. Can anyone help please? Have search the Python packages under Database and there is no reference to either SQL Server or ODBC. Thanks Graham
2
2792
by: Simon Faulkner | last post by:
Hi All, I am new to Cygwin and am hoping that someone here will be able to tell me how to get ODBC running in Python on Cygwin. Maximum gratefullness... Simon
10
3254
by: callmebill | last post by:
I'm getting my feet wet with making Python talk to MySQL via ODBC. I started on Windows, and it went smoothly enough due to the ODBC stuff that apparently is native to Python at least on windows...
5
1873
by: dananrg | last post by:
I was messing around with the native ODBC module (I am using Python in a Win32 environment), e.g: import dbi, odbc ....and it seems to meet my needs. I'd rather use a module that comes...
1
2478
by: zxo102 | last post by:
Hi everyone, I need your help for using python odbc module. I have a simple table defined as create table A ( userId char(10), courseid char(10), grade integer, primary key(userId,courseId)...
2
1842
by: Greg Corradini | last post by:
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a...
0
7260
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
7160
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7384
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
7525
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...
0
5685
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.