Simple example for blob

15 views
Skip to first unread message

Rodolfo Ochoa

unread,
Apr 30, 2014, 5:06:04 PM4/30/14
to hel...@googlegroups.com
need a simple example for blob fields...
read/write...

Russell Bradberry

unread,
Apr 30, 2014, 5:15:00 PM4/30/14
to hel...@googlegroups.com
you can use either a binary string or a Buffer object to insert Blobs

Rodolfo Ochoa

unread,
Apr 30, 2014, 5:21:59 PM4/30/14
to hel...@googlegroups.com
I have this:
    fs.readFile('image.jpg', function read(err, data) {
   pool.cql(insert_query, ['Test User', 'Test User', '1234567890', data], function(err, results){
      console.log(err, results);
   });

data is already a buffer, but this throw
{ [HelenusInvalidRequestException: line 1:21725 no viable alternative at input ')'] name: 'HelenusInvalidRequestException' } undefined

what else is need?

Rodolfo Ochoa

unread,
Apr 30, 2014, 5:22:52 PM4/30/14
to hel...@googlegroups.com
previously 
create_query = " CREATE TABLE IF NOT EXISTS users ( name text, lastname text, phone text, picture blob, \
                     PRIMARY KEY (name) ) ";

and the insert query is:
    insert_query = "  INSERT INTO users (name, lastname, phone, picture) \
                      VALUES (?, ?, ?, ?); "

Russell Bradberry

unread,
Apr 30, 2014, 5:29:40 PM4/30/14
to hel...@googlegroups.com
what version of Hlenus are you using?

Rodolfo Ochoa

unread,
Apr 30, 2014, 5:30:01 PM4/30/14
to hel...@googlegroups.com
latest... fresh from npm...

Russell Bradberry

unread,
Apr 30, 2014, 5:32:58 PM4/30/14
to hel...@googlegroups.com
can you paste your CREATE TABLE schema here

Russell Bradberry

unread,
Apr 30, 2014, 5:33:24 PM4/30/14
to hel...@googlegroups.com
nevermind, i didnt notice that, ill check into this

Rodolfo Ochoa

unread,
Apr 30, 2014, 5:39:43 PM4/30/14
to hel...@googlegroups.com
should I use on the buffer:
data.toString('hex')

and on the query:
    insert_query = "  INSERT INTO users (name, lastname, phone, picture) \
                      VALUES (?, ?, ?, textAsBlob(?)); "

is this the way?

Russell Bradberry

unread,
Apr 30, 2014, 5:59:54 PM4/30/14
to hel...@googlegroups.com
it seems that now it expects the format of "0x..." for the blob data.  I'll have to change the driver to do this automagically but in the mean time you can use your original code just change the update statement to:

INSERT INTO users (name, lastname, phone, picture) VALUES (?, ?, ?, 0x?);

That should allow it to insert. 

Rodolfo Ochoa

unread,
Apr 30, 2014, 6:19:53 PM4/30/14
to hel...@googlegroups.com
thanks!!
Reply all
Reply to author
Forward
0 new messages