Hello, I have a vtable implementation that wraps a storage layer of my own using Sqlite 3.5.6 (which is excellent--kudos!).
If the user does an SQL INSERT statement but provides the wrong type (according to my storage manager) for one of the values, I'd like to report a descriptive error message. For example, if the user has a table "foo", with one column, "bar", of type integer, and says: sqlite> INSERT INTO foo VALUES ("Hello, world!"); I'd like sqlite to say: Error: datatype mismatch: column "bar" of table "foo" is of type INTEGER. Currently, my code looks something like this: static int vt_update(sqlite3_vtab *pVTab, int argc, sqlite3_value **argv, sqlite3_int64 *pRowid) { ... for (int i = 2; i < argc; ++i) { if (sqlite3_value_type(argv[i]) != my_table_types[i]) { if (vtab->zErrMsg) sqlite3_free(vtab->zErrMsg); vtab->zErrMsg = sqlite3_mprintf("column %s of table %s is of type %s", ...); return SQLITE_MISMATCH; } ... } } When I try the example above, I get: sqlite> INSERT INTO foo VALUES ("Hello, world!"); SQL error: datatype mismatch The documentation at http://www.sqlite.org/cvstrac/wiki?p=VirtualTables says: "The virtual table implementation can pass error message text to the core by putting an error message string obtained from sqlite3_mprintf() in zErrMsg. Prior to assigning a new value to zErrMsg, the virtual table implementation should free any prior content of zErrMsg using sqlite3_free(). Failure to do this might result in a memory leak. The SQLite core will free and zero the content of zErrMsg when it delivers the error message text to the client application or when it destroys the virtual table." That leads me to believe I should see my message ('column "bar" of table "foo" is of type INTEGER') echoed to the user. Is that not the case? Am I missing something obvious? Thanks in advance for your help, Sean -- "We're borrowing money from China to buy oil from the Persian Gulf to burn it in ways that destroy the planet. Every bit of that's got to change." -- Al Gore _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users