SQLite Forum

sqlite3_stmt_readonly is dependent on the current database
Login
sqlite3_stmt_readonly gives valid results only if you check right after you prepare the statement. 

```
char *err;
sqlite3 *db;
sqlite3_stmt *s1, *s2;

sqlite3_open(":memory:", &db);

sqlite3_prepare_v3(db, "CREATE TABLE IF NOT EXISTS data(key TEXT);",-1, SQLITE_PREPARE_PERSISTENT, &s1, NULL);

// Prints 0, not readonly
printf("Readonly : %d \n", sqlite3_stmt_readonly(s1));

sqlite3_exec(db,"CREATE TABLE IF NOT EXISTS data(key TEXT);", NULL,NULL, &err);

sqlite3_prepare_v3(db, "CREATE TABLE IF NOT EXISTS data(key TEXT);",-1, SQLITE_PREPARE_PERSISTENT, &s2, NULL);

// Prints 1, readonly
printf("Readonly : %d \n", sqlite3_stmt_readonly(s2));


sqlite3_exec(db,"DROP TABLE data;", NULL, NULL, &err);

// Prints 1, readonly
printf("Readonly : %d \n", sqlite3_stmt_readonly(s2));

```

Also, I'd expect sqlite3_stmt_readonly would be more like a generic API. E.g it gives 'false' for UPDATE clauses even the statement will not change the database. 

Overall, I find this behavior confusing. Can this be improved somehow? If not, could you consider adding documentation for that please?