 |
 |
|
 |
09-13-2010, 07:03 PM
|
#1 (permalink)
|
|
Registered Member
Join Date: Nov 2009
Location: Illinois
Posts: 92
|
'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
|
|
|
09-13-2010, 07:42 PM
|
#2 (permalink)
|
|
Registered Member
Join Date: Nov 2009
Location: Illinois
Posts: 92
|
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
|
|
|
09-13-2010, 08:14 PM
|
#3 (permalink)
|
|
Registered Member
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
|
Maybe it's the way you write single quotes?
|
|
|
09-14-2010, 05:18 AM
|
#4 (permalink)
|
|
Registered Member
Join Date: Sep 2010
Posts: 62
|
Quote:
Originally Posted by lifeCoder45
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
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» 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 |
|