in reply to Re: How to store NUL characters into SQLite BLOB ?
in thread How to store NUL characters into SQLite BLOB ?
The solution is use sqlite3_bind_blob() to bind the variable. There is is currently code in dbdimp.c that appears to do this, but it never is called. I'm not sure if this is due to a bug or something not implemented at a higher level. I've come up with a a workaround patch, but I don't understand the internals well enough to know whether it is a good idea.
--- dbdimp.c.orig 2005-11-10 19:27:55.000000000 -0700
+++ dbdimp.c 2005-11-10 19:27:32.000000000 -0700
@@ -356,11 +356,17 @@
STRLEN len;
char * data = SvPV(value, len);
retval = sqlite3_bind_blob(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
- }
+ }
else {
STRLEN len;
char * data = SvPV(value, len);
- retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
+ if (memchr(data, 0, len)) {
+ sqlite_trace(4, "binding NUL containing data as a blob");
+ retval = sqlite3_bind_blob(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
+ }
+ else {
+ retval = sqlite3_bind_text(imp_sth->stmt, i+1, data, len, SQLITE_TRANSIENT);
+ }
}
|
|---|