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-13-2010, 07:03 PM   #1 (permalink)
Registered Member
 
lifeCoder45's Avatar
 
Join Date: Nov 2009
Location: Illinois
Posts: 92
lifeCoder45 is on a distinguished road
Send a message via AIM to lifeCoder45
Default 'Unknown Error' SQLITE Error

Hey guys. I have this bit of code, which is causing me some grief. I have no clue why it is erroring or why it is unknown:

Code:
sqlite3 *database3;
	
	if(sqlite3_open([self.databasePath UTF8String], &database3) == SQLITE_OK) {
		
		const char *sqlStatement2 = "SELECT COUNT(*) FROM `transactions` WHERE `account_id`=? AND `type`=?";
		
		sqlite3_stmt *compiledStatement2;
		
		if(sqlite3_prepare_v2(database3, sqlStatement2, -1, &compiledStatement2, NULL) != SQLITE_OK){
			
			NSLog(@"Prepare Error. '%s'", sqlite3_errmsg(database3));
			
		}//end if
		
		sqlite3_bind_int(compiledStatement2, 1, [loadId intValue]);
		sqlite3_bind_int(compiledStatement2, 2, 1);
		
		if(sqlite3_step(compiledStatement2) != SQLITE_DONE){
			
			NSLog(@"Step Error: '%s'", sqlite3_errmsg(database3));
			
		}//end if

		self.totalCreditItems = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement2, 0)] intValue];

		sqlite3_finalize(compiledStatement2);
		
	}//end if
	
	sqlite3_close(database3);

        NSLog(@"Items: %@",self.totalCreditItems);
Produces:

Code:
2010-09-13 19:01:02.884 X[26415:207] Step Error: 'unknown error'
2010-09-13 19:01:02.886 X[26415:207] Items: (null)
It's ending up with an sql statement of (I think):

Code:
SELECT COUNT(*) FROM `transactions` WHERE `account_id`=2 AND `type`=1
Which when I run through SQLITE Manager yields a count of 1, as it should.

Thoughts?

Thanks a lot!

- Josh
lifeCoder45 is offline   Reply With Quote
Old 09-13-2010, 07:42 PM   #2 (permalink)
Registered Member
 
lifeCoder45's Avatar
 
Join Date: Nov 2009
Location: Illinois
Posts: 92
lifeCoder45 is on a distinguished road
Send a message via AIM to lifeCoder45
Default

Here it is with some more logging. Makes zero sense.

Code:
	// calculate total credit
	
	sqlite3 *database3;
	
	sqlite3_open([self.databasePath UTF8String], &database3);
		NSLog(@"Open Error: '%s'", sqlite3_errmsg(database3));
	
	const char *sqlStatement2 = "SELECT COUNT(*) FROM `transactions` WHERE `account_id`=? AND `type`=1";
		
	sqlite3_stmt *compiledStatement2;
		
	sqlite3_prepare_v2(database3, sqlStatement2, -1, &compiledStatement2, NULL);
		NSLog(@"Prepare Error: '%s'", sqlite3_errmsg(database3));
					
	sqlite3_bind_int(compiledStatement2, 1, [loadId intValue]);
		NSLog(@"Bind Error: '%s'", sqlite3_errmsg(database3));
		
	sqlite3_step(compiledStatement2);
		NSLog(@"Step Error: '%s'", sqlite3_errmsg(database3));

	self.totalCreditItems = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement2, 0)] intValue];

	sqlite3_finalize(compiledStatement2);
		NSLog(@"Finalize Error: '%s'", sqlite3_errmsg(database3));

	sqlite3_close(database3);
		NSLog(@"Close Error: '%s'", sqlite3_errmsg(database3));
	
		NSLog(@"Items: %@",self.totalCreditItems);
Yields a no-error crash plus:

Code:
[Session started at 2010-09-13 19:38:52 -0500.]
2010-09-13 19:38:55.390 X[27266:207] Open Error: 'not an error'
2010-09-13 19:38:55.393 X[27266:207] Prepare Error: 'not an error'
2010-09-13 19:38:55.393 X[27266:207] Bind Error: 'not an error'
2010-09-13 19:38:55.395 X[27266:207] Step Error: 'unknown error'
2010-09-13 19:38:55.396 X[27266:207] Finalize Error: 'not an error'
2010-09-13 19:38:55.397 X[27266:207] Close Error: 'library routine called out of sequence'
Links to the db:





I'm going crazy!

- Josh
lifeCoder45 is offline   Reply With Quote
Old 09-13-2010, 08:14 PM   #3 (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

Maybe it's the way you write single quotes?
__________________
My dev blog:
http://www.kelvinkaodev.com
kelvinkao is offline   Reply With Quote
Old 09-14-2010, 05:18 AM   #4 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 62
devanshree.c is on a distinguished road
Thumbs up

Quote:
Originally Posted by lifeCoder45 View Post
Here it is with some more logging. Makes zero sense.

Code:
	// calculate total credit
	
	sqlite3 *database3;
	
	sqlite3_open([self.databasePath UTF8String], &database3);
		NSLog(@"Open Error: '%s'", sqlite3_errmsg(database3));
	
	const char *sqlStatement2 = "SELECT COUNT(*) FROM `transactions` WHERE `account_id`=? AND `type`=1";
		
	sqlite3_stmt *compiledStatement2;
		
	sqlite3_prepare_v2(database3, sqlStatement2, -1, &compiledStatement2, NULL);
		NSLog(@"Prepare Error: '%s'", sqlite3_errmsg(database3));
					
	sqlite3_bind_int(compiledStatement2, 1, [loadId intValue]);
		NSLog(@"Bind Error: '%s'", sqlite3_errmsg(database3));
		
	sqlite3_step(compiledStatement2);
		NSLog(@"Step Error: '%s'", sqlite3_errmsg(database3));

	self.totalCreditItems = [[NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement2, 0)] intValue];

	sqlite3_finalize(compiledStatement2);
		NSLog(@"Finalize Error: '%s'", sqlite3_errmsg(database3));

	sqlite3_close(database3);
		NSLog(@"Close Error: '%s'", sqlite3_errmsg(database3));
	
		NSLog(@"Items: %@",self.totalCreditItems);
Yields a no-error crash plus:

Code:
[Session started at 2010-09-13 19:38:52 -0500.]
2010-09-13 19:38:55.390 X[27266:207] Open Error: 'not an error'
2010-09-13 19:38:55.393 X[27266:207] Prepare Error: 'not an error'
2010-09-13 19:38:55.393 X[27266:207] Bind Error: 'not an error'
2010-09-13 19:38:55.395 X[27266:207] Step Error: 'unknown error'
2010-09-13 19:38:55.396 X[27266:207] Finalize Error: 'not an error'
2010-09-13 19:38:55.397 X[27266:207] Close Error: 'library routine called out of sequence'
Links to the db:





I'm going crazy!

- Josh
Either you have to add a semicolon to query statement as:

const char *sqlStatement2 = "SELECT COUNT(*) FROM `transactions` WHERE `account_id`=? AND `type`=1;";

And if this is not the problem then check out your single quotes
devanshree.c 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: 330
14 members and 316 guests
Absentia, cgokey, fiftysixty, givensur, heshiming, iGamesDev, linkmx, michaelhansen, mraalex, PixelInteractive, raihan.zbr, Sloshmonster, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,117
Posts: 402,890
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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