【发布时间】:2009-03-11 03:56:19
【问题描述】:
我开始注意到我的 iPhone 应用程序的 SQLite 查询有一个奇怪的行为。每当我执行“INSERT”语句时,都会在我的 db 文件旁边创建一个日志文件(确切的文件名是“userdata.db-journal”)。
如果我正确理解文档,SQLite 会使用此日志文件来回滚以防操作失败。但是操作完成后文件会一直保留在那里。
我执行准备、绑定和执行查询的经典步骤(为简单起见,不检查返回值):
sqlite3 *db = NULL;
sqlite3_open( "userdata.db", &db );
sqlite3_stmt *insertStmt = NULL;
const char *query = "INSERT INTO table VALUES(?,?)";
sqlite3_prepare_v2( db, query, -1, &insertStmt, NULL );
sqlite3_bind_int( insertStmt, 1, 0 );
sqlite3_bind_int( insertStmt, 2, 0 );
sqlite3_step( insertStmt );
sqlite3_reset( insertStmt );
sqlite3_clear_bindings( insertStmt );
sqlite3_close( db );
日志文件是在调用 'sqlite3_step' 函数后创建的,并一直保留在那里,直到我关闭数据库。我需要做什么才能让它消失?
【问题讨论】: