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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 02-15-2009, 07:04 PM   #1 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 8
Unhappy SQL3 differences between simulator and iPod Touch

I am using an sql database. Works fine with the simulator but when I test on iPod Touch, the statement "if(sqlite3_prepare_v2(database, sql, -1, &compiledStatement, NULL) == SQLITE_OK)" is never true i.e. does not fine anything in the database.

Anyone have any suggestions where to look?

Thanks
dbrownstone is offline   Reply With Quote
Old 02-15-2009, 09:13 PM   #2 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

folder names are different on the device. show us how you access "database"
lbendlin is offline   Reply With Quote
Old 02-16-2009, 05:41 PM   #3 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 8
Default

Quote:
Originally Posted by lbendlin View Post
folder names are different on the device. show us how you access "database"

static sqlite3 *database = nil;
static NSString *kDatabaseName = @"mydatabase.db";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:kDatabaseName];

if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) {
.....

Last edited by dbrownstone; 02-16-2009 at 05:45 PM.
dbrownstone is offline   Reply With Quote
Old 02-16-2009, 05:47 PM   #4 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 8
Default

static sqlite3 *database = nil;
static NSString *kDatabaseName = @"mydatabase.db";
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDire ctory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *databasePath = [documentsDir stringByAppendingPathComponent:kDatabaseName];

if (sqlite3_open([databasePath UTF8String], &database) != SQLITE_OK) {
.....
dbrownstone is offline   Reply With Quote
Old 02-16-2009, 05:50 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

The database file is initially in the bundle folder. You need to copy it to the documents folder if it doesn't exist there. Look at the SQLBooks example for 'copydatabaseifneeded'
lbendlin is offline   Reply With Quote
Old 02-16-2009, 06:30 PM   #6 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 8
Default

Quote:
Originally Posted by lbendlin View Post
The database file is initially in the bundle folder. You need to copy it to the documents folder if it doesn't exist there. Look at the SQLBooks example for 'copydatabaseifneeded'
I guess I missed that! However, surely if the db is not in the right place, the sqlite3_open would fail - it did not!
dbrownstone is offline   Reply With Quote
Old 02-17-2009, 04:31 PM   #7 (permalink)
New Member
 
Join Date: May 2008
Posts: 99
Default

Quote:
Originally Posted by dbrownstone View Post
I guess I missed that! However, surely if the db is not in the right place, the sqlite3_open would fail - it did not!
Yeah, sqlite3_open never fails.
bgeerdes is offline   Reply With Quote
Old 02-17-2009, 04:44 PM   #8 (permalink)
Registered Member
 
Join Date: Dec 2008
Posts: 429
Default

oh, it can fail easily, and if you don't implement your own checks it will happily open nonexisting databases and write to them. Been there, done that.
lbendlin is offline   Reply With Quote
Old 02-17-2009, 04:47 PM   #9 (permalink)
New Member
 
Join Date: Jan 2009
Posts: 8
Default

Quote:
Originally Posted by lbendlin View Post
oh, it can fail easily, and if you don't implement your own checks it will happily open nonexisting databases and write to them. Been there, done that.
Well whatever... I did make the change - adding something along the lines of the "copydatabaseifneeded" code as you suggested, and, after cleaning up the iPod, it worked!!

Thanks for the help.
dbrownstone is offline   Reply With Quote
Old 02-17-2009, 04:58 PM   #10 (permalink)
New Member
 
Join Date: May 2008
Posts: 99
Default

Quote:
Originally Posted by lbendlin View Post
oh, it can fail easily
Well, if you want to be technical, *it* thinks it never fails and never returns an error code (as far as I can tell).
bgeerdes is offline   Reply With Quote
Reply

Bookmarks

Tags
differences, sqlite3

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: 266
19 members and 247 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, JasonR, mer10, prchn4christ, Promo Dispenser, Punkjumper, Rudy, sacha1996, sneaky, spiderguy84, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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