-
Notifications
You must be signed in to change notification settings - Fork 38
Setting up a PLIST Configuration File
Configuring an SQLite database connection is easy; it is done via a property list (i.e. PLIST) configuration file. The PLIST configuration file will define the database type, the database (itself), and any privilege restrictions.
A PLIST configuration file uses the .plist extension. By default, all database configurations are stored in db.plist. You may choose to store your configurations in a PLIST file with another name but you will have to override the pre-processing instruction ZIMDbPropertyList in your project-name_Prefix.pch. To do so, just add the following line of code to your project-name_Prefix.pch:
#define ZIMDbPropertyList @"custom.plist"
Below is a sample PLIST configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>test</key>
<dict>
<key>database</key>
<string>testdb.sqlite</string>
<key>readonly</key>
<false/>
<key>type</key>
<string>SQLite</string>
</dict>
</dict>
</plist>
Every PLIST configuration file must declared the type and database key/value pairs. These are required key/value pairs. Since this library right now only works with SQLite databases, the type key/value pair will always be declared as so. The database key/value pair, however, will be application specific; therefore, you will need to modified the value to reference your specific SQLite database.
The above settings will grant privileges to use all SQL commands.
To limit such privileges, you can add another key/value pair to the PLIST configuration file. The following PLIST configuration file restricts privileges to just CRUD statements:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>live</key>
<dict>
<key>database</key>
<string>livedb.sqlite</string>
<key>privileges</key>
<array>
<string>SELECT</string>
<string>INSERT</string>
<string>UPDATE</string>
<string>DELETE</string>
</array>
<key>readonly</key>
<false/>
<key>type</key>
<string>SQLite</string>
</dict>
</dict>
</plist>
Here is a list of permissible privileges:
- ALTER
- ANALYZE
- ATTACH
- BEGIN
- COMMIT
- CREATE
- DELETE
- DETACH
- DROP
- EXPLAIN
- INSERT
- PRAGMA
- REINDEX
- ROLLBACK
- SELECT
- UPDATE
- VACUUM
You can combine the above two examples into one PLIST file like so:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>live</key>
<dict>
<key>database</key>
<string>livedb.sqlite</string>
<key>privileges</key>
<array>
<string>SELECT</string>
<string>INSERT</string>
<string>UPDATE</string>
<string>DELETE</string>
</array>
<key>readonly</key>
<false/>
<key>type</key>
<string>SQLite</string>
</dict>
<key>test</key>
<dict>
<key>database</key>
<string>testdb.sqlite</string>
<key>type</key>
<string>SQLite</string>
</dict>
</dict>
</plist>
As you may have noticed, you can also have just read-only databases by changing the readonly key's value to YES (i.e. ). This will basically limit the your usage of a database to only querying. Therefore, you will not be able to use any command that utilizes the execute method.