Posted By


iswear_wxp on 04/01/10

Tagged


Statistics


Viewed 239 times
Favorited by 0 user(s)

iPhone中的SQLite应用


/ Published in: iPhone
Save to your folder(s)



Copy this code and paste it in your HTML
  1. SQLite是基于C的API,在iPhone中的运行速度超级快(在苹果网站上也有一个对比,确实应该是速度最快的)。
  2.  
  3. 由于在iPhone3.0上已经支持了Core Data,是苹果一个新的API,并且是基于SQlite的。速度也是非常快吧,信不信由你。所以我们对SQLite仅需要懂一些即可,以下是一些基础信息
  4.  
  5. 打开数据库
  6.  
  7. sqlite3 *database = NULL; //建立一个sqlite数据库变量
  8.  
  9. int sqlite3_open(const char *文件名, sqlite3 **db); //那个文件名需要是cString,
  10. //之后那个db对象使用我们建立的database变量
  11.  
  12. //以下是一个开打的例子:
  13. NSString *fileAddress = [[NSBundle mainBundle] pathForResource:@"预存文件的文件名" ofType:@"db"]; //db是扩展名
  14.  
  15. if(sqlite3_open([fileAddress UTF8String], &database) == SQLITE_OK) //UTF8String方法转换NSString为cString
  16.  
  17. 执行一个SQLite语句:
  18.  
  19. int sqlite3_exec(sqlite3 *db, const char *sql, int (*callback)(void*,int,char**,char**), void *context, char **error);
  20.  
  21. 关闭一个数据库:
  22.  
  23. int sqlite3_close(sqlite3 *db); //这个不用解释了吧
  24.  
  25. 一个响应函数的格式:
  26.  
  27. int callback(void *context, int count, char **values, char **columns);
  28.  
  29. 多了暂时就不打了,试试CoreData吧,很酷的。Apple真的会把人惯坏的

URL: http://c.gzl.name/archives/195

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.