我是电话编程的新手。我将图像路径和音频路径存储在数据库中。现在我想检索图像路径表单数据库,我得到所有图像路径,但我只想检索 3 个图像路径,剩下的东西我想在其他地方使用。任何人都可以告诉我如何只检索 3 个图像路径表单数据库 下面的代码用于从数据库中检索图像路径
NSString *docsDir;
NSArray *dirPaths;
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
arrayy=[[NSMutableArray alloc]init];
arrayy2=[[NSMutableArray alloc]init];
arrayy1=[[NSMutableArray alloc]init];
// array2=[[NSMutableArray alloc]init];
// Build the path to the database file
databasePath = [docsDir stringByAppendingPathComponent: @"Taukydaataaa.db"];
// NSLog(@"%@",databasePath);
NSFileManager *fn=[NSFileManager defaultManager];
NSError *error;
BOOL success=[fn fileExistsAtPath:databasePath];
if(!success) {
NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Taukydaataaa.db"];
success = [fn copyItemAtPath:defaultDBPath toPath:databasePath error:&error];
}
const char *dbpath = [databasePath UTF8String];
sqlite3_stmt *statement;
if (sqlite3_open(dbpath, &contactDB) == SQLITE_OK)
{
NSString *querySQL = [NSString stringWithFormat: @" select t.imagepath,t.audiopath,t.id from blauky b,taukyblauky tb,tauky t where tb.blaukyid=b.id and tb.taukyid=t.id and tb.blaukyid=1"];
const char *query_stmt = [querySQL UTF8String];
if (sqlite3_prepare_v2(contactDB, query_stmt, -1, &statement, NULL) == SQLITE_OK)
{
while(sqlite3_step(statement) == SQLITE_ROW)
{
email_idField = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,2)];
email_idField1 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,1)];
email_idField2 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,0)];
// NSString *email_idField2 = [[NSString alloc] initWithUTF8String:(const char *) sqlite3_column_text(statement,2)];
NSLog(@"ASlma");
NSLog(@"%@",email_idField);
NSLog(@"%@",email_idField1);
NSLog(@"%@",email_idField2);
[arrayy addObject:email_idField];
[arrayy1 addObject:email_idField1];
[arrayy2 addObject:email_idField2];
NSLog(@"%@",arrayy);
NSLog(@"%@",arrayy1);
NSLog(@"%@",arrayy2);
NSLog(@"Iam here");
}
}
}
}
谢谢阿斯拉姆