Reading BLOB

Johan.Vervoort at utimaco.be Johan.Vervoort at utimaco.be
Wed Jan 21 17:18:07 CET 2004


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:
>>> reload (Test)
[('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()



On Wed, 21 Jan 2004 09:20:32 -0500, Peter Hansen <peter at engcorp.com>
wrote:

>Johan Vervoort wrote:
>> 
>> 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




More information about the Python-list mailing list