Re: [Vala] Problems retrieving binary data from a sqlite3 database BLOB column



Hi, more information.

2011/6/26 Iñigo Serna <inigoserna gmail com>:
I have problems retrieving binary data from a sqlite3 DB.

One of the columns of the database (f.e., number 3) is a BLOB with png images.

Using FileUtils.set_data("test.png", (uint8[]) smtm.column_blob(3));
writes a 8-bytes file with the first bytes of the image ("PNG" header
and some other numbers)

I'm sure the query is ok as I also retrieve other fields in the same
query and even stmt.column_bytes(3) returns the correct size of the
image.

Documentation explains "smtm.column_blob()" returns a void * so I
guess I have to cast to uint8[] to use FileUtils.set_data.


What am I doing wrong?


I've tested vala v0.12.0 and 0.13.0, results are the same in both cases.


Compilation runs ok except for this warning:

/home/inigo/tmp/2/nodb.c: In function ‘my_app_get_items’:
/home/inigo/tmp/2/nodb.c:431:13: warning: assignment discards ‘const’
qualifier from pointer target type [enabled by default]

that correspond to:

void* _tmp8_ = NULL;
[...]
_tmp8_ = sqlite3_column_blob (stmt, 4);


if I include a line like:

uint8[]? data = (uint8[]) stmt.column_blob(3);

it's translated as next C code:

_tmp11_ = (_tmp10_ = (guint8*) _tmp9_, (_tmp10_ == NULL) ? ((gpointer)
_tmp10_) : _vala_array_dup3 (_tmp10_, -1));

and this crashes with the message:

Program received signal SIGSEGV, Segmentation fault.
0x0000003f58888fa6 in __memcpy_sse2 () from /lib64/libc.so.6


The complete backtrace is:

(gdb) bt
#0  0x0000003f58888fa6 in __memcpy_sse2 () from /lib64/libc.so.6
#1  0x0000003f5b85ff49 in g_memdup () from /lib64/libglib-2.0.so.0
#2  0x00000000004025e3 in _vala_array_dup3 (self=0x62a8f8
"\211PNG\r\n\032\n", length=-1) at /home/inigo/tmp/2/nodb.c:351
#3  0x0000000000402a4c in my_app_get_items (self=0x607040,
dbfile=0x404760 "./global.db") at /home/inigo/tmp/2/nodb.c:442
#4  0x000000000040351b in my_app_process (self=0x607040) at
/home/inigo/tmp/2/nodb.c:649
#5  0x000000000040423a in my_app_main (args=0x7fffffffe1e8,
args_length1=1) at /home/inigo/tmp/2/nodb.c:860
#6  0x000000000040428b in main (argc=1, argv=0x7fffffffe1e8) at
/home/inigo/tmp/2/nodb.c:869


If I edit C code for FileUtils.set_data("test.png", (uint8[])
smtm.column_blob(3)) and specify size as returned by
smtm.column_bytes(3) instead of -1, the file is created with the
correct image.


One last thing.
If I use a cross-compile to ARM the binary crash exiting with this message:

root qemuarm:/media/mmcblk0p1# ./nodb
GLib-ERROR **: gmem.c:136: failed to allocate 4294967295 bytes
aborting...
Aborted


Any idea?

Thanks,
Iñigo Serna



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]