Objective-C++ Preprocessor  5.0 with ARC & GC
C++ classes to enhance syntax and manage reference counting.
Instance Methods | Class Methods | Public Attributes | Protected Attributes | List of all members
OODatabase Class Reference

#import <objsql.h>

Inheritance diagram for OODatabase:

Instance Methods

(id) - initPath:
 
(OOStringArray- registerSubclassesOf:
 
(void) - registerTableClassesNamed:
 
(OOArray< OOMetaData * >) - tablesRelatedByNaturalJoinFrom:
 
(OOMetaData *) - tableMetaDataForClass:
 
(BOOL) - exec:
 
(OOString- stringForSql:
 
(id) - copyJoinKeysFrom:to:
 
(OOArray< id >) - select:intoClass:joinFrom:
 
(OOArray< id >) - select:intoClass:
 
(OOArray< id >) - select:
 
(long long) - rowIDForRecord:
 
(long long) - lastInsertRowID
 
(int) - insertArray:
 
(int) - deleteArray:
 
(int) - insert:
 
(int) - delete:
 
(int) - update:
 
(int) - indate:
 
(int) - upsert:
 
(int) - commit
 
(int) - commitTransaction
 
(int) - rollback
 
(OOString- whereClauseFor:values:qualifyNulls: [implementation]
 
(BOOL) - prepareSql:joinFrom:toTable: [implementation]
 

Class Methods

(OODatabase *) + sharedInstance
 
(OODatabase *) + sharedInstanceForPath:
 
(BOOL) + exec:
 
(OOArray< id >) + select:intoClass:joinFrom:
 
(OOArray< id >) + select:intoClass:
 
(OOArray< id >) + select:
 
(int) + insertArray:
 
(int) + deleteArray:
 
(int) + insert:
 
(int) + delete:
 
(int) + update:
 
(int) + indate:
 
(int) + upsert:
 
(int) + commit
 
(int) + rollback
 
(int) + commitTransaction
 

Public Attributes

OOArray< OOValueDictionarytransaction
 
OOArray< OOValueDictionaryresults
 
int errcode
 
int updateCount
 
char * errmsg
 
OOString lastSQL
 

Protected Attributes

OODictionary< OOMetaData * > tableMetaDataByClassName
 
OOReference< OOAdaptor * > adaptor
 

Detailed Description

Simple persistence class for Objective-C objects using a "sqlite" database. Instances a class are automatically bound to a table with the class name for insert, update and delete.

A table with the same name as the class is created automatically when you perform any operation on instances of that class with columns corresponding to the instance variables of the class except those which begin with the character "_". If an instance variable starts with an upper case letter it will be indexed.

To update a record, fetch it and call the update: method passing it in as the argument to save it's preious values. You can then modify it and call commit to update it's record. Delete operations on objects also accumulate and need to be commited to take effect.

Definition at line 181 of file objsql.h.

Method Documentation

+ (int) commit

Commit all pending inserts, updates and deletes to the database. Use commitTransaction to perform this inside a database transaction.

Definition at line 248 of file objsql.mm.

- (int) commit
+ (int) commitTransaction

Commit all pending inserts, updates, deletes to the database inside a transaction.

Definition at line 250 of file objsql.mm.

- (int) commitTransaction
- (id) copyJoinKeysFrom: (id)  parent
to: (id)  newChild 

Used to initialise new child records automatically from parent in relation.

Definition at line 344 of file objsql.mm.

+ (int) delete: (id)  record

Use the values of the record instance at the time this method is called in a where clause to delete from the database when commit is called. Returns the total number of outstanding inserts/updates/deletes.

Definition at line 242 of file objsql.mm.

- (int) delete: (id)  object
+ (int) deleteArray: (const OOArray<id> &)  objects

Delete an array of record objects from the database. This needs to be commited to take effect.

Definition at line 239 of file objsql.mm.

- (int) deleteArray: (const OOArray< id > &)  objects
+ (BOOL) exec: (cOOString fmt
,   ... 

Send any SQL to the database. Sql is a format string so escape any '' characters using '%'. Any results returned are placed as an array of dictionary values in the database->results.

Definition at line 221 of file objsql.mm.

- (BOOL) exec: (cOOString sql
,   ... 
+ (int) indate: (id)  record

Inserts a record into the database the deletes any previous record with the same key. This ensures the record's rowid changes if this is used by child records.

Definition at line 245 of file objsql.mm.

- (int) indate: (id)  object
- (id) initPath: (cOOString path

Designated initialiser for OODatabase instances. Generally only the shared instance is used and the OODatabase class object is messaged instead.

Definition at line 257 of file objsql.mm.

+ (int) insert: (id)  record

Insert the values of the record class instance at the time this method was called into the db. (must be commited to take effect). Returns the total number of outstanding inserts/updates/deletes.

Definition at line 241 of file objsql.mm.

- (int) insert: (id)  object
+ (int) insertArray: (const OOArray<id> &)  objects

Insert an array of record objects into the database. This needs to be commited to take effect.

Definition at line 238 of file objsql.mm.

- (int) insertArray: (const OOArray< id > &)  objects
- (long long) lastInsertRowID

Returns sqlite3 row identifier for last inserted record.

Definition at line 472 of file objsql.mm.

- (BOOL) prepareSql: (OOString &)  sql
joinFrom: (id)  parent
toTable: (OOMetaData *)  metaData 
implementation

Prepare the sql passed in adding a where clause with bindings for a join to values taken from the parent record.

Definition at line 379 of file objsql.mm.

- (OOStringArray) registerSubclassesOf: (Class)  recordSuperClass

Automatically register all classes which are subclasses of a record abstract superclass (e.g. OORecord).

Definition at line 267 of file objsql.mm.

- (void) registerTableClassesNamed: (cOOStringArray classes

Register a list of classes before using them so OODatabase can determine the relationships between them.

Definition at line 305 of file objsql.mm.

+ (int) rollback

Rollback any outstanding inserts, updates, or deletes. Please note updated values are also rolled back inside the actual record in the application as well.

Definition at line 249 of file objsql.mm.

- (int) rollback
- (long long) rowIDForRecord: (id)  record

Returns sqlite3 row identifier for a record instance.

Definition at line 461 of file objsql.mm.

+ (OOArray< id >) select: (cOOString select

Definition at line 234 of file objsql.mm.

- (OOArray<id>) select: (cOOString select
+ (OOArray< id >) select: (cOOString select
intoClass: (Class)  recordClass 

Definition at line 231 of file objsql.mm.

- (OOArray<id>) select: (cOOString select
intoClass: (Class)  recordClass 
+ (OOArray< id >) select: (cOOString select
intoClass: (Class)  recordClass
joinFrom: (id)  parent 

Perform a select from a table on the database using either the sql specified orselect all columns from the table associated with the record class passed in. If a parent is passed in make a natural join from that record.

Definition at line 228 of file objsql.mm.

- (OOArray<id>) select: (cOOString select
intoClass: (Class)  recordClass
joinFrom: (id)  parent 
+ (OODatabase *) sharedInstance

By default database file is "objsql.db" in the user/application's "Documents" directory and a single shared OODatabase instance used for all db operations.

Definition at line 203 of file objsql.mm.

+ (OODatabase *) sharedInstanceForPath: (cOOString path

Shared instance can be switched between any file paths.

Definition at line 213 of file objsql.mm.

- (OOString) stringForSql: (cOOString fmt
,   ... 

Return a single value from row 1, column one from sql sent to the database as a string.

Definition at line 328 of file objsql.mm.

- (OOMetaData *) tableMetaDataForClass: (Class)  recordClass

Find/create an instance of the OOMetaData class which describes a record class and its associated table. If the table does not exist it will be created along with indexes for columns/ivars which have upper case names for use in joins. Details of the tables parameters can be controlled by using methods in the OOTableCustomisation protool. If it does not exist a meta table class which prepresents OOMetaData records themselves is also created from which the list of all registered tables can be selected.

Definition at line 690 of file objsql.mm.

- (OOArray< OOMetaData * >) tablesRelatedByNaturalJoinFrom: (id)  record

Determine a list of the tables which have a natural join to the record passed in. If the record is a specific instance of from a table this should determine if there are any record which exist using the join.

Definition at line 410 of file objsql.mm.

+ (int) update: (id)  record

Call this method if you intend to make changes to the record object and save them to the database. This takes a snapshot of the previous values to use as a key for the update operation when "commit" is called. Returns the total number of outstanding inserts/updates/deletes.

Definition at line 243 of file objsql.mm.

- (int) update: (id)  object
+ (int) upsert: (id)  record

Inserts a record into the database unless another record with the same key column values exists in which case it will do an update of the previous record (preserving the ROWID.)

Definition at line 246 of file objsql.mm.

- (int) upsert: (id)  object
- (OOString) whereClauseFor: (cOOStringArray columns
values: (cOOValueDictionary values
qualifyNulls: (BOOL)  qualifyNulls 
implementation

Build a where clause for the columns specified.

Definition at line 357 of file objsql.mm.

Member Data Documentation

- (OOReference<OOAdaptor *>) adaptor
protected

Definition at line 183 of file objsql.h.

- (int) errcode

Definition at line 186 of file objsql.h.

- (char*) errmsg

Definition at line 187 of file objsql.h.

- (OOString) lastSQL

Definition at line 188 of file objsql.h.

- (OOArray<OOValueDictionary >) results

Definition at line 185 of file objsql.h.

- (OODictionary<OOMetaData *>) tableMetaDataByClassName
protected

Definition at line 182 of file objsql.h.

- (OOArray<OOValueDictionary >) transaction

Definition at line 185 of file objsql.h.

- (int) updateCount

Definition at line 186 of file objsql.h.


The documentation for this class was generated from the following files: