gpt4 book ai didi

iphone - 从 NSMutable 字典中分离键和对象,并在 sqlite 的插入命令中使用值

转载 作者:行者123 更新时间:2023-12-02 04:17:42 25 4
gpt4 key购买 nike

大家好,我正在 iPhone 中开发一个 sqlite 应用程序。因为我是这个应用程序的新手,所以我不知道如何在 sqlite 的插入语句命令中使用 NSMutableDictionary 中的键和对象。例如,我想要以下格式的插入语句。

插入表名(列名作为 NSMUTABLEDICTIONARY 中的键)值(值作为 NSMUTABLEDICTIONARY 中的对象)请帮帮我。谢谢

最佳答案

我实际上对 SQL 知之甚少,但也许这样的东西会对你有所帮助:

NSDictionary *myDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
@"Foo", @"Bar",
@"Foz", @"Baz",
nil];

NSMutableString *keys = [NSMutableString string];
NSMutableString *values = [NSMutableString string];
for (NSString *key in myDictionary) {
[keys appendFormat:@"%@,", key];
[values appendFormat:@"%@,", [myDictionary objectForKey:key]];
}
// remove last ,
[keys deleteCharactersInRange:NSMakeRange([keys length]-1, 1)];
[values deleteCharactersInRange:NSMakeRange([values length]-1, 1)];
NSString *sqlQuery = [NSString stringWithFormat:@"INSERT INTO TABLENAME %@ VALUES %@", keys, values];

// sqlQuery = INSERT INTO TABLENAME Bar,Baz VALUES Foo,Foz

关于iphone - 从 NSMutable 字典中分离键和对象,并在 sqlite 的插入命令中使用值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5677396/

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