Reading BLOB

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Johan Vervoort

    Reading BLOB

    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
  • Peter Hansen

    #2
    Re: Reading BLOB

    Johan Vervoort wrote:[color=blue]
    >
    > 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'[/color]

    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

    Comment

    • Johan.Vervoort@utimaco.be

      #3
      Re: Reading BLOB

      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:[color=blue][color=green][color=darkred]
      >>> reload (Test)[/color][/color][/color]
      [('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.fet chone, None):
      # Dump certif to file
      FileName="C:\\C ERTS\\%s.crt" % row[0]
      CertFile = open(FileName, "wb")
      CertFile.write( row[1])
      CertFile.close( )

      print cursor.descript ion
      for tup in cursor.descript ion:
      print tup[0]

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

      ReadCmail()



      On Wed, 21 Jan 2004 09:20:32 -0500, Peter Hansen <peter@engcorp. com>
      wrote:
      [color=blue]
      >Johan Vervoort wrote:[color=green]
      >>
      >> 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'[/color]
      >
      >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[/color]

      Comment

      • Peter Hansen

        #4
        Re: Reading BLOB

        Johan.Vervoort@ utimaco.be wrote:[color=blue]
        >
        > 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...)[/color]

        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:
        [color=blue][color=green][color=darkred]
        >>> reload (Test)[/color][/color][/color]
        [('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

        Comment

        Working...