Permalink
Browse files

Merge pull request #4 from gradha/master

Small improvements
  • Loading branch information...
2 parents 79cd281 + 476661c commit 8bbeedea445f76e5709716f4c7f7c4bfeaff6cf8 @shnhrrsn shnhrrsn committed Jun 25, 2012
Showing with 31 additions and 1 deletion.
  1. +2 −0 EGODatabase.h
  2. +16 −1 EGODatabase.m
  3. 0 EGODatabaseResult.h
  4. 0 EGODatabaseResult.m
  5. +3 −0 EGODatabaseRow.h
  6. +10 −0 EGODatabaseRow.m
View
2 EGODatabase.h 100755 → 100644
@@ -53,6 +53,8 @@
- (BOOL)executeUpdate:(NSString*)sql;
- (BOOL)executeUpdate:(NSString*)sql parameters:(NSArray*)parameters;
+- (sqlite3_int64)last_insert_rowid;
+
// Execute Query
- (EGODatabaseResult*)executeQueryWithParameters:(NSString*)sql, ... NS_REQUIRES_NIL_TERMINATION;
View
@@ -137,6 +137,7 @@ - (BOOL)open {
- (void)close {
if(!handle) return;
sqlite3_close(handle);
+ handle = 0;
opened = NO;
}
@@ -208,6 +209,16 @@ - (BOOL)executeUpdate:(NSString*)sql parameters:(NSArray*)parameters {
return (returnCode == SQLITE_OK);
}
+- (sqlite3_int64)last_insert_rowid
+{
+ if (handle) {
+ return sqlite3_last_insert_rowid(handle);
+ } else {
+ EGODBDebugLog(@"[EGODatabase] Can't get last rowid of nil sqlite");
+ return 0;
+ }
+}
+
- (EGODatabaseResult*)executeQueryWithParameters:(NSString*)sql,... {
return [self executeQuery:sql parameters:VAToArray(sql)];
}
@@ -277,7 +288,11 @@ - (EGODatabaseResult*)executeQuery:(NSString*)sql parameters:(NSArray*)parameter
while(sqlite3_step(statement) == SQLITE_ROW) {
EGODatabaseRow* row = [[EGODatabaseRow alloc] initWithDatabaseResult:result];
for(x=0;x<columnCount;x++) {
- if(sqlite3_column_text(statement,x) != NULL) {
+ if (SQLITE_BLOB == sqlite3_column_type(statement, x)) {
+ [row.columnData 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]];
} else {
[row.columnData addObject:@""];
View
0 EGODatabaseResult.h 100755 → 100644
No changes.
View
0 EGODatabaseResult.m 100755 → 100644
No changes.
View
3 EGODatabaseRow.h 100755 → 100644
@@ -50,6 +50,9 @@
- (NSString*)stringForColumn:(NSString*)columnName;
- (NSString*)stringForColumnIndex:(int)columnIdx;
+- (NSData*)dataForColumn:(NSString*)columnName;
+- (NSData*)dataForColumnIndex:(int)columnIndex;
+
- (NSDate*)dateForColumn:(NSString*)columnName;
- (NSDate*)dateForColumnIndex:(int)columnIdx;
View
10 EGODatabaseRow.m 100755 → 100644
@@ -93,6 +93,16 @@ - (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;

0 comments on commit 8bbeede

Please sign in to comment.