Mac Os X Sqlite Library

In order to install sqlite3 on Mac using brew, you can simply run: $ brew install sqlite3 Probably, you have already installed sqlite3 because by default it comes installed since Mac OSX 10.4 onwards.In this case, you can update sqlite3 using brew by running the following command: $ brew upgrade sqlite3. SQLite is a in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. The code for SQLite is in.

  1. Mac Os X Sqlite Library For Free
  2. Mac Os Sqlite Viewer
  3. Mac Sqlite Viewer

Bugfix 2012-08-16: Removed a dependency to a custom library.

This is a very simple thread safe SQLite wrapper for Mac OS X and iOS development.

Download

It is a singleton, so it allows for a single database connection. That being said, the library is threadsafe and if multiple threads attempt to do SQL operations, they will be queued up until the currentthread is done (i.e. the database transaction is committed).

It has support for transactions and uses blocks.

Mac

Data skeleton and data locations

Before using the library you have to set the name of your preferred database file and it's location.

After setting the file name, the code below will copy the file data_skeleton.sqlite3 to the file you specified above.Note that this will NOT override the file, UNLESS you specify YES as the ForceReset parameter.

setDatabaseFileInCache

The cache location will store the database in a cache folder and this folder can be deleted at any timewhen the application is not running. It is also not backed up.

Use this for databases that store temporary data that you will not need to store between application launches.

setDatabaseFileInDocuments

Mac Os X Sqlite Library For Free

The documents location will store the database in the user's Documents folder. This folder is persistentand will not be deleted unless the user uninstalls the iOS application or manually deletes the file on Mac.

Mac Os Sqlite Viewer

Use this for databases that store persistent data such as user profiles or game highscores.

Mac Sqlite Viewer

Logging

Log messages are output based on your setting of DEBUG_LOG preprocessor macro.

  • DEBUG_LOG=1 - outputs basic messages and errors
  • DEBUG_LOG=2 - outputs every query and lots of other data

Typical usage scenario

The performQuery: method returns different integer values depending on the query:

  • INSERT returns the id of the last inserted row
  • UPDATE returns the number of affected rows
  • SELECT returns number of found rows

Using transactions

By default every query is performed in it's own transaction, however if you are performing lotsof insert queries using transactions increases performance quite a bit.

Threads

Calling begin initiates a thread lock, and the lock is only released only when commit is called.

So once an SQL transaction is started, all other database access will be put on hold until the threadthat begun the transaction calls commit.

Note: A single query outside a transaction calls begin and commit, and thus follows the above principle.

Rollback

There is currently no rollback support.

sqlite3_column_nsstring

For NSString support I wrote a custom function sqlite3_column_nsstring, it behaves like other sqlite3 functions but returns an NSString instead of a C string.