fmdb

FMDatabaseQueue Error: database is locked

北城以北 提交于 2019-12-05 21:42:23
I have a method that runs in a background thread, and so (as I understand it) I need to use FMDatabaseQueue to safely and reliably access my SQLite database. I'm doing a query to check for the presence of a record, after which I immediately UPDATE or INSERT depending on the result. The first query runs fine and I get a count, but then the query that follows doesn't run. Here's the error I get: Unknown error calling sqlite3_step (5: database is locked) eu Here is my code: //Establish database queue NSString *path = [[PPHelpers documentsPath] stringByAppendingPathComponent:@"PilotPro2.db"];

FMDB and encryption

纵然是瞬间 提交于 2019-12-05 15:48:51
I'm using FMDB to work with sqlite and I'd prefer to avoid a dependency on SQLCipher. How can I simply leverage the DataProtection capability built into iOS? Is this possible - the only requirement is to protect the data in the event of the phone being stolen. If the phone is unlocked with a PIN, it's fine that the user could access the DB - it's their data. Look for the line where you do databaseWithPath: (or initWithPath: ), then add: FMDatabase *db = [FMDatabase databaseWithPath:path]; NSDictionary *attributes = @{NSFileProtectionKey: NSFileProtectionCompleteUnlessOpen}; NSError *error;

How do I make FMDB's database a singleton

与世无争的帅哥 提交于 2019-12-05 15:48:32
I have been using SQLite for awhile now, and have decided to go to FMDB. I need to make it a singleton. Here's my code below; what do I have to change to have FMDB access the singleton d/b? #pragma mark Singleton Methods + (SQLiteDB *) sharedSQLiteDB { if(!sharedSQLiteDB) { sharedSQLiteDB = [[SQLiteDB alloc] init]; [sharedSQLiteDB openCreateDB]; // check to see if d/b exists } return sharedSQLiteDB; } and this is the code I use to initialize the d/b using FMDB: //----------------------- checkIfDatabaseExists -----------------| - (void) openCreateDB { searchPaths =

FMDatabase locked, best practice for usage within class

若如初见. 提交于 2019-12-05 07:54:10
问题 I have a sync method for an app I'm building storing data in SQLite locally, using the FMDatabase wrapper. When I put all the queries in one class everything works fine. However to maintain complexity I added some data controller classes for parts of the sync, but when I do so FMDatabase gives 'database locked' errors, both when I add a new connection in a data class and when I send along the initial database connection as a parameter. Now I was thinking to add the database connection in a

How to delete a row in a sqlite database table?

人走茶凉 提交于 2019-12-05 05:08:11
I am using fmdb for managing my database. I could not find any example for deleting a row from a table in fmdb. I tried NSString *sqlStat=@"DELETE from tableName WHERE id=3"; FMResultSet *rs = [database executeQuery:sqlStat]; but its not working because when I checked the total number of entries in table, I am getting the same number as before executing the above statement. So, what is a proper way to delete a row from a table using fmdb? FMDB can be a little finicky if you dont pass in the object as an NSNumber. This is the supported, and safe way of formatting queries. [db executeUpdate:@

How FMDB makes sqlite more simpler iOS?

此生再无相见时 提交于 2019-12-04 14:51:26
问题 i want to use fmdb in my iPhone application. What are the differences in using sqlite with fmdb without fmdb? i need to be able to write queries. how the fmdb is easier/effecient to use than single sqlite? if there is any source code or guide to it please post its link 回答1: FMDB is a wrapper on top of SQLite's C API with an API more in Objective-C style. Which API style is "easier" is more up to you, it would depend greatly on your programming background and personal preference. There's a

FMDatabaseQueue How To Return A Value

半腔热情 提交于 2019-12-04 11:11:47
问题 I'm using FMDatabaseQueue in my iOS application. I'm stuck in understanding how to return the value upon creating the queue. Appreciate your help!! FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:aPath]; [queue inDatabase:^(FMDatabase *db) { [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:1]]; [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:2]]; [db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber

FMDatabase locked, best practice for usage within class

浪尽此生 提交于 2019-12-03 21:59:24
I have a sync method for an app I'm building storing data in SQLite locally, using the FMDatabase wrapper. When I put all the queries in one class everything works fine. However to maintain complexity I added some data controller classes for parts of the sync, but when I do so FMDatabase gives 'database locked' errors, both when I add a new connection in a data class and when I send along the initial database connection as a parameter. Now I was thinking to add the database connection in a songleton, and was wondering if that is good practice and how I wrap FMDatabase in a singleton class. Any

iOS

孤者浪人 提交于 2019-12-03 19:34:45
初识FMDB iOS中原生的 SQLite API在进行数据存储的时候,需要使用C语言中的函数,操作比较麻烦。于是,就出现了一系列将SQLite API进行封装的库,例如 FMDB 、 PlausibleDatabase 、 sqlitepersistentobjects 等。 FMDB是一款简洁、易用的封装库。因此,在这里推荐使用第三方框架FMDB,它是对libsqlite3框架的封装,用起来的步骤与SQLite使用类似,并且它对于多线程的并发操作进行了处理,所以是线程安全的。 FMDB PK Sqlite 优点: 对多线程的并发操作进行处理,所以是线程安全的; 以OC的方式封装了 SQLite 的C语言API,使用起来更加的方便; FMDB是轻量级的框架,使用灵活。 缺点: 因为它是OC的语言封装的,只能在ios开发的时候使用,所以在实现跨平台操作的时候存在局限性。 FMDB框架中重要的框架类 FMDatabase FMDatabase 对象就代表一个单独的 SQLite 数据库,用来执行 SQL 语句 FMResultSet 使用 FMDatabase 执行查询后的结果集 FMDatabaseQueue 用于在多线程中执行多个查询或更新,它是线程安全的 FMDB使用步骤 下载FMDB文件 GitHub ,并将FMDB文件夹添加到项目中(也可使用CocoaPods导入) 导入