【发布时间】:2012-09-24 11:21:22
【问题描述】:
如何将nsmutablearray添加到sqlite数据库表中?谁能帮我写代码?
【问题讨论】:
-
你的数组中的数据是什么??如果可能,提供一些代码 sn-p 。
标签: iphone ios sqlite nsmutablearray
如何将nsmutablearray添加到sqlite数据库表中?谁能帮我写代码?
【问题讨论】:
标签: iphone ios sqlite nsmutablearray
你可以使用:
for (int i = 0; i < [mutArray count]; i++)
{
NSString *string = [mutArray objectAtIndex:i];
// insert query
insert into table_name ('string') values(column_name);
}
【讨论】:
使用循环控件对数组进行排序并插入每个值
示例:
for(int itemIndex = 0; itemIndex < [yourArray count];itemIndex++){
NSString *myname = [yourArray objectAtIndex:itemIndex];
//insert myname to database.
}
要检索,您可以使用下面的示例代码
if(sqlite3_open([path UTF8String], &dataBase) == SQLITE_OK)
{
NSString *query = [NSString stringWithFormat:@"select name from syncTable where Crc = %d",crc]; const char *sql = [query UTF8String];
sqlite3_stmt *statement;
if (sqlite3_prepare(dataBase, sql, -1, &statement, NULL) == SQLITE_OK)
{
char *name;
unsigned int value;
while(sqlite3_step(statement) == SQLITE_ROW)
{
name = (char *)sqlite3_column_text(statement, 0);
[yourArray addObject:[NSString stringWithUTF8String:name]];
}
sqlite3_finalize(statement);
}
}
【讨论】:
NSString *myname = [yourArrayCount objectAtIndex:itemIndex]; yourArraycount 上显示错误..