Reading BLOB

J

Johan Vervoort

How can I read a binary value from a blob via ODBC (Microsoft VFP
driver-win32all)? The value seems to be truncated at the first '\0'

TIA
 
P

Peter Hansen

Johan said:
How can I read a binary value from a blob via ODBC (Microsoft VFP
driver-win32all)? The value seems to be truncated at the first '\0'

Maybe posting a very small snippet of code which reproduces the
problem would help get you responses. I can't help, as I don't
know what VFP driver-win32all is, but if there was example code I
might be able to see the problem anyway, and others more expert in
this area would likely see the problem right away.

-Peter
 
J

Johan.Vervoort

This is the sample code: It should dump all the certificates to the
certs directory...
What I suspect is that python thinks that the certif field is a STRING
and it's truncated when the first '\0' occurs...
(The data is stored completely in the database as an equivalent
C-program works fine...)

Sample output:[('csernum', 'STRING', 80, 80, 0, 0, 0), ('certif', 'STRING', 0,
2147483647, 0, 0, 0)]
csernum
certif


import dbi, odbc

def ReadCmail():
result = { 'Result' : 'OK' }

# Microsoft Visual FoxPro ODBC DNS
# Database type: Free table directory
dbc = odbc.odbc('CEC')
cursor = dbc.cursor()
query = "SELECT CSERNUM,CERTIF FROM C_MAIL"
cursor.execute(query)

row = cursor.fetchone()
for row in iter(cursor.fetchone, None):
# Dump certif to file
FileName="C:\\CERTS\\%s.crt" % row[0]
CertFile = open(FileName, "wb")
CertFile.write(row[1])
CertFile.close()

print cursor.description
for tup in cursor.description:
print tup[0]

cursor.close()
dbc.close()
return result

ReadCmail()
 
P

Peter Hansen

This is the sample code: It should dump all the certificates to the
certs directory...
What I suspect is that python thinks that the certif field is a STRING
and it's truncated when the first '\0' occurs...
(The data is stored completely in the database as an equivalent
C-program works fine...)

Python itself does not care about '\0' in a string, and will happily
handle strings with any kind of binary data.

At the least, then you need to look lower, perhaps at the ODBC wrapper
code itself, perhaps at the database schema or something. Are there
multiple types of string that can be stored in the database, and you've
picked one that is effectively null-terminated? Or, wait a minute, your
subject line is "reading BLOB", yet you are dealing with strings in
some way, given this:
[('csernum', 'STRING', 80, 80, 0, 0, 0), ('certif', 'STRING', 0,
2147483647, 0, 0, 0)]

Surely that is the cause of the problem, at least indirectly? Isn't
there some kind of BLOB data type instead?

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,283
Messages
2,571,407
Members
48,101
Latest member
LinetteDeg

Latest Threads

Top