gpt4 book ai didi

iphone - 如何从 iPhone 数据库中仅检索 3imagepaths 或 id

转载 作者:行者123 更新时间:2023-11-29 03:59:46 26 4
gpt4 key购买 nike

我是手机编程的新手。我将图像路径和音频路径存储在数据库中。现在我想从数据库中检索图像路径,我得到了所有图像路径,但我只想检索剩下的 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");

}
}
}
}

谢谢阿斯拉姆

最佳答案

您可以将 LIMIT 3 添加到您的查询中。

关于iphone - 如何从 iPhone 数据库中仅检索 3imagepaths 或 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16032310/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com