Licensing ITFoundation under the GNU General Public License version 2.
[ITFoundation.git] / ITSQLite3Database.h
1 /*
2  *      ITFoundation
3  *      ITSQLite3Database.h
4  *
5  *      Copyright (c) 2008 iThink Software
6  *
7  */
8
9 #import <Foundation/Foundation.h>
10 #import <sqlite3.h>
11
12 extern int sqlite3_bind_objc_object(sqlite3_stmt *statement, int index, id object);
13 extern id sqlite3_column_objc_object(sqlite3_stmt *statement, int columnIndex);
14
15 @interface ITSQLite3Database : NSObject {
16         NSString *dbPath;
17         sqlite3 *db;
18         NSRecursiveLock *dbLock;
19 }
20
21 - (id)initWithPath:(NSString *)path;
22
23 - (BOOL)begin;
24 - (BOOL)beginTransaction;
25 - (BOOL)commit;
26 - (BOOL)commitTransaction;
27 - (BOOL)rollback;
28 - (BOOL)rollbackTransaction;
29
30 - (BOOL)executeQuery:(NSString *)query, ...;
31
32 // returns a dictionary with column names as keys, or nil
33 - (NSDictionary *)fetchRow:(NSString *)query, ...;
34
35 // returns an array of dictionaries with column names as keys, or an empty array
36 - (NSArray *)fetchTable:(NSString *)query, ...;
37
38 // returns a single column value, or nil
39 - (id)fetchRowColumn:(NSString *)query, ...;
40
41 // returns an array of single column values, or an empty array
42 - (NSArray *)fetchTableColumn:(NSString *)query, ...;
43
44 @end