jeudi 15 janvier 2015

SELECT Statement Not Worked in Sqllite iOS

i am newbie in iOS Development, and also newbie in sqllite i want to Fetch Data From Sqllite Table With SELECT Statement with WHERE clause but it is Not Working Plese Give me Solution for it. Here i Write a code like as



- (void)getTextFomDB
{
NSString *docsDir;
NSArray *dirPaths;
NSError *error;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];

_databasePath = [[NSString alloc]
initWithString: [docsDir stringByAppendingPathComponent:
@"sampleDatabase.db"]];

const char *dbpath = [_databasePath UTF8String];
sqlite3_stmt *statement;
int bookmark=1;
if (sqlite3_open(dbpath, &_myDatabase) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat:@"SELECT PostId,PostTitle,ImageLink,ShortDescription,Category,PostDate FROM ALLREADTABLE WHERE Bookmark==\"%d\"",bookmark];

const char *query_stmt = [querySQL UTF8String];

if (sqlite3_prepare_v2(_myDatabase, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
[self.postId removeAllObjects];
[self.postTitle removeAllObjects];
[self.imageLink removeAllObjects];
[self.shortDecsription removeAllObjects];
[self.category removeAllObjects];
[self.postDate removeAllObjects];
while (sqlite3_step(statement) == SQLITE_ROW) {
NSString *postId = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 0)];
NSString *postTitle = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 1)];
NSString *ImageLink = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 2)];
shortDescription = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 3)];
NSString *Category = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 4)];
NSString *postDate = [[NSString alloc] initWithUTF8String: (const char *) sqlite3_column_text(statement, 5)];
[self.postId addObject:[NSString stringWithFormat:@"%@ ", postId]];
[self.postTitle addObject:[NSString stringWithFormat:@"%@ ",postTitle]];
[self.imageLink addObject:[NSString stringWithFormat:@"%@",ImageLink]];
[self.shortDecsription addObject:[NSString stringWithFormat:@" %@",shortDescription]];
[self.category addObject:[NSString stringWithFormat:@" %@",Category]];
[self.postDate addObject:[NSString stringWithFormat:@" %@",postDate]];
}
sqlite3_finalize(statement);
}
sqlite3_close(_myDatabase);
NSLog(@"Error %@",error);
}
}


Here self.postId,postTitle,imageLink,shortDescription,imageLink,category,postdate all are NSMuttable array.


Aucun commentaire:

Enregistrer un commentaire