Re: [sqlite] why is the data file locked after writing?

2009-06-17 Thread Igor Tandetnik
liubin liu wrote:
> why is the data file locked after writing?
>
> the last printf() result is:
> # IN END, ret = 5

Because you still have a statement in progress. Finalize it with 
sqlite3_finalize.

Igor Tandetnik 



___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] why is the data file locked after writing?

2009-06-17 Thread liubin liu

why is the data file locked after writing?

the last printf() result is:
# IN END, ret = 5

according to the "Result Codes":
#define SQLITE_BUSY 5   /* The database file is locked */

It means to the database file is locked? why does it happen after writing?


_

// basic10.c

#include 
#include 

#include 


int main ( void )
{
int ret = 0;

sqlite3 *db = NULL;
sqlite3_stmt *p_stmt = NULL;

char *sql_ct = "CREATE TABLE table1 (id INTEGER, m INTEGER, n
VARCHAR(32), t CHAR(1), con VARCHAR(512))";
char *sql_in = "INSERT INTO table1 VALUES (%d, %d, %Q, %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 );

sql = sqlite3_mprintf ( sql_in, 0, 0, "goodc", 0, "test -
varcharvarcharvarchar" );
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_close ( db );
printf ( "# IN END, ret = %d\n", ret );
system ( "rm test.db" );

return 0;
}

_

[...@lb basic]$ make basic10
[...@lb basic]$ ./basic10 
# AFTER sqlite3_open, ret = 0
# AFTER sqlite3_exec, create table,   ret = 0
# AFTER sqlite3_prepare_v2,   ret = 0
# AFTER sqlite3_step, ret = 101
# IN END, ret = 5

-- 
View this message in context: 
http://www.nabble.com/why-is-the-data-file-locked-after-writing--tp24071633p24071633.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