将数组存储到 SQLite 数据库中
我在 SQLite 数据库中有 2 列类型为 VARCHAR(1000) 和类型为 TEXT 的列。我的要求是将数组中的值存储到数据库中。我尝试使用 for 循环将数组中的值存储到字符串中,但是一旦控件退出 for 循环,为字符串显示的值只是数组中的最后一个元素...
有什么方法可以使用它直接将数组存入DB?
下面是我的代码:
NSString *tempVal=0, *tempFlag=0;
NSString *temp[256], *Flag[256];
for(int i=0; i<256; i++)
{
NSLog(@"HELLO %d", tempVal);
temp[i] = (NSString*)valMines[i];
Flag[i] = (NSString*)openFlag[i];
NSLog(@"ValMines is %d", temp[i]);
NSLog(@"OpenFlag is %d", Flag[i]);
tempVal = temp[i];
tempFlag == Flag[i];
NSLog(@"ValMines is %d %d", temp[i], tempVal);
}
NSLog(@"Inside Save Data func");
NSLog(@"ValMines is %d", tempVal);
NSLog(@"OpenFlag is %d", tempFlag);
可以追加工作吗?如何?
I have 2 columns of type VARCHAR(1000) and type TEXT in a SQLite db. My requirement is to store the values in an array into the db. I tried storing the values in the array into a string using the for loop but once the control comes out of the for loop the values displayed for the string is only the last element in the array...
Is there any way using which I can directly store the array into the DB??
Below is my code:
NSString *tempVal=0, *tempFlag=0;
NSString *temp[256], *Flag[256];
for(int i=0; i<256; i++)
{
NSLog(@"HELLO %d", tempVal);
temp[i] = (NSString*)valMines[i];
Flag[i] = (NSString*)openFlag[i];
NSLog(@"ValMines is %d", temp[i]);
NSLog(@"OpenFlag is %d", Flag[i]);
tempVal = temp[i];
tempFlag == Flag[i];
NSLog(@"ValMines is %d %d", temp[i], tempVal);
}
NSLog(@"Inside Save Data func");
NSLog(@"ValMines is %d", tempVal);
NSLog(@"OpenFlag is %d", tempFlag);
Would append work on it? How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据另一篇文章,SQLite 不直接支持数组。它只处理整数、文本和浮点数。
如何在Sqlite3中将数组存储在一列中?
According to this other post, SQLite does not support arrays directly. It only does ints, text and floats.
How to store array in one column in Sqlite3?
试试这个:
Try this: