Skip to content
Browse files

New 2.0 release, lots of changes, see CHANGELOG for more

  • Loading branch information...
1 parent 8bbeede commit 93b4de5557eaa00c0af4d577147af5862ce8b4f0 @shnhrrsn shnhrrsn committed with tvgeng Feb 4, 2014
View
20 .gitignore
@@ -0,0 +1,20 @@
+# Xcode
+.DS_Store
+*/build/*
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata
+profile
+*.moved-aside
+DerivedData
+.idea/
+*.hmap
+
+#CocoaPods
+Pods
View
16 CHANGELOG.md
@@ -0,0 +1,16 @@
+# EGODatabase CHANGELOG
+
+## 1.0 (2009)
+
+Initial release.
+
+## 2.0 (Feb 2, 2014)
+
+* Updated code to Modern Objective-C (ARC, auto-synthesize, auto-boxing, etc.)
+* Added new -[EGODatabase execute:] method to easily run low level sqlite calls
+* Added -[EGODatabaseResult firstRow] and -[EGODatabaseResult lastRow]
+* Replaced NSLock usage with dispatch_semaphor, which gives us a free performance boost
+* Removed EGODatabaseRequestDelegate in favor of new completion property on EGODatabaseRequest
+* Renamed all -[EGODatabaseRow xxForColumnIndex:] methdos to -[EGODatabaseRow xxForColumnAtIndex:]
+* Moved internal methods out of public headers
+* Minor other improvements
View
32 EGODatabase.h → Classes/EGODatabase.h
@@ -2,8 +2,7 @@
// EGODatabase.h
// EGODatabase
//
-// Created by Shaun Harrison on 3/6/09.
-// Copyright (c) 2009 enormego
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -25,35 +24,29 @@
//
#import <Foundation/Foundation.h>
+#import <sqlite3.h>
+
#import "EGODatabaseRequest.h"
#import "EGODatabaseResult.h"
#import "EGODatabaseRow.h"
-#import <sqlite3.h>
+@interface EGODatabase : NSObject
-@interface EGODatabase : NSObject {
-@protected
- NSString* databasePath;
- NSLock* executeLock;
-
-@private
- sqlite3* handle;
- BOOL opened;
-}
-
-+ (id)databaseWithPath:(NSString*)aPath;
-- (id)initWithPath:(NSString*)aPath;
++ (instancetype)databaseWithPath:(NSString*)aPath;
+- (instancetype)initWithPath:(NSString*)aPath;
- (BOOL)open;
- (void)close;
+@property(nonatomic,readonly) sqlite3* sqliteHandle;
+
// Execute Updates
- (BOOL)executeUpdateWithParameters:(NSString*)sql, ... NS_REQUIRES_NIL_TERMINATION;
- (BOOL)executeUpdate:(NSString*)sql;
- (BOOL)executeUpdate:(NSString*)sql parameters:(NSArray*)parameters;
-- (sqlite3_int64)last_insert_rowid;
+- (sqlite3_int64)lastInsertRowId;
// Execute Query
- (EGODatabaseResult*)executeQueryWithParameters:(NSString*)sql, ... NS_REQUIRES_NIL_TERMINATION;
@@ -62,24 +55,23 @@
- (EGODatabaseResult*)executeQuery:(NSString*)sql parameters:(NSArray*)parameters;
// Query request operation
-
- (EGODatabaseRequest*)requestWithQueryAndParameters:(NSString*)sql, ... NS_REQUIRES_NIL_TERMINATION;
- (EGODatabaseRequest*)requestWithQuery:(NSString*)sql;
- (EGODatabaseRequest*)requestWithQuery:(NSString*)sql parameters:(NSArray*)parameters;
// Update request operation
-
- (EGODatabaseRequest*)requestWithUpdateAndParameters:(NSString*)sql, ... NS_REQUIRES_NIL_TERMINATION;
- (EGODatabaseRequest*)requestWithUpdate:(NSString*)sql;
- (EGODatabaseRequest*)requestWithUpdate:(NSString*)sql parameters:(NSArray*)parameters;
-// Error methods
+// Execute raw sqlite calls, with thread safe lock protection. Do not nest, as it will cause a deadlock.
+- (void)execute:(void(^)(sqlite3*))block;
+// Error methods
- (NSString*)lastErrorMessage;
- (BOOL)hadError;
- (int)lastErrorCode;
-@property(nonatomic,readonly) sqlite3* sqliteHandle;
@end
View
184 EGODatabase.m → Classes/EGODatabase.m
@@ -2,8 +2,7 @@
// EGODatabase.m
// EGODatabase
//
-// Created by Shaun Harrison on 3/6/09.
-// Copyright (c) 2009 enormego
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -34,53 +33,51 @@
* @see http://code.google.com/p/flycode/soureturnCodee/browse/#svn/trunk/fmdb
*/
-#define VAToArray(firstarg) ({\
-NSMutableArray* valistArray = [NSMutableArray array];\
-id obj = nil;\
-va_list arguments;\
-va_start(arguments, sql);\
-while ((obj = va_arg(arguments, id))) {\
- [valistArray addObject:obj];\
-}\
-va_end(arguments);\
-valistArray;\
-})
-
-
-
#import "EGODatabase.h"
+#import "EGODatabaseResult_Internal.h"
+#import "EGODatabaseRow_Internal.h"
#define EGODatabaseDebugLog 1
#define EGODatabaseLockLog 0
#if EGODatabaseDebugLog
-#define EGODBDebugLog(s,...) NSLog(s, ##__VA_ARGS__)
+ #define EGODBDebugLog(s,...) NSLog(s, ##__VA_ARGS__)
#else
-#define EGODBDebugLog(s,...)
+ #define EGODBDebugLog(s,...)
#endif
#if EGODatabaseLockLog
-#define EGODBLockLog(s,...) NSLog(s, ##__VA_ARGS__)
+ #define EGODBLockLog(s,...) NSLog(s, ##__VA_ARGS__)
#else
-#define EGODBLockLog(s,...)
+ #define EGODBLockLog(s,...)
#endif
-@interface EGODatabase (Private)
-- (BOOL)bindStatement:(sqlite3_stmt*)statement toParameters:(NSArray*)parameters;
-- (void)bindObject:(id)obj toColumn:(int)idx inStatement:(sqlite3_stmt*)pStmt;
-@end
+#define VAToArray(firstarg) ({\
+ NSMutableArray* valistArray = [[NSMutableArray alloc] init]; \
+ id obj = nil;\
+ va_list arguments;\
+ va_start(arguments, sql);\
+ while ((obj = va_arg(arguments, id))) {\
+ [valistArray addObject:obj];\
+ }\
+ va_end(arguments);\
+ valistArray;\
+})
-@implementation EGODatabase
-@synthesize sqliteHandle=handle;
+@implementation EGODatabase {
+ dispatch_semaphore_t _executeLock;
+ NSString* _databasePath;
+ BOOL _opened;
+}
-+ (id)databaseWithPath:(NSString*)aPath {
- return [[[[self class] alloc] initWithPath:aPath] autorelease];
++ (instancetype)databaseWithPath:(NSString*)aPath {
+ return [[[self class] alloc] initWithPath:aPath];
}
-- (id)initWithPath:(NSString*)aPath {
+- (instancetype)initWithPath:(NSString*)aPath {
if((self = [super init])) {
- databasePath = [aPath retain];
- executeLock = [[NSLock alloc] init];
+ _databasePath = [aPath copy];
+ _executeLock = dispatch_semaphore_create(1);
}
return self;
@@ -95,7 +92,7 @@ - (EGODatabaseRequest*)requestWithQuery:(NSString*)sql {
}
- (EGODatabaseRequest*)requestWithQuery:(NSString*)sql parameters:(NSArray*)parameters {
- EGODatabaseRequest* request = [[[EGODatabaseRequest alloc] initWithQuery:sql parameters:parameters] autorelease];
+ EGODatabaseRequest* request = [[EGODatabaseRequest alloc] initWithQuery:sql parameters:parameters];
request.database = self;
request.requestKind = EGODatabaseSelectRequest;
@@ -112,7 +109,7 @@ - (EGODatabaseRequest*)requestWithUpdate:(NSString*)sql {
}
- (EGODatabaseRequest*)requestWithUpdate:(NSString*)sql parameters:(NSArray*)parameters {
- EGODatabaseRequest* request = [[[EGODatabaseRequest alloc] initWithQuery:sql parameters:parameters] autorelease];
+ EGODatabaseRequest* request = [[EGODatabaseRequest alloc] initWithQuery:sql parameters:parameters];
request.database = self;
request.requestKind = EGODatabaseUpdateRequest;
@@ -121,24 +118,43 @@ - (EGODatabaseRequest*)requestWithUpdate:(NSString*)sql parameters:(NSArray*)par
}
- (BOOL)open {
- if(opened) return YES;
+ if(_opened) {
+ return YES;
+ }
- int err = sqlite3_open([databasePath fileSystemRepresentation], &handle);
+ int err = sqlite3_open([_databasePath fileSystemRepresentation], &_sqliteHandle);
if(err != SQLITE_OK) {
EGODBDebugLog(@"[EGODatabase] Error opening DB: %d", err);
return NO;
}
- opened = YES;
- return YES;
+ return (_opened = YES);
}
- (void)close {
- if(!handle) return;
- sqlite3_close(handle);
- handle = 0;
- opened = NO;
+ if(self.sqliteHandle != 0) {
+ sqlite3_close(self.sqliteHandle);
+ _sqliteHandle = 0;
+ _opened = NO;
+ }
+}
+
+- (void)execute:(void(^)(sqlite3*))block {
+ EGODBLockLog(@"[Update] Waiting for Lock (%@): %@ %@", [sql md5], sql, [NSThread isMainThread] ? @"** Alert: Attempting to lock on main thread **" : @"");
+ dispatch_semaphore_wait(_executeLock, 0);
+ EGODBLockLog(@"[Update] Got Lock (%@)", [sql md5]);
+
+ if(![self open]) {
+ EGODBLockLog(@"%@ released lock", [sql md5]);
+ dispatch_semaphore_signal(_executeLock);
+ return;
+ }
+
+ block(_sqliteHandle);
+
+ EGODBLockLog(@"%@ released lock", [sql md5]);
+ dispatch_semaphore_signal(_executeLock);
}
- (BOOL)executeUpdateWithParameters:(NSString*)sql,... {
@@ -151,30 +167,30 @@ - (BOOL)executeUpdate:(NSString*)sql {
- (BOOL)executeUpdate:(NSString*)sql parameters:(NSArray*)parameters {
EGODBLockLog(@"[Update] Waiting for Lock (%@): %@ %@", [sql md5], sql, [NSThread isMainThread] ? @"** Alert: Attempting to lock on main thread **" : @"");
- [executeLock lock];
+ dispatch_semaphore_wait(_executeLock, 0);
EGODBLockLog(@"[Update] Got Lock (%@)", [sql md5]);
if(![self open]) {
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return NO;
}
int returnCode = 0;
sqlite3_stmt* statement = NULL;
- returnCode = sqlite3_prepare(handle, [sql UTF8String], -1, &statement, 0);
+ returnCode = sqlite3_prepare(self.sqliteHandle, [sql UTF8String], -1, &statement, 0);
if (SQLITE_BUSY == returnCode) {
- EGODBLockLog(@"[EGODatabase] Query Failed, Database Busy:\n%@\n\n", sql);
+ EGODBDebugLog(@"[EGODatabase] Query Failed, Database Busy:\n%@\n\n", sql);
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return NO;
} else if (SQLITE_OK != returnCode) {
EGODBDebugLog(@"[EGODatabase] Query Failed, Error: %d \"%@\"\n%@\n\n", [self lastErrorCode], [self lastErrorMessage], sql);
sqlite3_finalize(statement);
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return NO;
}
@@ -183,7 +199,7 @@ - (BOOL)executeUpdate:(NSString*)sql parameters:(NSArray*)parameters {
EGODBDebugLog(@"[EGODatabase] Invalid bind count for number of arguments.");
sqlite3_finalize(statement);
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return NO;
}
@@ -204,15 +220,14 @@ - (BOOL)executeUpdate:(NSString*)sql parameters:(NSArray*)parameters {
returnCode = sqlite3_finalize(statement);
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return (returnCode == SQLITE_OK);
}
-- (sqlite3_int64)last_insert_rowid
-{
- if (handle) {
- return sqlite3_last_insert_rowid(handle);
+- (sqlite3_int64)lastInsertRowId {
+ if (self.sqliteHandle) {
+ return sqlite3_last_insert_rowid(self.sqliteHandle);
} else {
EGODBDebugLog(@"[EGODatabase] Can't get last rowid of nil sqlite");
return 0;
@@ -229,91 +244,99 @@ - (EGODatabaseResult*)executeQuery:(NSString*)sql {
- (EGODatabaseResult*)executeQuery:(NSString*)sql parameters:(NSArray*)parameters {
EGODBLockLog(@"[Query] Waiting for Lock (%@): %@", [sql md5], sql);
- [executeLock lock];
+ dispatch_semaphore_wait(_executeLock, 0);
EGODBLockLog(@"[Query] Got Lock (%@)", [sql md5]);
- EGODatabaseResult* result = [[[EGODatabaseResult alloc] init] autorelease];
+ EGODatabaseResult* result = [[EGODatabaseResult alloc] init];
if(![self open]) {
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return result;
}
int returnCode = 0;
sqlite3_stmt* statement = NULL;
- returnCode = sqlite3_prepare(handle, [sql UTF8String], -1, &statement, 0);
+ returnCode = sqlite3_prepare(self.sqliteHandle, [sql UTF8String], -1, &statement, 0);
result.errorCode = [self lastErrorCode];
result.errorMessage = [self lastErrorMessage];
if (SQLITE_BUSY == returnCode) {
EGODBDebugLog(@"[EGODatabase] Query Failed, Database Busy:\n%@\n\n", sql);
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return result;
} else if (SQLITE_OK != returnCode) {
EGODBDebugLog(@"[EGODatabase] Query Failed, Error: %d \"%@\"\n%@\n\n", [self lastErrorCode], [self lastErrorMessage], sql);
sqlite3_finalize(statement);
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return result;
}
if (![self bindStatement:statement toParameters:parameters]) {
EGODBDebugLog(@"[EGODatabase] Invalid bind count for number of arguments.");
sqlite3_finalize(statement);
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return result;
}
int columnCount = sqlite3_column_count(statement);
- int x;
- for(x=0;x<columnCount;x++) {
+ NSMutableArray* columnNames = [[NSMutableArray alloc] init];
+ NSMutableArray* columnTypes = [[NSMutableArray alloc] init];
+
+ for(int x = 0; x < columnCount; x++) {
if(sqlite3_column_name(statement,x) != NULL) {
- [result.columnNames addObject:[NSString stringWithUTF8String:sqlite3_column_name(statement,x)]];
+ [columnNames addObject:[NSString stringWithUTF8String:sqlite3_column_name(statement,x)]];
} else {
- [result.columnNames addObject:[NSString stringWithFormat:@"%d", x]];
+ [columnNames addObject:[NSString stringWithFormat:@"%d", x]];
}
if(sqlite3_column_decltype(statement,x) != NULL) {
- [result.columnTypes addObject:[NSString stringWithUTF8String:sqlite3_column_decltype(statement,x)]];
+ [columnTypes addObject:[NSString stringWithUTF8String:sqlite3_column_decltype(statement,x)]];
} else {
- [result.columnTypes addObject:@""];
+ [columnTypes addObject:@""];
}
}
+ result.columnNames = columnNames;
+ result.columnTypes = columnTypes;
+
+ NSMutableArray* rows = [[NSMutableArray alloc] init];
+
while(sqlite3_step(statement) == SQLITE_ROW) {
- EGODatabaseRow* row = [[EGODatabaseRow alloc] initWithDatabaseResult:result];
- for(x=0;x<columnCount;x++) {
+ NSMutableArray* data = [[NSMutableArray alloc] init];
+
+ for(int x = 0; x < columnCount; x++) {
if (SQLITE_BLOB == sqlite3_column_type(statement, x)) {
- [row.columnData addObject:[NSData
- dataWithBytes:sqlite3_column_text(statement,x)
- length:sqlite3_column_bytes(statement,x)]];
+ [data addObject:[NSData dataWithBytes:sqlite3_column_text(statement,x) length:sqlite3_column_bytes(statement,x)]];
} else if (sqlite3_column_text(statement,x) != NULL) {
- [row.columnData addObject:[[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement,x)] autorelease]];
+ [data addObject:@((char*)sqlite3_column_text(statement,x))];
} else {
- [row.columnData addObject:@""];
+ [data addObject:@""];
}
}
- [result addRow:row];
- [row release];
+ EGODatabaseRow* row = [[EGODatabaseRow alloc] initWithDatabaseResult:result data:data];
+ [rows addObject:row];
}
+ result.rows = rows;
+
sqlite3_finalize(statement);
EGODBLockLog(@"%@ released lock", [sql md5]);
- [executeLock unlock];
+ dispatch_semaphore_signal(_executeLock);
return result;
}
- (NSString*)lastErrorMessage {
if([self hadError]) {
- return [NSString stringWithUTF8String:sqlite3_errmsg(handle)];
+ return [NSString stringWithUTF8String:sqlite3_errmsg(self.sqliteHandle)];
} else {
return nil;
}
@@ -324,7 +347,7 @@ - (BOOL)hadError {
}
- (int)lastErrorCode {
- return sqlite3_errcode(handle);
+ return sqlite3_errcode(self.sqliteHandle);
}
- (BOOL)bindStatement:(sqlite3_stmt*)statement toParameters:(NSArray*)parameters {
@@ -343,7 +366,7 @@ - (void)bindObject:(id)obj toColumn:(int)idx inStatement:(sqlite3_stmt*)pStmt {
if ((!obj) || ((NSNull *)obj == [NSNull null])) {
sqlite3_bind_null(pStmt, idx);
} else if ([obj isKindOfClass:[NSData class]]) {
- sqlite3_bind_blob(pStmt, idx, [obj bytes], [obj length], SQLITE_STATIC);
+ sqlite3_bind_blob(pStmt, idx, [obj bytes], (int)[obj length], SQLITE_STATIC);
} else if ([obj isKindOfClass:[NSDate class]]) {
sqlite3_bind_double(pStmt, idx, [obj timeIntervalSince1970]);
} else if ([obj isKindOfClass:[NSNumber class]]) {
@@ -367,9 +390,6 @@ - (void)bindObject:(id)obj toColumn:(int)idx inStatement:(sqlite3_stmt*)pStmt {
- (void)dealloc {
[self close];
- [executeLock release];
- [databasePath release];
- [super dealloc];
}
@end
View
41 EGODatabaseRequest.h → Classes/EGODatabaseRequest.h
@@ -2,8 +2,7 @@
// EGODatabaseRequest.h
// EGODatabase
//
-// Created by Shaun Harrison on 10/18/09.
-// Copyright (c) 2009 enormego
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -31,33 +30,23 @@
#import <Foundation/Foundation.h>
-typedef enum {
+typedef NS_ENUM(NSInteger, EGODatabaseRequestKind) {
EGODatabaseUpdateRequest,
EGODatabaseSelectRequest
-} EGODatabaseRequestKind;
+};
@class EGODatabase, EGODatabaseResult;
-@protocol EGODatabaseRequestDelegate;
-@interface EGODatabaseRequest : NSOperation {
-@private
- NSArray* parameters;
- NSInteger tag;
- NSString* query;
- EGODatabase* database;
- EGODatabaseRequestKind requestKind;
- id<EGODatabaseRequestDelegate> delegate;
-}
-
-- (id)initWithQuery:(NSString*)aQuery;
-- (id)initWithQuery:(NSString*)aQuery parameters:(NSArray*)someParameters;
-
-@property(nonatomic,assign) NSInteger tag;
-@property(nonatomic,retain) EGODatabase* database;
-@property(nonatomic,assign) EGODatabaseRequestKind requestKind;
-@property(nonatomic,assign) id<EGODatabaseRequestDelegate> delegate;
-@end
-@protocol EGODatabaseRequestDelegate<NSObject>
-- (void)requestDidSucceed:(EGODatabaseRequest*)request withResult:(EGODatabaseResult*)result; // result will be nil for EGODatabaseUpdateRequest
-- (void)requestDidFail:(EGODatabaseRequest*)request withError:(NSError*)error;
+@interface EGODatabaseRequest : NSOperation
+
+- (id)initWithQuery:(NSString*)query;
+- (id)initWithQuery:(NSString*)query parameters:(NSArray*)parameters;
+
+@property(nonatomic) NSInteger tag;
+@property(nonatomic) EGODatabaseRequestKind requestKind;
+
+@property(nonatomic,strong) EGODatabase* database;
+
+// Called asynchronously on the main queue
+@property(nonatomic,copy) void(^completion)(EGODatabaseRequest* request, EGODatabaseResult* result, NSError* error);
@end
View
106 Classes/EGODatabaseRequest.m
@@ -0,0 +1,106 @@
+//
+// EGODatabaseRequest.m
+// EGODatabase
+//
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#import "EGODatabaseRequest.h"
+#import "EGODatabase.h"
+
+
+@implementation EGODatabaseRequest {
+ NSArray* _parameters;
+ NSString* _query;
+}
+
+- (id)initWithQuery:(NSString*)query {
+ return [self initWithQuery:query parameters:nil];
+}
+
+- (id)initWithQuery:(NSString*)query parameters:(NSArray*)parameters {
+ if((self = [super init])) {
+ _query = [query copy];
+ _parameters = parameters;
+ self.requestKind = EGODatabaseSelectRequest;
+ }
+
+ return self;
+}
+
+- (void)main {
+ if(self.requestKind == EGODatabaseUpdateRequest) {
+ [self executeUpdate];
+ } else {
+ [self executeQuery];
+ }
+}
+
+- (void)executeUpdate {
+ BOOL result = [self.database executeUpdate:_query parameters:_parameters];
+
+ if(result) {
+ [self didSucceedWithResult:nil];
+ } else {
+ NSString* errorMessage = [self.database lastErrorMessage];
+ NSDictionary* userInfo = nil;
+
+ if(errorMessage != nil) {
+ userInfo = @{ @"message" : errorMessage };
+ }
+
+ [self didFailWithError:[NSError errorWithDomain:@"com.egodatabase.update" code:[self.database lastErrorCode] userInfo:userInfo]];
+ }
+}
+
+- (void)executeQuery {
+ EGODatabaseResult* result = [self.database executeQuery:_query parameters:_parameters];
+
+ if(result.errorCode == 0) {
+ [self didSucceedWithResult:result];
+ } else {
+ NSDictionary* userInfo = nil;
+
+ if(result.errorMessage != nil) {
+ userInfo = @{ @"message" : result.errorMessage };
+ }
+
+ [self didFailWithError:[NSError errorWithDomain:@"com.egodatabase.select" code:result.errorCode userInfo:userInfo]];
+ }
+}
+
+- (void)didSucceedWithResult:(EGODatabaseResult*)result {
+ if(self.completion != nil) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.completion(self, result, nil);
+ });
+ }
+}
+
+- (void)didFailWithError:(NSError*)error {
+ if(self.completion != nil) {
+ dispatch_async(dispatch_get_main_queue(), ^{
+ self.completion(self, nil, error);
+ });
+ }
+}
+
+@end
View
30 EGODatabaseResult.h → Classes/EGODatabaseResult.h
@@ -2,8 +2,7 @@
// EGODatabaseResult.h
// EGODatabase
//
-// Created by Shaun Harrison on 3/6/09.
-// Copyright (c) 2009 enormego
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -27,22 +26,19 @@
#import <Foundation/Foundation.h>
@class EGODatabaseRow;
-@interface EGODatabaseResult : NSObject<NSFastEnumeration> {
-@private
- int errorCode;
- NSString* errorMessage;
- NSMutableArray* columnNames;
- NSMutableArray* columnTypes;
- NSMutableArray* rows;
-}
-- (void)addRow:(EGODatabaseRow*)row;
-- (EGODatabaseRow*)rowAtIndex:(NSInteger)index;
+@interface EGODatabaseResult : NSObject <NSFastEnumeration>
+
+- (EGODatabaseRow*)rowAtIndex:(NSUInteger)index;
- (NSUInteger)count;
-@property(nonatomic,assign) int errorCode;
-@property(nonatomic,copy) NSString* errorMessage;
-@property(readonly) NSMutableArray* columnNames;
-@property(readonly) NSMutableArray* columnTypes;
-@property(readonly) NSMutableArray* rows;
+- (EGODatabaseRow*)firstRow;
+- (EGODatabaseRow*)lastRow;
+
+@property(nonatomic,readonly) int errorCode;
+@property(nonatomic,copy,readonly) NSString* errorMessage;
+
+@property(nonatomic,strong,readonly) NSArray* columnNames;
+@property(nonatomic,strong,readonly) NSArray* columnTypes;
+@property(nonatomic,strong,readonly) NSArray* rows;
@end
View
41 EGODatabaseResult.m → Classes/EGODatabaseResult.m
@@ -2,8 +2,7 @@
// EGODatabaseResult.m
// EGODatabase
//
-// Created by Shaun Harrison on 3/6/09.
-// Copyright (c) 2009 enormego
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -24,44 +23,28 @@
// THE SOFTWARE.
//
-#import "EGODatabaseResult.h"
-
+#import "EGODatabaseResult_Internal.h"
@implementation EGODatabaseResult
-@synthesize errorCode, errorMessage, columnNames, columnTypes, rows;
-- (id)init {
- if((self = [super init])) {
- errorCode = 0;
- columnNames = [[NSMutableArray alloc] init];
- columnTypes = [[NSMutableArray alloc] init];
- rows = [[NSMutableArray alloc] init];
- }
-
- return self;
-}
-- (void)addRow:(EGODatabaseRow*)row {
- [rows addObject:row];
+- (EGODatabaseRow*)rowAtIndex:(NSUInteger)index {
+ return [self.rows objectAtIndex:index];
}
-- (EGODatabaseRow*)rowAtIndex:(NSInteger)index {
- return [rows objectAtIndex:index];
+- (EGODatabaseRow*)firstRow {
+ return [self.rows firstObject];
}
-- (NSUInteger)count {
- return rows.count;
+- (EGODatabaseRow*)lastRow {
+ return [self.rows lastObject];
}
-- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len {
- return [rows countByEnumeratingWithState:state objects:stackbuf count:len];
+- (NSUInteger)count {
+ return [self.rows count];
}
-- (void)dealloc {
- [rows release];
- [errorMessage release];
- [columnNames release];
- [columnTypes release];
- [super dealloc];
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state objects:(id __unsafe_unretained [])buffer count:(NSUInteger)len {
+ return [self.rows countByEnumeratingWithState:state objects:buffer count:len];
}
@end
View
35 Classes/EGODatabaseResult_Internal.h
@@ -0,0 +1,35 @@
+//
+// EGODatabaseResult_Internal.h
+// EGODatabase
+//
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#import "EGODatabaseResult.h"
+
+@interface EGODatabaseResult ()
+
+@property(nonatomic,readwrite) int errorCode;
+@property(nonatomic,copy,readwrite) NSString* errorMessage;
+@property(nonatomic,strong,readwrite) NSArray* columnNames;
+@property(nonatomic,strong,readwrite) NSArray* columnTypes;
+@property(nonatomic,strong,readwrite) NSArray* rows;
+@end
View
40 EGODatabaseRow.h → Classes/EGODatabaseRow.h
@@ -2,8 +2,7 @@
// EGODatabaseRow.h
// EGODatabase
//
-// Created by Shaun Harrison on 3/6/09.
-// Copyright (c) 2009 enormego
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@@ -27,34 +26,29 @@
#import <Foundation/Foundation.h>
@class EGODatabaseResult;
-@interface EGODatabaseRow : NSObject {
-@private
- NSMutableArray* columnData;
- EGODatabaseResult* result;
-}
-- (id)initWithDatabaseResult:(EGODatabaseResult*)aResult;
+@interface EGODatabaseRow : NSObject
-- (int)intForColumn:(NSString*)columnName;
-- (int)intForColumnIndex:(int)columnIdx;
+- (int)intForColumn:(NSString*)name;
+- (int)intForColumnAtIndex:(NSUInteger)index;
-- (long)longForColumn:(NSString*)columnName;
-- (long)longForColumnIndex:(int)columnIdx;
+- (long)longForColumn:(NSString*)name;
+- (long)longForColumnAtIndex:(NSUInteger)index;
-- (BOOL)boolForColumn:(NSString*)columnName;
-- (BOOL)boolForColumnIndex:(int)columnIdx;
+- (BOOL)boolForColumn:(NSString*)name;
+- (BOOL)boolForColumnAtIndex:(NSUInteger)index;
-- (double)doubleForColumn:(NSString*)columnName;
-- (double)doubleForColumnIndex:(int)columnIdx;
+- (double)doubleForColumn:(NSString*)name;
+- (double)doubleForColumnAtIndex:(NSUInteger)index;
-- (NSString*)stringForColumn:(NSString*)columnName;
-- (NSString*)stringForColumnIndex:(int)columnIdx;
+- (NSString*)stringForColumn:(NSString*)name;
+- (NSString*)stringForColumnAtIndex:(NSUInteger)index;
-- (NSData*)dataForColumn:(NSString*)columnName;
-- (NSData*)dataForColumnIndex:(int)columnIndex;
+- (NSData*)dataForColumn:(NSString*)name;
+- (NSData*)dataForColumnAtIndex:(NSUInteger)index;
-- (NSDate*)dateForColumn:(NSString*)columnName;
-- (NSDate*)dateForColumnIndex:(int)columnIdx;
+- (NSDate*)dateForColumn:(NSString*)name;
+- (NSDate*)dateForColumnAtIndex:(NSUInteger)index;
-@property(readonly) NSMutableArray* columnData;
+@property(nonatomic,strong,readonly) NSArray* data;
@end
View
153 Classes/EGODatabaseRow.m
@@ -0,0 +1,153 @@
+//
+// EGODatabaseRow.m
+// EGODatabase
+//
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#import "EGODatabaseRow_Internal.h"
+#import "EGODatabaseResult.h"
+
+@interface EGODatabaseRow ()
+
+@property(nonatomic,strong) NSArray* names;
+@end
+
+@implementation EGODatabaseRow
+
+- (instancetype)initWithDatabaseResult:(EGODatabaseResult*)result data:(NSArray*)data {
+ if((self = [super init])) {
+ self.names = result.columnNames;
+ self.data = data;
+ }
+
+ return self;
+}
+
+- (NSUInteger)indexForName:(NSString*)column {
+ return [self.names indexOfObject:column];
+}
+
+- (int)intForColumn:(NSString*)column {
+ NSUInteger index = [self indexForName:column];
+
+ if(index == NSNotFound) {
+ return 0;
+ } else {
+ return [self intForColumnAtIndex:index];
+ }
+}
+
+- (int)intForColumnAtIndex:(NSUInteger)index {
+ return [[self.data objectAtIndex:index] intValue];
+}
+
+- (long)longForColumn:(NSString*)column {
+ NSUInteger index = [self indexForName:column];
+
+ if(index == NSNotFound) {
+ return 0;
+ } else {
+ return [[self.data objectAtIndex:index] longValue];
+ }
+}
+
+- (long)longForColumnAtIndex:(NSUInteger)index {
+ return [[self.data objectAtIndex:index] longValue];
+}
+
+- (BOOL)boolForColumn:(NSString*)column {
+ return ([self intForColumn:column] != 0);
+}
+
+- (BOOL)boolForColumnAtIndex:(NSUInteger)index {
+ return ([self intForColumnAtIndex:index] != 0);
+}
+
+- (double)doubleForColumn:(NSString*)column {
+ NSUInteger index = [self indexForName:column];
+
+ if(index == NSNotFound) {
+ return 0.0;
+ } else {
+ return [self doubleForColumnAtIndex:index];
+ }
+}
+
+- (double)doubleForColumnAtIndex:(NSUInteger)index {
+ return [[self.data objectAtIndex:index] doubleValue];
+}
+
+- (NSString*)stringForColumn:(NSString*)column {
+ NSUInteger index = [self indexForName:column];
+
+ if(index == NSNotFound) {
+ return nil;
+ } else {
+ return [self stringForColumnAtIndex:index];
+ }
+}
+
+- (NSString*)stringForColumnAtIndex:(NSUInteger)index {
+ id object = [self.data objectAtIndex:index];
+
+ if ([object isKindOfClass:[NSString class]]) {
+ return object;
+ } else {
+ return [object description];
+ }
+}
+
+- (NSData*)dataForColumn:(NSString*)column {
+ NSUInteger index = [self indexForName:column];
+
+ if (index == NSNotFound) {
+ return nil;
+ } else {
+ return [self dataForColumnAtIndex:index];
+ }
+}
+
+- (NSData*)dataForColumnAtIndex:(NSUInteger)index {
+ id object = [self.data objectAtIndex:index];
+
+ if ([object isKindOfClass:[NSData class]]) {
+ return object;
+ } else {
+ return nil;
+ }
+}
+
+- (NSDate*)dateForColumn:(NSString*)column {
+ NSUInteger index = [self indexForName:column];
+
+ if (index == NSNotFound) {
+ return nil;
+ } else {
+ return [self dateForColumnAtIndex:index];
+ }
+}
+
+- (NSDate*)dateForColumnAtIndex:(NSUInteger)index {
+ return [NSDate dateWithTimeIntervalSince1970:[self doubleForColumnAtIndex:index]];
+}
+
+@end
View
33 Classes/EGODatabaseRow_Internal.h
@@ -0,0 +1,33 @@
+//
+// EGODatabaseRow_Internal.h
+// EGODatabase
+//
+// Copyright (c) 2009-2014 Enormego, Shaun Harrison
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#import "EGODatabaseRow.h"
+
+@interface EGODatabaseRow ()
+
+- (instancetype)initWithDatabaseResult:(EGODatabaseResult*)result data:(NSArray*)data;
+
+@property(nonatomic,strong,readwrite) NSArray* data;
+@end
View
13 EGODatabase.podspec
@@ -0,0 +1,13 @@
+Pod::Spec.new do |s|
+ s.name = "EGODatabase"
+ s.version = "2.0"
+ s.summary = "Thread-safe Objective-C SQLite library."
+ s.description = "EGODatabase is a thread-safe Objective-C SQLite wrapper with full support for asynchronous SQLite calls as well as build in NSOperationQueue support."
+ s.homepage = "https://github.com/enormego/egodatabase"
+ s.license = "MIT"
+ s.author = "Enormego, Shaun Harrison"
+ s.source = { :git => "https://github.com/enormego/egodatabase.git", :tag => s.version.to_s }
+ s.requires_arc = true
+ s.source_files = "Classes"
+ s.library = "sqlite3"
+end
View
118 EGODatabaseRequest.m
@@ -1,118 +0,0 @@
-//
-// EGODatabaseRequest.m
-// EGODatabase
-//
-// Created by Shaun Harrison on 10/18/09.
-// Copyright (c) 2009 enormego
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#import "EGODatabaseRequest.h"
-#import "EGODatabase.h"
-
-@interface EGODatabaseRequest (Private)
-- (void)didSucceedWithResult:(EGODatabaseResult*)result;
-- (void)didFailWithError:(NSError*)error;
-@end
-
-
-@implementation EGODatabaseRequest
-@synthesize requestKind, database, delegate, tag;
-
-- (id)initWithQuery:(NSString*)aQuery {
- return [self initWithQuery:aQuery parameters:nil];
-}
-
-- (id)initWithQuery:(NSString*)aQuery parameters:(NSArray*)someParameters {
- if((self = [super init])) {
- query = [aQuery retain];
- parameters = [someParameters retain];
- requestKind = EGODatabaseSelectRequest;
- }
-
- return self;
-}
-
-- (void)main {
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [delegate retain];
-
- if(self.requestKind == EGODatabaseUpdateRequest) {
- BOOL result = [self.database executeUpdate:query parameters:parameters];
-
- if(result) {
- [self didSucceedWithResult:nil];
- } else {
- NSString* errorMessage = [self.database lastErrorMessage];
- NSDictionary* userInfo = nil;
-
- if(errorMessage) {
- userInfo = [NSDictionary dictionaryWithObject:errorMessage forKey:@"message"];
- }
-
- NSError* error = [NSError errorWithDomain:@"com.egodatabase.update"
- code:[self.database lastErrorCode]
- userInfo:userInfo];
-
- [self didFailWithError:error];
- }
- } else {
- EGODatabaseResult* result = [self.database executeQuery:query parameters:parameters];
-
- if(result.errorCode == 0) {
- [self didSucceedWithResult:result];
- } else {
- NSDictionary* userInfo = nil;
-
- if(result.errorMessage) {
- userInfo = [NSDictionary dictionaryWithObject:result.errorMessage forKey:@"message"];
- }
-
- NSError* error = [NSError errorWithDomain:@"com.egodatabase.select"
- code:result.errorCode
- userInfo:userInfo];
-
- [self didFailWithError:error];
- }
- }
-
- [delegate release];
- [pool release];
-}
-
-- (void)didSucceedWithResult:(EGODatabaseResult*)result {
- if(delegate && [delegate respondsToSelector:@selector(requestDidSucceed:withResult:)]) {
- [delegate requestDidSucceed:self withResult:result];
- }
-}
-
-- (void)didFailWithError:(NSError*)error {
- if(delegate && [delegate respondsToSelector:@selector(requestDidFail:withError:)]) {
- [delegate requestDidFail:self withError:error];
- }
-}
-
-- (void)dealloc {
- [parameters release];
- [database release];
- [super dealloc];
-}
-
-@end
View
122 EGODatabaseRow.m
@@ -1,122 +0,0 @@
-//
-// EGODatabaseRow.m
-// EGODatabase
-//
-// Created by Shaun Harrison on 3/6/09.
-// Copyright (c) 2009 enormego
-//
-// Permission is hereby granted, free of charge, to any person obtaining a copy
-// of this software and associated documentation files (the "Software"), to deal
-// in the Software without restriction, including without limitation the rights
-// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-// copies of the Software, and to permit persons to whom the Software is
-// furnished to do so, subject to the following conditions:
-//
-// The above copyright notice and this permission notice shall be included in
-// all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-// THE SOFTWARE.
-//
-
-#import "EGODatabaseRow.h"
-#import "EGODatabaseResult.h"
-
-
-@implementation EGODatabaseRow
-@synthesize columnData;
-
-- (id)initWithDatabaseResult:(EGODatabaseResult*)aResult {
- if((self = [super init])) {
- columnData = [[NSMutableArray alloc] init];
- result = aResult;
- // result = [aResult retain];
- }
-
- return self;
-}
-
-- (int)columnIndexForName:(NSString*)columnName {
- return [result.columnNames indexOfObject:columnName];
-}
-
-- (int)intForColumn:(NSString*)columnName {
- int columnIndex = [self columnIndexForName:columnName];
- if(columnIndex < 0 || columnIndex == NSNotFound) return 0;
- return [[columnData objectAtIndex:columnIndex] intValue];
-}
-
-- (int)intForColumnIndex:(int)columnIndex {
- return [[columnData objectAtIndex:columnIndex] intValue];
-}
-
-- (long)longForColumn:(NSString*)columnName {
- int columnIndex = [self columnIndexForName:columnName];
- if(columnIndex < 0 || columnIndex == NSNotFound) return 0;
- return [[columnData objectAtIndex:columnIndex] longValue];
-}
-
-- (long)longForColumnIndex:(int)columnIndex {
- return [[columnData objectAtIndex:columnIndex] longValue];
-}
-
-- (BOOL)boolForColumn:(NSString*)columnName {
- return ([self intForColumn:columnName] != 0);
-}
-
-- (BOOL)boolForColumnIndex:(int)columnIndex {
- return ([self intForColumnIndex:columnIndex] != 0);
-}
-
-- (double)doubleForColumn:(NSString*)columnName {
- int columnIndex = [self columnIndexForName:columnName];
- if(columnIndex < 0 || columnIndex == NSNotFound) return 0;
- return [[columnData objectAtIndex:columnIndex] doubleValue];
-}
-
-- (double)doubleForColumnIndex:(int)columnIndex {
- return [[columnData objectAtIndex:columnIndex] doubleValue];
-}
-
-- (NSString*) stringForColumn:(NSString*)columnName {
- int columnIndex = [self columnIndexForName:columnName];
- if(columnIndex < 0 || columnIndex == NSNotFound) return @"";
- return [columnData objectAtIndex:columnIndex];
-}
-
-- (NSString*)stringForColumnIndex:(int)columnIndex {
- return [columnData objectAtIndex:columnIndex];
-}
-
-- (NSData*)dataForColumn:(NSString*)columnName {
- int columnIndex = [self columnIndexForName:columnName];
- if (columnIndex < 0 || columnIndex == NSNotFound) return nil;
- return [columnData objectAtIndex:columnIndex];
-}
-
-- (NSData*)dataForColumnIndex:(int)columnIndex {
- return [columnData objectAtIndex:columnIndex];
-}
-
-- (NSDate*)dateForColumn:(NSString*)columnName {
- int columnIndex = [self columnIndexForName:columnName];
- if(columnIndex == -1) return nil;
- return [NSDate dateWithTimeIntervalSince1970:[self doubleForColumnIndex:columnIndex]];
-}
-
-- (NSDate*)dateForColumnIndex:(int)columnIndex {
- return [NSDate dateWithTimeIntervalSince1970:[self doubleForColumnIndex:columnIndex]];
-}
-
-- (void)dealloc {
- // [result release];
- [columnData release];
- [super dealloc];
-}
-
-@end
View
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2014 Enormego
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
55 README.markdown
@@ -1,55 +0,0 @@
-# About EGODatabase
-EGODatabase is a thread-safe Objective SQLite wrapper created by enormego. After extensively using FMDB in our applications, we saw a lot of room for improvements, the biggest was making it thread-safe. EGODatabase uses some code from FMDB, but for the most part, it was completely reworked to use result sets and row objects. A major difference between FMDB and EGODatabase is when selecting data, EGODatabase populates its EGODatabaseRow class with the data from SQLite, as opposed to retaining the SQLite results like FMDB does.
-
-EGODatabase is tested to work with with iPhone OS and Mac OS X 10.5
-
-# Classes
-## EGODatabase
-This is the class where you'll open your SQLite database file and execute queries through.
-
-## EGODatabaseResult
-This is the class returned by EGODatabase when running "executeQuery:". It supports fast enumeration, and contains properties for the column names, column types, rows, and errors if there are any.
-
-## EGODatabaseRow
-Every object that EGODatabaseResult contains, is an EGODatabaseRow. This is your raw data for each row. You'll be able to return specific types based on different methods such as intForColumn: or dateForColumn:. Check out the header files for a complete listing.
-
-# Documentation
-Check out each header file for a complete listing of each method.
-
-# Example
- EGODatabase* database = [EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]];
- EGODatabaseResult* result = [database executeQueryWithParameters:@"SELECT * FROM `posts` WHERE `post_user_id` = ?", [NSNumber numberWithInt:10]];
- for(EGODatabaseRow* row in result) {
- NSLog(@"Subject: %@", [row stringForColumn:@"post_subject"]);
- NSLog(@"Date: %@", [row dateForColumn:@"post_date"]);
- NSLog(@"Views: %d", [row intForColumn:@"post_views"]);
- NSLog(@"Message: %@", [row stringForColumn:@"post_message"]);
- }
-
-# Note
-Remember to link libsqlite3.dylib to your project!
-
-# Questions
-Feel free to contact info@enormego.com if you need any help with EGODatabase.
-
-# License
-Copyright (c) 2009 enormego
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
View
30 README.md
@@ -0,0 +1,30 @@
+# About EGODatabase
+EGODatabase is a thread-safe Objective SQLite wrapper created by enormego. After extensively using FMDB in our applications, we saw a lot of room for improvements, the biggest was making it thread-safe. EGODatabase uses some code from FMDB, but for the most part, it was completely reworked to use result sets and row objects. A major difference between FMDB and EGODatabase is when selecting data, EGODatabase populates its EGODatabaseRow class with the data from SQLite, as opposed to retaining the SQLite results like FMDB does.
+
+EGODatabase is tested to work with with all versions of iOS and Mac OS X 10.5+.
+
+# Classes
+## EGODatabase
+This is the class where you'll open your SQLite database file and execute queries through.
+
+## EGODatabaseResult
+This is the class returned by EGODatabase when running "executeQuery:". It supports fast enumeration, and contains properties for the column names, column types, rows, and errors if there are any.
+
+## EGODatabaseRow
+Every object that EGODatabaseResult contains, is an EGODatabaseRow. This is your raw data for each row. You'll be able to return specific types based on different methods such as intForColumn: or dateForColumn:. Check out the header files for a complete listing.
+
+# Documentation
+Check out each header file for a complete listing of each method.
+
+# Example
+ EGODatabase* database = [EGODatabase databaseWithPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/database.db"]];
+ EGODatabaseResult* result = [database executeQueryWithParameters:@"SELECT * FROM `posts` WHERE `user_id` = ?", @(10), nil];
+ for(EGODatabaseRow* row in result) {
+ NSLog(@"Subject: %@", [row stringForColumn:@"subject"]);
+ NSLog(@"Date: %@", [row dateForColumn:@"date"]);
+ NSLog(@"Views: %d", [row intForColumn:@"views"]);
+ NSLog(@"Message: %@", [row stringForColumn:@"message"]);
+ }
+
+# Note
+Remember to link libsqlite3.dylib to your project!

1 comment on commit 93b4de5

@johndpope

Hi Shaun,

Thanks for your efforts and updates on this library.
I'm trying to work out why one of my batch inserts isn't working and thought I'd enable the logging.
EGODBLockLog 1
but when I do - it kicks back a lot errors around use of undeclared identifier sql.
You also have an md5 value on nsstring which I don't think is referenced in this library anywhere.

Please sign in to comment.
Something went wrong with that request. Please try again.