zoukankan      html  css  js  c++  java
  • iOS下使用sqlite3

    1、创建数据库

    使用firefox的sqlite manager创建和打开数据库,详细请参考:

    http://www.cnblogs.com/hanjun/archive/2012/10/29/2744573.html

    2、导入数据

    sqlite manager支持csv 和sql两种导入方式。

    导入时默认的编码为utf-8,导入后如果数据乱码,可以尝试使用gb2312编码重新导入。

    3、调用数据库

    很多教程说从Document文件夹读取数据库,读取方法为:

      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

      NSString *documentsDirectory = [paths objectAtIndex:0]; 

      self.databaseFilePath = [documentsDirectory stringByAppendingPathComponent:kDatabaseName]; 

    我尝试把数据库文件(data.sqlite)附加到Supporting FIles下,用下面的方式读取:

      NSString *filePath = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"sqlite"];

    事实上是没有问题的。

    增删改之类的操作和sqlserver没有多大的区别,网上一大把,这里就不重复了。

  • 相关阅读:
    关于值传递和引用传递
    单例设计模式(创建型模式)
    逻辑分页和物理分页
    java基本数据类型
    Keepalived笔记
    lvs,HAProxy,nginx简单笔记
    限流, 熔断,降级笔记
    redis事务之watch
    Redis-Sentinel
    正式入驻博客园
  • 原文地址:https://www.cnblogs.com/JayK/p/4029084.html
Copyright © 2011-2022 走看看