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 > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 07-19-2010, 09:00 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default SQLite Problem

Hello,

I'm trying to select data from the database and I have the following code in place:
Code:
// Setup the database object
	sqlite3 *database;
	
	// Init the animals Array
	list = [[NSMutableArray alloc] init];
	NSLog(@"documents path: ", documentsDir);	
	NSLog(@"database path: ", databasePath);
	
	// Open the database from the users filessytem
	if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 
	{
		// Setup the SQL Statement and compile it for faster access
		const char *sqlStatement = "select route_name from Route";
		sqlite3_stmt *compiledStatement;
		if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) 
		{
			// Loop through the results and add them to the feeds array
			while(sqlite3_step(compiledStatement) == SQLITE_ROW) 
			{
				// Read the data from the result row
				NSString *aName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
				
				// Add the animal object to the animals Array
				//[list addObject:animal];				
				[list addObject:aName];				
				//[animal release];
			}
		}
		// Release the compiled statement from memory
		sqlite3_finalize(compiledStatement);		
	}
	sqlite3_close(database);
I'm getting EXC_BAD_ACCESS error at the first IF statement. Anyone any thoughts.

Also in the NSLOG documentsDir and databasePath are blank.

I have the following code in ViewDidLoad:
Code:
-(void)viewDidLoad 
{	
	// Setup some globals
	databaseName = @"xxxxxxCoreData.sqlite";
	
	// Get the path to the documents directory and append the databaseName
	NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//	NSString *documentsDir = [documentPaths objectAtIndex:0];
	documentsDir = [documentPaths objectAtIndex:0];
	databasePath = [documentsDir stringByAppendingPathComponent:databaseName];
stephen is offline   Reply With Quote
Old 07-19-2010, 09:37 AM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 72
F.R.E.E. is on a distinguished road
Default

you answered your own question, the path to the database is NULL.
F.R.E.E. is offline   Reply With Quote
Old 07-19-2010, 09:42 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Quote:
Originally Posted by F.R.E.E. View Post
you answered your own question, the path to the database is NULL.
Thanks FREE, yeah I kind of guess that. Any ideas why the path is null ?
stephen is offline   Reply With Quote
Old 07-19-2010, 11:10 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 129
stephen is on a distinguished road
Default

Okay, I've updated the code slightly and I'm getting the database path now:

Code:
-(void)viewDidLoad 
{	
	NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *documentsDir = [documentPaths objectAtIndex:0];
	databasePath = [[documentsDir stringByAppendingPathComponent:databaseName] copy];
}
But its not its doesn't go through the following IF statement:

Code:
	if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
Any thoughts ?
stephen 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: 382
14 members and 368 guests
AragornSG, ChrisYates, coolman, davejas69, givensur, guusleijsten, hussain1982, jbro, Kryckter, locombiano89, Mah6447, Meoz, stanny, WeaselPig
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,646
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, locombiano89
Powered by vBadvanced CMPS v3.1.0

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