I am creating iOS
app which uses Sqlite DB.
I have created Table
As:
const char *sql_stmt = "CREATE TABLE IF NOT EXISTS ORDERTABLE (ID INTEGER PRIMARY KEY AUTOINCREMENT, ITEMDESC TEXT)";
and then I have to insert self.selectedItemsDictnory Dictionary into ItemDESC i am inserting as :
NSData *data = [NSJSONSerialization dataWithJSONObject:self.selectedItemsDictnory options:NSJSONWritingPrettyPrinted error:nil];
NSString *insertSQL = [NSString stringWithFormat: @"INSERT INTO ORDERTABLE(ITEMDESC)VALUES( \"%@\");",data];
Upto this it is successfully done.
Now i have to retrieve this dictionary in same format
what i am doing is :
if (sqlite3_open(dbpath, &orderDB) == SQLITE_OK)
{
const char* sqlStatement = [[NSString stringWithFormat:@"SELECT * FROM ORDERTABLE WHERE (ID = '%d')",self.orderSelected]cStringUsingEncoding:NSUTF8StringEncoding];
sqlite3_stmt* statement;
if (sqlite3_prepare_v2(orderDB, sqlStatement, -1, &statement, NULL) == SQLITE_OK) {
if( sqlite3_step(statement) == SQLITE_ROW )
{
NSData *retData = (__bridge NSData*) sqlite3_column_value(statement, 1);
NSDictionary *jsonObject=[NSJSONSerialization
JSONObjectWithData:retData
options:NSJSONReadingMutableLeaves
error:nil];
NSLog(@"jsonObject is %@",jsonObject);
NSDictionary *dic = [NSDictionary dictionaryWithContentsOfData:retData];
NSLog(@"dic is %@",dic);
}
}
sqlite3_finalize(statement);
sqlite3_close(orderDB);
}
But i am getting Bad Excess Exception. Please help me out in retrieval of data