How-To Create A Multi Database IOS App With SQLite

This Person sub class will handle the details the databases along with the UI. It is a simple data type subclassed in the NSObject class. Create a the NSObject subclass, Person (.h and .m). This class will handle the database operations. It includes a solution to read the data on the two tables, SelectRecords and another to insert records: InsertRecords. In the implementation file firstly you will need to import the Person header file that will create the accessor fileMgr and homeDir properties.
The method declares a char constant, sql, with the SQL statement. Notice the syntax, it's just like any other multi table or multi database join, without worrying about join statement. The other important part of information is the naming scheme in the first database, it usually is “main” and another database that's attached is known by the alias name which was used in the attach statement. The rest with the code is boilerplate sqlite3 commands that follows the appropriate lifecycle.
If the prepare statement is parsed correctly, then you can prepare the input variables, execute the the answer to move to the 1st row. Finally call the finalize command to clear out the sql statement and close the database. Using SQLite: Small. Fast. Reliable. Choose Any Three. Buy Now The InsertRecords uses the Person parameter to insert records in each with the databases.
This way is the main center of operations. It starts by obtaining the path to both databases after which moving those to the Documents directory in order that the app can write to them, otherwise, should they remain in the Resource path, they'll be read-only. Once the databases are in the right directory, the technique attempts to open the primary, or main database. The next little business is to determine which operation to carry out, “Insert” or “Select” in accordance with the “operationName” parameter that may be received in the QueryViewController which we shall look at next.
Depending around the type of template you used or will to generate the sample app if you plan on testing the code and concepts on this tutorial, the ViewController could be created. I chose to utilize an Empty Solution then create the ViewController and Storyboard separately.
The QueryViewController which I created as being a sub class in the UIViewController class will handle the interaction with all the UI. Again look at the included links to make the ViewController. For the Storyboard, I make a new one through the Storyboard template and add three fields with the name, gender and city.
I also added two buttons: Save and Query to do the insert and select functions. Since I made the Storyboard through the template, I needed to include it to your “MultiDB-Info.plist” file in the Supporting Files folder. In the opened file, right-click and select “Add Row”, then choose “Main storyboard file base name” through the list of attributes.
For the significance I entered multiDb, which is the name with the Storyboard file. You don’t should enter the file extension. In the open Storyboard, I added a reference to your custom ViewController class that I created. The IBActions and IBOutlets are created by creating connections, see tutorials above on the header file. In the SaveAction method I demonstrated three other ways to assign a value for the “me” object.
0 Response to "How-To Create A Multi Database IOS App With SQLite"
Post a Comment