Hi. I'm performing some inserts during my application is running. The trouble is that I'm only able to see this changes while my application is running. If I close it, all changes dissapears. It's the same problem discussed here
http://www.iphonedevsdk.com/forum/ip...e-changes.html.
I'm finalizing all my prepared statements and every sqlite call returns an ok or done result, so no error is found.
Here's my wrapper:
PHP Code:
#import <Foundation/Foundation.h>
#import <sqlite3.h>
@interface Db : NSObject {
NSString* path;
sqlite3* connection;
sqlite3_stmt* currentStmt;
short paramIndex;
}
-(void) bindVarchar:(const char*) value;
-(void) bindInt:(int) value;
-(void) close;
-(void) executeNonQuery;
-(bool) fetchRow;
-(const unsigned char*) fetchColumn:(int) index;
-(void) open;
-(void) prepare:(const char*) statement;
@end
/****************/
@implementation Db
-(Db*) init
{
if(self = [super init])
{
path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"sudoku_db.sql"];
connection = NULL;
paramIndex = 1;
}
return self;
}
-(void) bindVarchar:(const char*) value
{
if(sqlite3_bind_text(currentStmt, paramIndex, value, strlen(value), SQLITE_STATIC) != SQLITE_OK)
printf("error on Database::bindVarchar - %s\n", sqlite3_errmsg(connection));
paramIndex += 1;
}
-(void) bindInt:(int)value
{
if(sqlite3_bind_int(currentStmt, paramIndex, value) != SQLITE_OK)
printf("error on Database::bindInt - %s\n", sqlite3_errmsg(connection));
paramIndex += 1;
}
-(void) close
{
if(sqlite3_close(connection) != SQLITE_OK)
printf("error on Database::close - %s\n", sqlite3_errmsg(connection));
currentStmt = NULL;
connection = NULL;
paramIndex = 1;
}
-(void) executeNonQuery
{
if(sqlite3_step(currentStmt) != SQLITE_DONE)
printf("error on Database::executeNonQuery - %s\n", sqlite3_errmsg(connection));
sqlite3_finalize(currentStmt);
paramIndex = 1;
}
-(const unsigned char*) fetchColumn:(int)index
{
return sqlite3_column_text(currentStmt, index);
}
-(bool) fetchRow
{
bool hasRow = sqlite3_step(currentStmt) == SQLITE_ROW;
if(!hasRow)
{
sqlite3_finalize(currentStmt);
paramIndex = 1;
}
return hasRow;
}
-(void) prepare:(const char *)statement
{
if(sqlite3_prepare_v2(connection, statement, -1, ¤tStmt, NULL) != SQLITE_OK)
printf("error on Database::prepare - %s\n", sqlite3_errmsg(connection));
}
-(void) open
{
sqlite3_open([path UTF8String], &connection);
}
@end
and this is how I'm using it (the following code executes within viewDidLoad):
PHP Code:
Db* db = [[Db alloc] init];
[db open];
[db prepare:"insert into SAVEDGAMES (PROBLEM, POINTS, PUZZLES_ID) values (?, ?, ?)"];
[db bindVarchar:"00000000003232323232"];
[db bindVarchar:"123123"];
[db bindInt:1];
[db executeNonQuery];
[db close];
Can you see what's wrong?.
Thanks.