Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-15-2010, 08:44 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 324
mariano_donati is on a distinguished road
Default SQlite is not commiting changes

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 {
    
NSStringpath;
    
sqlite3connection;
    
sqlite3_stmtcurrentStmt;
    
short paramIndex;
}

-(
voidbindVarchar:(const char*) value;
-(
voidbindInt:(int) value;
-(
voidclose;
-(
voidexecuteNonQuery;
-(bool) 
fetchRow;
-(const 
unsigned char*) fetchColumn:(int) index;
-(
voidopen;
-(
voidprepare:(const char*) statement;

@
end
/****************/

@implementation Db

-(Db*) init
{
    if(
self = [super init])
    {
        
path = [[[NSBundle mainBundleresourcePathstringByAppendingPathComponent:@"sudoku_db.sql"];
        
connection NULL;
        
paramIndex 1;
    }
    return 
self;
}

-(
voidbindVarchar:(const char*) value
{
    if(
sqlite3_bind_text(currentStmtparamIndexvaluestrlen(value), SQLITE_STATIC) != SQLITE_OK)
        
printf("error on Database::bindVarchar - %s\n"sqlite3_errmsg(connection));
    
paramIndex += 1;
}

-(
voidbindInt:(int)value
{
    if(
sqlite3_bind_int(currentStmtparamIndexvalue) != SQLITE_OK)
        
printf("error on Database::bindInt - %s\n"sqlite3_errmsg(connection));
    
paramIndex += 1;
}

-(
voidclose
{
    if(
sqlite3_close(connection) != SQLITE_OK)
        
printf("error on Database::close - %s\n"sqlite3_errmsg(connection));
    
currentStmt NULL;
    
connection NULL;
    
paramIndex 1;
}

-(
voidexecuteNonQuery
{
    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(currentStmtindex);
}

-(bool) 
fetchRow
{
    
bool hasRow sqlite3_step(currentStmt) == SQLITE_ROW;
    if(!
hasRow
    {
        
sqlite3_finalize(currentStmt);
        
paramIndex 1;
    }
    return 
hasRow;
}

-(
voidprepare:(const char *)statement
{
    if(
sqlite3_prepare_v2(connectionstatement, -1, &currentStmtNULL) != SQLITE_OK)
        
printf("error on Database::prepare - %s\n"sqlite3_errmsg(connection));
}

-(
voidopen
{
    
sqlite3_open([path UTF8String], &connection);
}

@
end 
and this is how I'm using it (the following code executes within viewDidLoad):

PHP Code:
    Dbdb = [[Db allocinit];
    [
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.
mariano_donati is offline   Reply With Quote
Old 09-16-2010, 12:05 AM   #2 (permalink)
Registered Member
 
kelvinkao's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
kelvinkao is on a distinguished road
Send a message via AIM to kelvinkao
Default

The files in your bundle are basically read-only. If you were able to modify it, then it's probably done on some kind of temporary copy that only exists while the app runs. You need to copy the database into your app's Documents folder and do all subsequent load and save there instead.
__________________
My dev blog:
http://www.kelvinkaodev.com
kelvinkao is offline   Reply With Quote
Old 09-20-2010, 02:53 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 324
mariano_donati is on a distinguished road
Default

Thank you very much. I've just implemented that way and it worked like a charm.
mariano_donati is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 331
19 members and 312 guests
2ndSegment, bignoggins, cayladv57, cgokey, dermotos, djohnson, Domele, guusleijsten, Hamad, heshiming, linkmx, markuschow, Objective Zero, pungs, Rudy, Sloshmonster, teebee74, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,655
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, pungs
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:54 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0