Sorry if the title isn't accurate, I am not 100% sure it describes the situation correctly:
I am attempting to interface with the FreeTDS C-library using Python's ctypes module. I have some code running surprisingly well, but have run into one snag. I am not sure how to to translate the last parameter of the dbbind() call below into ctypes.
The C example I am following is:
/* these variable types are defined in the FreeTDS library */
DBINT customer_id;
DBCHAR company_name[255];
DBFLT8 avg_income;
/* <snip> */
/* Now bind the returned columns to the variables */
/* BYTE is defined in the FreeTDS library */
dbbind(dbconn, 1, INTBIND, 0, (BYTE *)&customer_id);
dbbind(dbconn, 2, NTBSTRINGBIND, 0, (BYTE *)&company_name);
dbbind(dbconn, 3, FLT8BIND, 0, (BYTE*)&avg_income);
So, A) how do I define my variables in Python as variable types from the library and B) how do I translate "(BYTE *)&company_name" etc. into ctypes calls?
Thank you!
Solution: thanks to Zuljin, I was able to work out the following:
import ctypes as ct
#<snip>
cid = ct.c_int()
cname = ct.create_string_buffer(256)
cavgincome = ct.c_float()
dtlib.dbbind(cdbconn, 1, INTBIND, 0, ct.byref(cid))
dtlib.dbbind(cdbconn, 2, NTBSTRINGBIND, 0, cname)
dtlib.dbbind(cdbconn, 3, REALBIND, 0, ct.byref(cavgincome))
while dtlib.dbnextrow(cdbconn) != NO_MORE_ROWS:
print '%s | %s | %s' % (cid, cname.value, cavgincome)