zoukankan      html  css  js  c++  java
  • FMDB中 databaseWithPath 的使用问题

     阅读fmdb的源码文件(下载地址http://github.com/ccgus/fmdb)会发现下面一段注释,里面提到的创建数据库的方法也在很多博客中被引用,但是跑代码的时候发现,文件并不会像文档中所说的那样自动去创建(哪怕是在沙盒目录下的Documents目录下也不能创建成功)

    /** Create a `FMDatabase` object.

     

     An `FMDatabase` is created with a path to a SQLite database file.  This path can be one of these three:

     

     1. A file system path.  The file does not have to exist on disk.  If it does not exist, it is created for you.

     2. An empty string (`@""`).  An empty database is created at a temporary location.  This database is deleted with the `FMDatabase` connection is closed.

     3. `nil`.  An in-memory database is created.  This database will be destroyed with the `FMDatabase` connection is closed.

     

     For example, to create/open a database in your Mac OS X `tmp` folder:

     

        FMDatabase *db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];

     

     Or, in iOS, you might open a database in the app's `Documents` directory:

     

        NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];

        NSString *dbPath   = [docsPath stringByAppendingPathComponent:@"test.db"];

        FMDatabase *db     = [FMDatabase databaseWithPath:dbPath];

     

     (For more information on temporary and in-memory databases, read the sqlite documentation on the subject: [http://www.sqlite.org/inmemorydb.html](http://www.sqlite.org/inmemorydb.html))

     

     @param inPath Path of database file

     

     @return `FMDatabase` object if successful; `nil` if failure.

     

     */

      

    问题出在哪了呢?一般的思路是:如果文件创建不成功,可能是路径不存在,需要手动创建路径;如果路径存在,那么就可能是创建方法出了问题。

     

    第一种情况添加下面的代码

     

        if (![[NSFileManager defaultManager] fileExistsAtPath:dbPath])
        {
            [[NSFileManager defaultManager] createFileAtPath:dbPath contents:nil attributes:nil];
        }

      

     第二种情况

    找了fmdb的所有代码,没有创建文件或判空路径的操作,于是猜想,也许是注释文档写好后,功能没加(个人瞎想,不必在意)。

  • 相关阅读:
    jQuery源码dom ready分析
    jQuery的deferred对象详解(二)
    jQuery的deferred对象详解(一)
    javascript线程解释(setTimeout,setInterval你不知道的事)---转载
    前端工程精粹(二):静态资源管理与模板框架
    拒绝了对对象 'sp_sdidebug'(数据库 'master',所有者 'dbo')的 EXECUTE 权限。
    Page.User.Identity.Name获取不到结果
    水晶报表(web)表格信息展示
    Office导入导出组件权限配置汇总
    CSS hack样式兼容模式收藏
  • 原文地址:https://www.cnblogs.com/PaulpauL/p/6124683.html
Copyright © 2011-2022 走看看