Hi,
in an application I encountered a problem, where the changing of the
structure of a table by dropping and recreating it via one connection to
a db was not directly seen by another connection to the same db. I could
reproduce the problem with the test program below. Inserting a
sqlite3_step (case 2) changes the output results of the program, which
represents actually the problem I have.
Could you please have a look at it?
SQLite version: 3.24 amalgination
OS: Windows 10
Compiler: Visual Studio Community 2017
Output case 1:
Column count: 1 -> OK
Column count: 2 -> OK
Column count: 1 -> should be 2
Column count: 1 -> should be 2
Output case 2:
Column count: 1 -> OK
Column count: 2 -> OK
Column count: 1 -> should be 2
Column count: 2 -> OK
Test program:
int main()
{
sqlite3* conn1;
sqlite3* conn2;
sqlite3_open("test.db", &conn1);
// the next two lines are only for preparing the db. They are not
relevant for the problem.
sqlite3_exec(conn1, "drop table if exists test", NULL, NULL, NULL);
sqlite3_exec(conn1, "create table test(a text)",NULL,NULL,NULL);
const char* select = "select * from test";
sqlite3_stmt* stmt;
sqlite3_prepare_v2(conn1, select, -1, &stmt, NULL);
printf("Column count: %d\n", sqlite3_column_count(stmt));
sqlite3_finalize(stmt);
sqlite3_open("test.db", &conn2);
sqlite3_exec(conn2, "drop table test;", NULL, NULL, NULL);
sqlite3_exec(conn2, "create table test(a text,b text);", NULL, NULL,
NULL);
sqlite3_prepare_v2(conn2, select, -1, &stmt, NULL);
printf("Column count: %d\n", sqlite3_column_count(stmt));
sqlite3_finalize(stmt);
// closing the second connection can also be done at the end of the
program. The result doesn't change.
sqlite3_close(conn2);
sqlite3_prepare_v2(conn1, select, -1, &stmt, NULL);
printf("Column count: %d\n", sqlite3_column_count(stmt));
/********** only case 2 *******************/
sqlite3_step(stmt);
/******************************************/
sqlite3_finalize(stmt);
sqlite3_prepare_v2(conn1, select, -1, &stmt, NULL);
printf("Column count: %d\n", sqlite3_column_count(stmt));
sqlite3_finalize(stmt);
sqlite3_close(conn1);
return 0;
}
Regards,
Jürgen
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users