neko and SQLite: How to insert filedata in a blob field?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

neko and SQLite: How to insert filedata in a blob field?

cambiata
Hmm... I want to store filedata (png images) in a SQlite blob field, like this:

var bytes = File.getBytes(filename); // png file
var rset = cnx.request('INSERT INTO pages (id, data) VALUES ("123", "' + bytes + '")');

This gives an exception - Error while executing INSERT INTO ...

How to properly do this? I haven't found a way to work with prameterized requests instead of manually concatenating the sql...

Jonas
Reply | Threaded
Open this post in threaded view
|

Re: neko and SQLite: How to insert filedata in a blob field?

Nicolas Cannasse
Le 11/11/2011 15:56, cambiata a écrit :

> Hmm... I want to store filedata (png images) in a SQlite blob field, like
> this:
>
> var bytes = File.getBytes(filename); // png file
> var rset = cnx.request('INSERT INTO pages (id, data) VALUES ("123", "' +
> bytes + '")');
>
> This gives an exception - Error while executing INSERT INTO ...
>
> How to properly do this? I haven't found a way to work with prameterized
> requests instead of manually concatenating the sql...

You need to quote to get a string from your bytes and quote it so
invalid chars get correctly escaped :

cnx.quote(neko.Lib.stringReference(bytes))

Best,
Nicolas


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: neko and SQLite: How to insert filedata in a blob field?

cambiata
Thank you, Nicolas!
Added to the Code sinppets page.

J