Package: libsqlite3-dev Version: 3.2.7-1 Severity: normal I have various calls to sqlite3_prepare() in my program. All of them are working fine except one that calls it with the query "DROP TABLE test1". This query works fine from /usr/bin/sqlite3.
The output I'm seeing is: user error (SQL error: SqlError {seState = "", seNativeError = 1, seErrorMsg = "prepare 16: DROP TABLE test1: unrecognized token: \"\b\""}) That is, the error message is "unrecognized token", and the token it seems to be thinking it's seeing is \b, or Ctrl-H, the backspace character. That is definately NOT in the query string. (Occasionally it thinks it's seeing other characters.) I wrote a little debug wrapper to help track this down: int sqlite3_prepare_dbg(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail) { int retval; printf("\nGot nBytes: %d, zSql at %p\n", nBytes, zSql); printStr(zSql, nBytes); retval = sqlite3_prepare(db, zSql, nBytes, ppStmt, pzTail); printf("\nCall returned %d\n", retval); //printf("\npzTail points at %p", *pzTail); return retval; } void printStr(const char *istr, int nBytes) { int counter; for (counter = 0; counter < nBytes; counter++) { printf("Byte %d is %d: '%c'\n", counter, (int) istr[counter], (int) istr[counter]); } } When run with this wrapper, a successful query looks like: Got nBytes: 5, zSql at 0x403be708 Byte 0 is 66: 'B' Byte 1 is 69: 'E' Byte 2 is 71: 'G' Byte 3 is 73: 'I' Byte 4 is 78: 'N' Call returned 0 But this query looks like: Got nBytes: 16, zSql at 0x403be728 Byte 0 is 68: 'D' Byte 1 is 82: 'R' Byte 2 is 79: 'O' Byte 3 is 80: 'P' Byte 4 is 32: ' ' Byte 5 is 84: 'T' Byte 6 is 65: 'A' Byte 7 is 66: 'B' Byte 8 is 76: 'L' Byte 9 is 69: 'E' Byte 10 is 32: ' ' Byte 11 is 116: 't' Byte 12 is 101: 'e' Byte 13 is 115: 's' Byte 14 is 116: 't' Byte 15 is 49: '1' Call returned 1 That error code 1 is SQLITE_ERROR (SQL error or missing database). Now, when I change my wrapper function to: int sqlite3_prepare_dbg(sqlite3 *db, const char *zSql, int nBytes, sqlite3_stmt **ppStmt, const char **pzTail) { int retval; char *newstr = strndup(zSql, nBytes); printf("\nGot nBytes: %d, zSql at %p\n", nBytes, zSql); printStr(zSql, nBytes); retval = sqlite3_prepare(db, newstr, nBytes, ppStmt, pzTail); printf("\nCall returned %d\n", retval); //printf("\npzTail points at %p", *pzTail); return retval; } Everything works fine. That is, when a \0 is added to the end of the string via the call to strndup(), sqlite3 processes it correctly. According to /usr/share/doc/sqlite3-doc/capi3ref.html: The second argument "zSql" is the statement to be compiled, encoded as either UTF-8 or UTF-16 (see above). If the next argument, "nBytes", is less than zero, then zSql is read up to the first nul terminator. If "nBytes" is not less than zero, then it is the length of the string zSql in bytes (not characters). As you have seen, nBytes is not less than zero. It appears that sqlite3 is ignoring nBytes altogether in prepare(), at least for this query. I have no explanation why this is not always the case. -- System Information: Debian Release: testing/unstable APT prefers unstable APT policy: (500, 'unstable'), (500, 'stable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.13-rc3-mm1 Locale: LANG=C, LC_CTYPE=en_US (charmap=ISO-8859-1) Versions of packages libsqlite3-dev depends on: ii libc6-dev 2.3.5-8.1 GNU C Library: Development Librari ii libsqlite3-0 3.2.7-1 SQLite 3 shared library libsqlite3-dev recommends no packages. -- no debconf information -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]