I am using the C/C++ API for sqlite. I am using sqlite3_bind_blob() to insert data into the DB. The call typically looks like the following:
rv = sqlite3_bind_blob(pStmt, 3, pBuffer, bufLen, SQLITE_TRANSIENT); For my purposes, I prefer that these empty blobs be stored in the DB as "" (i.e. zero length data) rather than NULL. However, if pBuffer NULL and bufLen is 0, then the bind assigns the NULL value. I have found that if pBuffer is non-NULL and bufLen is zero that the DB will store the empty value we want. As a result, I've resorted to coding as follows: if (pBuffer != NULL) { rv = sqlite3_bind_blob(pStmt, 3, pBuffer, bufLen, SQLITE_TRANSIENT); } else { rv = sqlite3_bind_blob(pStmt, 3, (void*)1, 0, SQLITE_TRANSIENT); } I'm left feeling a little dirty after making that cast. Is there a more appropriate idiom others are using for this purpose? Is there any guarantee provided by the API that if the length is zero that it will not dereference the pointer? I decided to use (void*)1 instead of a valid pointer to inappropriate data (a pointer to another stack variable, for instance) specifically so that the program would choke and die quickly if the API tried to use the pointer. Any suggestions will be appreciated. Thanks, -John _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users