how to insert a file as a blob?

81 views
Skip to first unread message

mhe...@gmail.com

unread,
Feb 8, 2016, 10:36:49 AM2/8/16
to node-ibm_db
I'm using version 0.0.19 and I'm trying to insert the contents of file into a blob column.  I use fs.readFileSync to read the contents of the file into a buffer.  The file contains binary data, not text, so I don't pass an encoding to readFileSync and it returns a buffer object.

var stmt = conn.prepareSync('insert into mytab(x1, x2) VALUES (?, ?)');
var result = stmt.executeSync(['data', fs.readFileSync(__dirname + '/x.data')]);
result
.closeSync();

I catch this error object:

{
 
"errors": [],
 
"error": "[node-odbc] Error in ODBCStatement::ExecuteSync",
 
"message": "[IBM][CLI Driver] CLI0100E  Wrong number of parameters. SQLSTATE=07001",
 
"state": "07001"
}

I know that "Wrong number of parameters" can also mean "Wrong type of parameters", so I think executeSync doesn't support my use of a buffer for the blob's data.

What is the correct way to insert a blob from a file?

bimaljha

unread,
Feb 28, 2016, 12:44:17 PM2/28/16
to node-ibm_db, mhe...@gmail.com
Seems your second parameter is not a blob. Check the example here https://github.com/ibmdb/node-ibm_db/issues/85 and try to modify your program. Thanks.

mhe...@gmail.com

unread,
Mar 11, 2016, 3:16:40 AM3/11/16
to node-ibm_db, mhe...@gmail.com
I saw that example and tried blob(?) instead of ? in my values clause before I posted my question.  It doesn't work.
Reply all
Reply to author
Forward
0 new messages