why is the data file locked after after using transaction? the last result of printf() is: # IN END, ret = 5
It means to the database file is locked? why does it happen after using transaction although using sqlite3_finalize()? PS: if shielding the codes relating with the transaction, all the result of printf() is correct. _______________________________________________________ // basic9.c #include <unistd.h> // for sleep(); #include <stdlib.h> // for system(); #include <stdio.h> // for printf(); #include <sqlite3.h> int main ( void ) { int ret = 0; int i = 0; int n = 10; sqlite3 *db = NULL; sqlite3_stmt *p_stmt = NULL; char *sql_ct = "CREATE TABLE table1 (id INTEGER, m INTEGER, con VARCHAR(512))"; char *sql_in = "INSERT INTO table1 VALUES (%d, %d, %Q)"; char *sql = NULL; ret = sqlite3_open ( "test.db", &db ); printf ( "# AFTER sqlite3_open, ret = %d\n", ret ); ret = sqlite3_exec ( db, sql_ct, NULL, NULL, NULL ); printf ( "# AFTER sqlite3_exec, create table, ret = %d\n", ret ); // system ( "free" ); // 采用事务; ret = sqlite3_prepare_v2 ( db, "BEGIN", -1, &p_stmt, 0 ); ret = sqlite3_step ( p_stmt ); // 创建事务; for ( i=0; i<n; i++ ) { sql = sqlite3_mprintf ( sql_in, i, i%(n/10), "test - - - varchar - varcharvarchar" ); ret = sqlite3_prepare_v2 ( db, sql, -1, &p_stmt, NULL ); // printf ( "# AFTER sqlite3_prepare_v2, ret = %d\n", ret ); ret = sqlite3_step ( p_stmt ); // printf ( "# AFTER sqlite3_step, ret = %d\n", ret ); sqlite3_free ( sql ); } // 提交事务; ret = sqlite3_prepare_v2 ( db, "COMMIT", -1, &p_stmt, 0 ); ret = sqlite3_step ( p_stmt ); //system ( "free" ); ret = sqlite3_finalize ( p_stmt ); printf ( "# AFTER sqlite3_finalize, ret = %d\n", ret ); ret = sqlite3_close ( db ); printf ( "# IN END, ret = %d\n", ret ); sleep ( 20 ); system ( "rm test.db" ); return 0; } _______________________________________________________ [...@lb basic]$ [...@lb basic]$ make basic9 gcc -Wall -lsqlite3 basic9.c -o basic9 [...@lb basic]$ [...@lb basic]$ ./basic9 # AFTER sqlite3_open, ret = 0 # AFTER sqlite3_exec, create table, ret = 0 # AFTER sqlite3_finalize, ret = 0 # IN END, ret = 5 [...@lb basic]$ -- View this message in context: http://www.nabble.com/why-is-the-data-file-locked-after-after-using-transaction--tp24085034p24085034.html Sent from the SQLite mailing list archive at Nabble.com. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users