SQLite是一个开源的嵌入式关系数据库,它在2000年由D. Richard Hipp发布,它的减少应用程序管理数据的开销,SQLite可移植性好,很容易使用,很小,高效而且可靠。 
SQLite嵌入到使用它的应用程序中,它们共用相同的进程空间,而不是单独的一个进程。从外部看,它并不像一个RDBMS,但在进程内部,它却是完整的,自包含的数据库引擎。 
嵌入式数据库的一大好处就是在你的程序内部不需要网络配置,也不需要管理。因为客户端和服务器在同一进程空间运行。SQLite 的数据库权限只依赖于文件系统,没有用户帐户的概念。SQLite 有数据库级锁定,没有网络服务器。它需要的内存,其它开销很小,适合用于嵌入式设备。

测试:

- (void)createEditableCopyOfDatabaseIfNeeded {

    // First, test for existence.

    NSString *dbFileName = @"TruthorDare.sqlite";

    BOOL success=NO;

    NSFileManager *fileManager = [NSFileManagerdefaultManager];

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

    NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:dbFileName];

    success = [fileManager fileExistsAtPath:writableDBPath];

    if (success){

        NSLog(@"数据库存在");

        return;}

    // The writable database does not exist, so copy the default to the appropriate location.

    NSString *defaultDBPath = [[[NSBundlemainBundle] resourcePath] stringByAppendingPathComponent:dbFileName];

    success = [fileManager copyItemAtPath:defaultDBPath toPath:writableDBPath error:&error];

    if (!success) {

        NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);

    }else {

        NSLog(@"createEditableCopyOfDatabaseIfNeeded 初始化成功");

    }

}

方法:按照http://blog.csdn.net/shang_515/article/details/7537889的方式,没有书写等低级错误,但仍不显示数据,此时,杀掉模拟器或真机的程序,重新添加(拷贝)数据库文件到程序,Clean、Build、Run一下。一般就能解决问题。

相关文章:

  • 2021-06-20
  • 2021-08-11
  • 2021-06-30
  • 2021-11-18
  • 2021-09-30
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案