Permalink
Browse files

iphone sqlite wrapper

  • Loading branch information...
1 parent 1e8fac1 commit 399eecfe65c85a961129978a41a356d45e85f7cd @bterm bterm committed Aug 20, 2010
Showing with 484 additions and 12 deletions.
  1. +6 −12 .gitignore
  2. +30 −0 iphone/SQLite/README
  3. +67 −0 iphone/SQLite/Sqlite.h
  4. +381 −0 iphone/SQLite/Sqlite.m
View
@@ -1,29 +1,23 @@
-##
# general
-##
*.swp
*~
-##
-# c
-##
+# c
*.o
-##
# java
-##
*.class
-##
# python
-##
*.pyc
-##
# system files
-##
-.DS_Store?
+.DS_Store
Icon?
._*
Thumbs.db
+# old skool
+.svn
+.cvs
+
View
@@ -0,0 +1,30 @@
+SQLite wrapper to make interaction with sqlite databases on the iphone easier.
+
+Based on sqlite wrapper by Matteo Bertozzi.
+
+Requires:
+ import libsqlite3.0.dylib
+ Add > Existing Frameworks... change dropdown to dylibs and select 'libsqlite3.0.dylib'
+
+Usage:
+ Sqlite *sqlite = [[Sqlite alloc] init];
+
+ if (![sqlite open:@"sample.db"])
+ return;
+
+ [sqlite executeNonQuery:@"DROP TABLE test"];
+ [sqlite executeNonQuery:@"CREATE TABLE test (key TEXT NOT NULL, num INTEGER, value TEXT);"];
+ [sqlite executeNonQuery:@"INSERT INTO test VALUES (?, ?, ?);", [Sqlite createUuid], [NSNumber numberWithInt:5], @"example"];
+ [sqlite executeNonQuery:@"INSERT INTO test VALUES (?, ?, ?);", [Sqlite createUuid], [NSNumber numberWithInt:3], @"values"];
+
+ NSArray *results = [sqlite executeQuery:@"SELECT * FROM test;"];
+
+ for (NSDictionary *dictionary in results) {
+ for (NSString *key in [dictionary keyEnumerator])
+ NSLog(@"%@ %@\n", key, [dictionary objectForKey:key]]);
+ }
+ }
+
+ [results release];
+ [sqlite release];
+
View
@@ -0,0 +1,67 @@
+/**
+ * SQLite wrapper
+ * Based on sqlite wrapper by Matteo Bertozzi.
+ *
+ * Requires:
+ * import libsqlite3.0.dylib
+ * Add > Existing Frameworks... change dropdown to dylibs and select 'libsqlite3.0.dylib'
+ *
+ * Usage:
+ * Sqlite *sqlite = [[Sqlite alloc] init];
+ *
+ * if (![sqlite open:@"sample.db"])
+ * return;
+ *
+ * [sqlite executeNonQuery:@"DROP TABLE test"];
+ * [sqlite executeNonQuery:@"CREATE TABLE test (key TEXT NOT NULL, num INTEGER, value TEXT);"];
+ * [sqlite executeNonQuery:@"INSERT INTO test VALUES (?, ?, ?);", [Sqlite createUuid], [NSNumber numberWithInt:5], @"example"];
+ * [sqlite executeNonQuery:@"INSERT INTO test VALUES (?, ?, ?);", [Sqlite createUuid], [NSNumber numberWithInt:3], @"values"];
+ *
+ * NSArray *results = [sqlite executeQuery:@"SELECT * FROM test;"];
+ *
+ * for (NSDictionary *dictionary in results) {
+ * for (NSString *key in [dictionary keyEnumerator])
+ * NSLog(@"%@ %@\n", key, [dictionary objectForKey:key]]);
+ * }
+ * }
+ *
+ * [results release];
+ * [sqlite release];
+ *
+ **/
+#import <Foundation/Foundation.h>
+#import <sqlite3.h>
+
+@interface Sqlite : NSObject {
+ NSInteger busyRetryTimeout;
+ NSString *filePath;
+ sqlite3 *_db;
+}
+
+@property (readwrite) NSInteger busyRetryTimeout;
+@property (readonly) NSString *filePath;
+
++ (NSString *)createUuid;
++ (NSString *)version;
+
+- (id)initWithFile:(NSString *)filePath;
+
+- (BOOL)open:(NSString *)filePath;
+- (void)close;
+
+- (NSInteger)errorCode;
+- (NSString *)errorMessage;
+
+- (NSArray *)executeQuery:(NSString *)sql, ...;
+- (NSArray *)executeQuery:(NSString *)sql arguments:(NSArray *)args;
+
+- (BOOL)executeNonQuery:(NSString *)sql, ...;
+- (BOOL)executeNonQuery:(NSString *)sql arguments:(NSArray *)args;
+
+- (BOOL)commit;
+- (BOOL)rollback;
+- (BOOL)beginTransaction;
+- (BOOL)beginDeferredTransaction;
+
+@end
+
Oops, something went wrong.

0 comments on commit 399eecf

Please sign in to comment.