如何将 nsmutablearray 添加到 sqlite 数据库表中?谁能帮我编码?
问问题
3947 次
3 回答
4
您可以使用 :
for (int i = 0; i < [mutArray count]; i++)
{
NSString *string = [mutArray objectAtIndex:i];
// insert query
insert into table_name ('string') values(column_name);
}
于 2012-09-24T11:45:56.497 回答
3
使用循环控件对数组进行排序并插入每个值
例子:
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);
}
}
于 2012-09-24T11:25:37.170 回答