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



On Sun, Jun 26, 2011 at 13:18, Iñigo Serna <inigoserna gmail com> wrote:

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));


I had this problem a lot of times before I realized that Vala arrays must
have a length, but this length is not always retrieved by the API, so Vala
has no idea of the size of the array returned from Sqlite. The -1 ilustrated
at the C code shows this, because Vala thinks this array has -1 items.
You can use stmt.column_bytes to retrieve the number of items in the array
(at this case, the number of bytes) and assign it to the array length such
as:

data.length = stmt.column_bytes(3);

So now Vala knows the size of the array and you can use it anyway you want
to.

*Alexandre Rosenfeld*


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