3 Replies Latest reply on Jun 19, 2011 1:32 PM by nrako

    unquoting a blob

    goodwinsvml
      SQLite suggests the use of the QUOTE() function to turn a binary string into a hex string suitable for storage in SQLite. It appears to me the QUOTE() function prepends a variable-length string of hex pairs to the hex convertion of the binary string. It also appears to me the prepended string of hex pairs is a representation of the length of the string. When I convert the BLOB hex string back to a byteArray, I need to get rid of the prepended string. How do I know where the prepended string stops and the original binary starts?
        • 1. Re: unquoting a blob
          nrako

          2 years later, same problem and it's still very hard for me either to found some info on this exact same problem : http://stackoverflow.com/questions/6388456/what-is-the-first-3-bytes-in-a-blob-column-sqli te-adobe-air

           

          Did you finaly found a solution?

          • 2. Re: unquoting a blob
            goodwinsvml Level 1

            I did not find an answer to my question, but I did develop a kluge that works for my purposes:

             

            I look for specific things in the string to indicate the start of the document in the blob.

            1. I skip the first 4 characters.

            2. I look for a hex-pair that begins with a 0 through 8.  If I find such a pair, it is the last pair of the "prefix" and the document begins in the next hex-pair.

            3. I look for a string of "3C3F786D6C".  If I find that string, it is the start of the document.

             

            #2 seemed to work for most, but not all blobs.  The other blobs contained the string in #3.

             

            Good Luck!

            Steve

             

             

             

             

             

            • 3. Re: unquoting a blob
              nrako Level 1

              Hi Steve, thank you for response.

               

              Since my message I stubbornly continued to search and finaly found the solution.

               

              I am not sure if your problem is the same. But I found that the added bytes to the blob were due to some AMF 3 formatting. I think Adobe AIR Sqlite provider let you store any object as a binary into a blob and when you try to store a ByteArray there some formatting applied to allow AIR to be able to convert it back into a ByteArray. (Which is the purpose of AMF but is not very wise for cross-compatibility and should obviously be more detailed in the docs!)

               

              So the first byte will define the AMF TypeCode which is 12 for a ByteArray and then it will add a 29-bit integer for the byte-length followed by the raw bytes.

               

              My complete solution is explained in my answer with the sources : http://stackoverflow.com/questions/6388456/what-is-the-first-bytes-in-a-blob-column-sqlite -adobe-air-blob-sizeinfo

               

              BR

              Nico