-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 28/06/12 07:57, Nate Bargmann wrote:
> The SQLite column affinity is set to text but the suggested conversion
> techniques I have found through Web searches have still left me with
> the dreaded (<read-write buffer ptr 0xac66c70, size 5 at 0xac66c50>,)
> result.
You are getting a blob back, not text. Even if the affinity is set to
text, there is no way that SQLite can perform affinity to convert a
blob(bytes) to text. The reason is quite simple: it is impossible to
convert bytes to text without knowing the encoding. The C++ app is very
broken.
And even if you wanted the affinity to do the conversion as say UTF8 it is
still impossible for it to know that for example something really was text
versus say an image.
> Here is example output starting with the sqlite command line utility:
The SQLite shell has a *very* nasty bug. For any values that are blobs,
it just outputs the bytes as is. If they happen to be text then it looks
fine. Anyway there is a command line tool included in APSW and it does
colouring, completion and whole bunch of other stuff.
http://apidoc.apsw.googlecode.com/hg/shell.html
Here I'll show you the difference:
SQLite version 3.7.13 (APSW 3.7.13-r1)
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table foo(col1,col2);
sqlite> insert into foo values('AB', X'4142');
sqlite> select * from foo;
AB|<Binary data>
SQLite version 3.7.4
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table foo(col1,col2);
sqlite> insert into foo values('AB', X'4142');
sqlite> select * from foo;
AB|AB
If you use .dump on the tables you can see what is going on, or use typeof:
sqlite> select typeof(col1), col1, typeof(col2), col2 from foo;
text|AB|blob|AB
> It appears as though the data is encoded in such a way that Python
> still has no idea what to do with it.
Python knows exactly what to do with it. It was added to the database
using sqlite3_bind_blob - ie the QT application explicitly said the data
was a bucket of bytes and did not use sqlite3_bind_text. So APSW and
Python treat your bucket of bytes as a bucket of bytes. This is
absolutely the correct thing to do.
Read this if you disagree in any way:
http://www.joelonsoftware.com/articles/Unicode.html
The correct thing to do is fix the C++ app. The SQLite internals are
somewhat ambivalent about the differences between strings and blobs and
many of the string functions (eg lower and length) treat them the same,
but others won't (eg equality).
Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iEYEARECAAYFAk/skjwACgkQmOOfHg372QRy1ACg4UCx2ZEWppzrW1/8ohz7r4E+
XuEAnis7/EGtV1Pfm8Bs8lIg2p5IgFXe
=A+tY
-----END PGP SIGNATURE-----