My scenario is like this. for a security reason, I decide I put app data to the bundle and user data to the document directory. the problem is how to join the tables from the different databases? if not possible do I have to create a table to the database in document directory?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
Sqlite3 allows it to attach foreign database to the current connection. Imagine, you have two databases, each one holds an own connection via FMDatabase (for multithreading purposes you should use FMDatabaseQueue instead). Now, attach the other database to the connection of the first database. Then you can join from database 1 to a table in database 2. Important: all this happens via sqlite per sql statement and has nothing to do with FMDB.
I'll provide example-code at github: https://github.com/itinance/MultiDatabaseJoin
For simplicity i placed the database-files under /tmp-directory. With iOS-Simulator this is working well, i haven't tested this code in a really device, where you would place the database in the document folder or something similar (but thats not the point yet).
The important thing here is the following query in sqlite3:
At the database connection db1 we attach the database-file from the second database.
After this attaching you can join in Database-Connection 1 to a table in database connection 2 in a query like this one:
Here is the whole code i tried: