-(NSMutableArray *)readInformationFromDatabase
{
NSMutableArray *array = [[NSMutableArray alloc] init];
// Setup the database object
sqlite3 *database;
// Open the database from the users filessytem
if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK)
{
// Setup the SQL Statement and compile it for faster access
//SQLIte Statement
NSString *sqlStatement_userInfo =[NSString stringWithFormat:@"Select * from TableName"];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, [sqlStatement_userInfo UTF8String], -1, &compiledStatement, NULL) == SQLITE_OK)
{
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW)
{
// Init the Data Dictionary
NSMutableDictionary *_dataDictionary=[[NSMutableDictionary alloc] init];
NSString *_userName = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 0)];
// NSLog(@"_userName = %@",_userName);
NSString *_emailID = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 2)];
// NSLog(@"_emailID = %@",_emailID);
NSString *_contactNumber = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 1)];
// NSLog(@"_contactNumber = %@",_contactNumber);
NSString *_address = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 3)];
// NSLog(@"_address = %@",_address);
NSString *_zipCode = [NSString stringWithUTF8String:(char *)sqlite3_column_text(compiledStatement, 4)];
// NSLog(@"_zipCode = %@",_zipCode);
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",_userName] forKey:@"UserName"];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",_emailID] forKey:@"EmailId"];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",_contactNumber] forKey:@"ContactNumber"];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",_address] forKey:@"Address"];
[_dataDictionary setObject:[NSString stringWithFormat:@"%@",_zipCode] forKey:@"ZIPCode"];
[array addObject:_dataDictionary];
}
}
else
{
NSLog(@"No Data Found");
}
// Release the compiled statement from memory
sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);
return array;
}
谢谢,但是我怎么能知道我目前的记录?如果我有100条记录,我该如何寻找该特定行。 有谁知道下面的sqlite命令有什么问题? NSString * sql = [NSString stringWithFormat:@“SELECT * FROM abc WHERE name = \”john \“”] 当我执行它时崩溃。 再次感谢您的帮助。 – 2013-05-02 09:22:01
您好Nishant,不确定论坛是否允许私下与您联系?如果是我适合您的电子邮件,我想问问并提供。谢谢。 – 2013-05-02 12:03:33