Problem in data binding in NSString?
Posted
by Rajendra Bhole
on Stack Overflow
See other posts from Stack Overflow
or by Rajendra Bhole
Published on 2010-06-18T13:59:41Z
Indexed on
2010/06/18
14:03 UTC
Read the original article
Hit count: 149
iphone
Hi, I selecting the row of the table. The text of the row i stored in the application delegate object as a NSString. That NSString i want to retrieving or binding in SELECT statement of SQLite query, For that i written code in the TableView Class
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
selectedText = [appDelegate.categoryArray objectAtIndex:indexPath.row]; appDelegate.selectedTextOfRow = selectedText; ListOfPrayersViewController *listVC = [[ListOfPrayersViewController alloc] init]; [self.navigationController pushViewController:listVC animated:YES];
[listVC release]; }
and database class class code is. + (void) getDuas:(NSString *)dbPath{
if(sqlite3_open([dbPath UTF8String], &database) == SQLITE_OK){
SalahAppDelegate *appDelegate = (SalahAppDelegate *)[[UIApplication sharedApplication] delegate];
NSString *categoryTextForQuery =[NSString stringWithFormat:@"SELECT Category FROM Prayer WHERE Category ='%s'", appDelegate.selectedTextOfRow ];
NSLog(@"The Text %@", categoryTextForQuery);
//const char *sqlQuery1 = (char *)categoryTextForQuery;
//const char *sqlQuery = "SELECT Category FROM Prayer WHERE Category = 'Invocations for the beginning of the prayer'";
sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, [categoryTextForQuery UTF8String], -1, &selectstmt, NULL) == SQLITE_OK){
appDelegate.duasArray =[[NSMutableArray alloc] init];
while(sqlite3_step(selectstmt) == SQLITE_ROW){
NSString *dua = [[NSString alloc] initWithCString:(char *)sqlite3_column_text(selectstmt,0) encoding:NSASCIIStringEncoding];
Prayer *prayerObj = [[Prayer alloc] initwithDuas:dua];
prayerObj.DuaName = dua;
[appDelegate.duasArray addObject:prayerObj];
}
}
}
}
The code is comes out of loop on the statement or starting the loop of the while(sqlite3_step(selectstmt) == SQLITE_ROW) Why? How i bind the table selected text in SELECT statement of sqlite?
© Stack Overflow or respective owner