SQLite Forum

Can't Insert the column data to a table

Can't Insert the column data to a table

(1) By Jerry Liu (jerry_szcn) on 2020-12-03 10:35:06 [link] [source]

Hi, Friends!

Do you get any issue when inster a recored to a tableļ¼Ÿ

I create a table by SQL "CREATE TABLE student(id INTEGER PRIMARY KEY AUTOINCREMENT,name VARCHAR(32),score INT);", but I get a error when insert a record to the table student by SQL "INSERT INTO student(name,score) VALUES (Jerry,90);"

The issue came from the Schema initialize when insert the record.The steps as below: Insert statment->sqlite3InitOne-> initial a table azArg[0] = "table"; azArg[1] = zMasterName = SCHEMA_TABLE(iDb); azArg[2] = azArg[1]; azArg[3] = "1"; azArg[4] = "CREATE TABLE x(type text,name text,tbl_name text," "rootpage int,sql text)"; azArg[5] = 0; initData.db = db; initData.iDb = iDb; initData.rc = SQLITE_OK; initData.pzErrMsg = pzErrMsg; initData.mInitFlags = mFlags; initData.nInitRow = 0; sqlite3InitCallback(&initData, 5, (char **)azArg, 0);

Here work correctly,then implement

zSql = sqlite3MPrintf(db, "SELECT*FROM"%w".%s ORDER BY rowid", db->aDb[iDb].zDbSName, zMasterName); rc = sqlite3_exec(db, zSql, sqlite3InitCallback, &initData, 0);

After finished above function, the "sqlite3InitCallback" return "initData.rc = SQLITE_CORRUPT", because get error from here " if( argv[3]==0 ){ corruptSchema(pData, argv[1], 0);"

What the root cause? Any one can help me to fix this issue?

Thanks! Jerry

(2) By Larry Brasfield (LarryBrasfield) on 2020-12-03 11:51:20 in reply to 1 [source]

While I could not completely puzzle out your paragraphs beginning with "The issue ...", I did notice that your insert statement has what appears to be intended as a string literal but which, because it is not single-quoted, is an identifier.

If you really are getting a SQLITE_CORRUPT return from the SQLite library, it means either you have a corrupt database or you have passed something to the SQLite API that was supposed to be a pointer to its database structures but was not. Either way, the library tends not to corrupt its own databases absent problems such as heap corruption or having its own data walked upon by other code.

It is impossible to reasonably guess at your root cause from what you have shown. For one thing, "sqlite3InitCallback(...)" is not a SQLite API, so it must be yours, doing who knows what. It is anybody's guess as to why it returns the string "initData.rc = SQLITE_CORRUPT". Or do you mean to say that initData.rc equals the API constant SQLITE_CORRUPT? I could believe that, but without seeing its code I cannot guess as to why.

BTW, Please use the HTML code tags to delimit your code in posts. For example:

<code> This is my code, without interpretation as markup. </code>