fmdb

display data from sqlite to label using FMDB

爷,独闯天下 提交于 2019-12-24 14:36:30
问题 How to display data from SQLite to label using FMDB like this: I would like to display whatever the output is in this format for the user to see. No Interaction. Only display for the select query. 回答1: If you want to add UILabel objects, just iterate through your result set, adding labels to your view. Something like: NSInteger rowNum = 0; NSArray *columnWidths = @[@(50), @(120), @(75), @(75)]; CGFloat rowHeight = 24.0; FMResultSet *rs = [db executeQuery:sql]; while ([rs next]) { CGFloat x =

FMDB: NULL Values Are Retrieved as Empty Strings

╄→尐↘猪︶ㄣ 提交于 2019-12-24 12:12:16
问题 I'm retrieving a customer record with FMDB and Swift using the (simplified) function below. When the optional value in the title column is NULL the title member of the returned customer object is an empty string rather than nil , which is misleading. Can this be re-written such that NULL values are retrieved as nil ? -- Ideally without testing for empty strings and setting nil explicitly (also wrong if the value is in fact an empty string)? func getCustomerById(id: NSUUID) -> Customer? { let

How to remove all data from table using FMDB

牧云@^-^@ 提交于 2019-12-24 12:06:18
问题 I want to delete all data from table in my database. I am using FMDB.And i have used this code but it will not delete data from my table. -(BOOL) deleteAll { FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]]; [db open]; BOOL success = [db executeUpdate:@"TRUNCATE TABLE customers"]; [db close]; return success; return YES; } 回答1: Try to use this code. BOOL success = [db executeUpdate:@"DELETE FROM customers"]; As long as i know Sqlite does not support TRUNCATE query. 回答2:

How To Create or Stabiles relationship between two tables in FMDB?

落爺英雄遲暮 提交于 2019-12-23 16:08:06
问题 I'm new with iOS Development and i'm also new with SQLITE database. I used FMDB as a wrapper in my project and i have two tables 1) ParticepentsTable and 2) ExerciseTable . ParticepentsTable contains 4-Rows like Id, Name, Gender and Exercise_Id and the ExerciseTable contains 2-Rows i.e. Id and exercise_Name . My questions are as follow:- 1) I want to make a Foreign-key Relation between Table-1 & 2 using FMDB, so that i can store the exercise according to Participants choice. 2) Or any other

SQLite. Can't add more than 1000 rows

非 Y 不嫁゛ 提交于 2019-12-23 12:32:56
问题 I'm trying to add to my SQLite database (with fmdb) 10k rows but writing is stopped on 1000 row. And I have no any errors or warnings. My code: NSString *queryString = [NSString stringWithFormat:@"insert into histories (storyid, text, date, storyurl) values (%li, ?, ?, ?)",history.storyIndex]; if ([self.db open]) { if([self.db executeUpdate:queryString, history.storyText, history.storyDate, history.storyUrl]) { NSLog(@"history added"); } } Any suggestions? 回答1: Can you try the following code

FMDB ios no such table

假如想象 提交于 2019-12-23 07:26:23
问题 I have a problem with a sqlite project that i'm doing, I'm using FMDB, I follow a simple example, but doesn´t work. And I can't find the error. I did my database schema from the terminal, I put some data on it. I'm very new to ios dev, so I don't know exactly if I did the steps ok. This is what I did: 1 - I made my Database schema and add some fields. 2 - I copied the database.db into my project folder in xcode. 3 - I add the FMDB files. 4 - I add the sqlite3.dylib 5 - I put this code: -

Copy Database after starting swift

喜你入骨 提交于 2019-12-23 01:43:27
问题 this is my first DB Project, so i am facing some issues. Hopefully you can help me! I am using FMDB to have access to an existing DB. When i try to execute a simpel Query like "Select * From films" it returns stuff like "no such table". I looked into the folder of the IPhone Simulator and found the DB, but it was empty. My next Step was, to include this Method: func copyDatabaseIfNeeded() { // Move database file from bundle to documents folder let fileManager = FileManager.default let

memory leak (?) after sqlite+fmdb vacuum command

岁酱吖の 提交于 2019-12-22 11:34:55
问题 I'm using sqlite in my app via the FMDB wrapper. Memory usage in my app sits at 2.25 MB before a call to VACUUM: [myFmdb executeUpdate: @"VACUUM;" ]; Afterwords its at 5.8 MB, and I can't seem to reclaim the memory. Post-vacuum, the Instruments/Allocations tool shows tons of sqlite3MemMalloc calls with live bytes, each allocating 1.5 K. Short of closing the database and reopening it (an option), how can I clean this up? Edit : closing and reopening the database connection does clear up the

FMDatabaseQueue Error: database is locked

五迷三道 提交于 2019-12-22 09:40:15
问题 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

swift 3.0 How can I access `AnyHashable` types in `Any` in Swift 3?

不打扰是莪最后的温柔 提交于 2019-12-22 06:33:13
问题 I'm using sqlite file to get the diaryEntriesTeacher from the authorId. it generates the following object of authorId when I print the variable authorId is nil Code :- func applySelectQuery() { checkDataBaseFile() objFMDB = FMDatabase(path: fullPathOfDB) objFMDB.open() objFMDB.beginTransaction() do { let results = try objFMDB.executeQuery("select * from diaryEntriesTeacher", values: nil) while results.next() { let totalCount = results.resultDictionary let authorId = totalCount?["authorId"]!