Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few additions and fixes #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions EGODatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@
@private
sqlite3* handle;
BOOL opened;
NSStringEncoding stringEncoding;
}

@property (nonatomic,assign) NSStringEncoding encoding;

+ (id)databaseWithPath:(NSString*)aPath;
- (id)initWithPath:(NSString*)aPath;

Expand Down
6 changes: 5 additions & 1 deletion EGODatabase.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ - (void)bindObject:(id)obj toColumn:(int)idx inStatement:(sqlite3_stmt*)pStmt;

@implementation EGODatabase
@synthesize sqliteHandle=handle;
@synthesize encoding=stringEncoding;

+ (id)databaseWithPath:(NSString*)aPath {
return [[[[self class] alloc] initWithPath:aPath] autorelease];
Expand All @@ -81,6 +82,7 @@ - (id)initWithPath:(NSString*)aPath {
if((self = [super init])) {
databasePath = [aPath retain];
executeLock = [[NSLock alloc] init];
stringEncoding = NSUTF8StringEncoding;
}

return self;
Expand Down Expand Up @@ -278,7 +280,9 @@ - (EGODatabaseResult*)executeQuery:(NSString*)sql parameters:(NSArray*)parameter
EGODatabaseRow* row = [[EGODatabaseRow alloc] initWithDatabaseResult:result];
for(x=0;x<columnCount;x++) {
if(sqlite3_column_text(statement,x) != NULL) {
[row.columnData addObject:[[[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(statement,x)] autorelease]];
char* text = (char *)sqlite3_column_text(statement,x);
NSString* textString = [NSString stringWithCString:text encoding:stringEncoding];
[row.columnData addObject:textString];
} else {
[row.columnData addObject:@""];
}
Expand Down
1 change: 1 addition & 0 deletions EGODatabaseRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ typedef enum {
@end

@protocol EGODatabaseRequestDelegate<NSObject>
- (void)requestDidStartLoad:(EGODatabaseRequest*)request;
- (void)requestDidSucceed:(EGODatabaseRequest*)request withResult:(EGODatabaseResult*)result; // result will be nil for EGODatabaseUpdateRequest
- (void)requestDidFail:(EGODatabaseRequest*)request withError:(NSError*)error;
@end
10 changes: 10 additions & 0 deletions EGODatabaseRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#import "EGODatabase.h"

@interface EGODatabaseRequest (Private)
- (void)didStartLoad;
- (void)didSucceedWithResult:(EGODatabaseResult*)result;
- (void)didFailWithError:(NSError*)error;
@end
Expand All @@ -54,6 +55,8 @@ - (void)main {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
[delegate retain];

[self didStartLoad];

if(self.requestKind == EGODatabaseUpdateRequest) {
BOOL result = [self.database executeUpdate:query parameters:parameters];

Expand Down Expand Up @@ -97,6 +100,12 @@ - (void)main {
[pool release];
}

-(void)didStartLoad{
if(delegate && [delegate respondsToSelector:@selector(requestDidStartLoad:)]) {
[delegate requestDidStartLoad:self];
}
}

- (void)didSucceedWithResult:(EGODatabaseResult*)result {
if(delegate && [delegate respondsToSelector:@selector(requestDidSucceed:withResult:)]) {
[delegate requestDidSucceed:self withResult:result];
Expand All @@ -110,6 +119,7 @@ - (void)didFailWithError:(NSError*)error {
}

- (void)dealloc {
[query release];
[parameters release];
[database release];
[super dealloc];
Expand Down