sqlite的iPhone数据插入问题 [英] Sqlite iPhone data insertion problem

查看:120
本文介绍了sqlite的iPhone数据插入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有这基本上试图插入一些数据从一个REST调用返回的功能。

Hi I have a function which basically tries to insert some data returned from a REST call.

- (void)syncLocalDatabase{
 NSString *file = [[NSBundle mainBundle] pathForResource:@"pickuplines" ofType:@"db"];
 NSMutableString *query = [[NSMutableString alloc] initWithFormat:@""];
 sqlite3 *database = NULL;
 char *errorMsg = NULL;
 if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
  for(PickUpLine *pickupline in pickUpLines){
   [query appendFormat:@"INSERT INTO pickuplines VALUES(%d,%d,%d,'%@','YES')", pickupline.line_id, pickupline.thumbsUps, pickupline.thumbsDowns, [pickupline.line stringByReplacingOccurrencesOfString:@"'" withString:@"`"]];
   NSLog(query);
   int result = sqlite3_exec(database, [query UTF8String], NULL, NULL, &errorMsg);
   if (result!=SQLITE_OK) {
    printf("\n%s",errorMsg);
    sqlite3_free(errorMsg);
   }
   //sqlite3_step([query UTF8String]);
   [query setString:@""];
  }//end for
 }//end if
 [query release];
 sqlite3_close(database); }

一切似乎都在日志中陈述精细的查询字符串也不错,但数据不被插入。凡作为此功能select语句的对应效果很好。
这里是计数器部分

everything seems fine query string in log statement is also fine but the data does not gets inserted. Where as a counterpart of this function for select statement works well. Here is the counter part

    - (void)loadLinesFromDatabase{

 NSString *file = [[NSBundle mainBundle] pathForResource:@"pickuplines" ofType:@"db"];
 sqlite3 *database = NULL;
 if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) {
  sqlite3_exec(database, "SELECT * FROM pickuplines", MyCallback, linesFromDatabase, NULL);
 }
 sqlite3_close(database);
}

我已经实现的回调和放大器;它工作正常。

I have implemented callback & it works fine.

我有点新sqlite的能有人请指出我在做什么错。
感谢名单

I am a little new to Sqlite can someone please point out what am I doing wrong. Thanx

推荐答案

您可以随时使用Crystalminds'SQLiteDatabase:结果
http://www.crystalminds.nl/?p=1342

You can always use Crystalminds' SQLiteDatabase:
http://www.crystalminds.nl/?p=1342

他们做了一个令人难以置信的易于使用的数据库库,所以没有更多的问题与困难code!我一直在使用了一段时间,我无法想象得到无!做

They made an incredibly easy-to-use Database Library, so no more problems with difficult code! I've been using this for some time now, and i can't imagine having to do without!

这篇关于sqlite的iPhone数据插入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆