appjam 0.1.8.6 → 0.1.8.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appjam.rb +1 -1
- data/lib/appjam/generators/blank.rb +133 -0
- data/lib/appjam/generators/help.rb +5 -3
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.pbxproj +855 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/project.xcworkspace/xcuserdata/eiffel.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/EiffelApplication.xcscheme +96 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication.xcodeproj/xcuserdata/eiffel.xcuserdatad/xcschemes/xcschememanagement.plist +27 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.h.tt +22 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/AppDelegate.m.tt +156 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Info.plist +45 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/EiffelApplication-Prefix.pch.tt +30 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/en.lproj/InfoPlist.strings +2 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.h +636 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPClient.m +1359 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.h +133 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFHTTPRequestOperation.m +318 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.h +108 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFImageRequestOperation.m +234 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.h +71 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFJSONRequestOperation.m +142 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.h +75 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworkActivityIndicatorManager.m +145 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFNetworking.h +43 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.h +68 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFPropertyListRequestOperation.m +142 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.h +379 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFURLConnectionOperation.m +818 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.h +89 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/AFXMLRequestOperation.m +166 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.h +78 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/AFNetworking/UIImageView+AFNetworking.m +184 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.h +251 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/JSONKit/JSONKit.m +3067 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.h +155 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabase.m +1162 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.h +37 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseAdditions.m +163 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.h +75 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabasePool.m +244 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.h +38 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.m +176 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.h +104 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.m +413 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.h +78 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/EGOCache/EGOCache.m +370 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.h +41 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDASLLogger.m +99 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDAbstractDatabaseLogger.m +727 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.h +334 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDFileLogger.m +1353 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.h +601 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDLog.m +1083 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.h +167 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/DDTTYLogger.m +1479 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.h +65 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/ContextFilterLogFormatter.m +191 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.h +116 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Lumberjack/Extensions/DispatchQueueLogFormatter.m +251 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.h +33 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/ObjectiveMixin/Mixin.m +122 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.h +72 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USArrayWrapper.m +305 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USConstants.h +38 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.h +57 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/USDictionaryWrapper.m +188 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.h +89 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore+Functional.m +261 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore-Prefix.pch +7 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.h +50 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/libs/toolkit/Underscore/Underscore.m +100 -0
- data/lib/appjam/generators/templates/blank/EiffelApplication/main.m.tt +18 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests-Info.plist +22 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.h.tt +13 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/EiffelApplicationTests.m.tt +32 -0
- data/lib/appjam/generators/templates/blank/EiffelApplicationTests/en.lproj/InfoPlist.strings +2 -0
- data/lib/appjam/generators/templates/resources/Default-568h@2x.png +0 -0
- data/lib/appjam/generators/templates/resources/Default.png +0 -0
- data/lib/appjam/generators/templates/resources/Default@2x.png +0 -0
- data/lib/appjam/generators/templates/resources/contents.tt +4 -0
- data/lib/appjam/version.rb +1 -1
- metadata +462 -326
- data/test/helper.rb +0 -132
- data/test/test_model_generator.rb +0 -28
- data/test/test_project_generator.rb +0 -38
data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.h
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
//
|
2
|
+
// FMDatabaseQueue.h
|
3
|
+
// fmdb
|
4
|
+
//
|
5
|
+
// Created by August Mueller on 6/22/11.
|
6
|
+
// Copyright 2011 Flying Meat Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import <Foundation/Foundation.h>
|
10
|
+
#import "sqlite3.h"
|
11
|
+
|
12
|
+
@class FMDatabase;
|
13
|
+
|
14
|
+
@interface FMDatabaseQueue : NSObject {
|
15
|
+
NSString *_path;
|
16
|
+
dispatch_queue_t _queue;
|
17
|
+
FMDatabase *_db;
|
18
|
+
}
|
19
|
+
|
20
|
+
@property (atomic, retain) NSString *path;
|
21
|
+
|
22
|
+
+ (id)databaseQueueWithPath:(NSString*)aPath;
|
23
|
+
- (id)initWithPath:(NSString*)aPath;
|
24
|
+
- (void)close;
|
25
|
+
|
26
|
+
- (void)inDatabase:(void (^)(FMDatabase *db))block;
|
27
|
+
|
28
|
+
- (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
|
29
|
+
- (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
|
30
|
+
|
31
|
+
#if SQLITE_VERSION_NUMBER >= 3007000
|
32
|
+
// NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
|
33
|
+
// If you need to nest, use FMDatabase's startSavePointWithName:error: instead.
|
34
|
+
- (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
|
35
|
+
#endif
|
36
|
+
|
37
|
+
@end
|
38
|
+
|
data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMDatabaseQueue.m
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
//
|
2
|
+
// FMDatabaseQueue.m
|
3
|
+
// fmdb
|
4
|
+
//
|
5
|
+
// Created by August Mueller on 6/22/11.
|
6
|
+
// Copyright 2011 Flying Meat Inc. All rights reserved.
|
7
|
+
//
|
8
|
+
|
9
|
+
#import "FMDatabaseQueue.h"
|
10
|
+
#import "FMDatabase.h"
|
11
|
+
|
12
|
+
/*
|
13
|
+
|
14
|
+
Note: we call [self retain]; before using dispatch_sync, just incase
|
15
|
+
FMDatabaseQueue is released on another thread and we're in the middle of doing
|
16
|
+
something in dispatch_sync
|
17
|
+
|
18
|
+
*/
|
19
|
+
|
20
|
+
@implementation FMDatabaseQueue
|
21
|
+
|
22
|
+
@synthesize path = _path;
|
23
|
+
|
24
|
+
+ (id)databaseQueueWithPath:(NSString*)aPath {
|
25
|
+
|
26
|
+
FMDatabaseQueue *q = [[self alloc] initWithPath:aPath];
|
27
|
+
|
28
|
+
FMDBAutorelease(q);
|
29
|
+
|
30
|
+
return q;
|
31
|
+
}
|
32
|
+
|
33
|
+
- (id)initWithPath:(NSString*)aPath {
|
34
|
+
|
35
|
+
self = [super init];
|
36
|
+
|
37
|
+
if (self != nil) {
|
38
|
+
|
39
|
+
_db = [FMDatabase databaseWithPath:aPath];
|
40
|
+
FMDBRetain(_db);
|
41
|
+
|
42
|
+
if (![_db open]) {
|
43
|
+
NSLog(@"Could not create database queue for path %@", aPath);
|
44
|
+
FMDBRelease(self);
|
45
|
+
return 0x00;
|
46
|
+
}
|
47
|
+
|
48
|
+
_path = FMDBReturnRetained(aPath);
|
49
|
+
|
50
|
+
_queue = dispatch_queue_create([[NSString stringWithFormat:@"fmdb.%@", self] UTF8String], NULL);
|
51
|
+
}
|
52
|
+
|
53
|
+
return self;
|
54
|
+
}
|
55
|
+
|
56
|
+
- (void)dealloc {
|
57
|
+
|
58
|
+
FMDBRelease(_db);
|
59
|
+
FMDBRelease(_path);
|
60
|
+
|
61
|
+
if (_queue) {
|
62
|
+
FMDBDispatchQueueRelease(_queue);
|
63
|
+
_queue = 0x00;
|
64
|
+
}
|
65
|
+
#if ! __has_feature(objc_arc)
|
66
|
+
[super dealloc];
|
67
|
+
#endif
|
68
|
+
}
|
69
|
+
|
70
|
+
- (void)close {
|
71
|
+
FMDBRetain(self);
|
72
|
+
dispatch_sync(_queue, ^() {
|
73
|
+
[_db close];
|
74
|
+
FMDBRelease(_db);
|
75
|
+
_db = 0x00;
|
76
|
+
});
|
77
|
+
FMDBRelease(self);
|
78
|
+
}
|
79
|
+
|
80
|
+
- (FMDatabase*)database {
|
81
|
+
if (!_db) {
|
82
|
+
_db = FMDBReturnRetained([FMDatabase databaseWithPath:_path]);
|
83
|
+
|
84
|
+
if (![_db open]) {
|
85
|
+
NSLog(@"FMDatabaseQueue could not reopen database for path %@", _path);
|
86
|
+
FMDBRelease(_db);
|
87
|
+
_db = 0x00;
|
88
|
+
return 0x00;
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
return _db;
|
93
|
+
}
|
94
|
+
|
95
|
+
- (void)inDatabase:(void (^)(FMDatabase *db))block {
|
96
|
+
FMDBRetain(self);
|
97
|
+
|
98
|
+
dispatch_sync(_queue, ^() {
|
99
|
+
|
100
|
+
FMDatabase *db = [self database];
|
101
|
+
block(db);
|
102
|
+
|
103
|
+
if ([db hasOpenResultSets]) {
|
104
|
+
NSLog(@"Warning: there is at least one open result set around after performing [FMDatabaseQueue inDatabase:]");
|
105
|
+
}
|
106
|
+
});
|
107
|
+
|
108
|
+
FMDBRelease(self);
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
- (void)beginTransaction:(BOOL)useDeferred withBlock:(void (^)(FMDatabase *db, BOOL *rollback))block {
|
113
|
+
FMDBRetain(self);
|
114
|
+
dispatch_sync(_queue, ^() {
|
115
|
+
|
116
|
+
BOOL shouldRollback = NO;
|
117
|
+
|
118
|
+
if (useDeferred) {
|
119
|
+
[[self database] beginDeferredTransaction];
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
[[self database] beginTransaction];
|
123
|
+
}
|
124
|
+
|
125
|
+
block([self database], &shouldRollback);
|
126
|
+
|
127
|
+
if (shouldRollback) {
|
128
|
+
[[self database] rollback];
|
129
|
+
}
|
130
|
+
else {
|
131
|
+
[[self database] commit];
|
132
|
+
}
|
133
|
+
});
|
134
|
+
|
135
|
+
FMDBRelease(self);
|
136
|
+
}
|
137
|
+
|
138
|
+
- (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
|
139
|
+
[self beginTransaction:YES withBlock:block];
|
140
|
+
}
|
141
|
+
|
142
|
+
- (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
|
143
|
+
[self beginTransaction:NO withBlock:block];
|
144
|
+
}
|
145
|
+
|
146
|
+
#if SQLITE_VERSION_NUMBER >= 3007000
|
147
|
+
- (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
|
148
|
+
|
149
|
+
static unsigned long savePointIdx = 0;
|
150
|
+
__block NSError *err = 0x00;
|
151
|
+
FMDBRetain(self);
|
152
|
+
dispatch_sync(_queue, ^() {
|
153
|
+
|
154
|
+
NSString *name = [NSString stringWithFormat:@"savePoint%ld", savePointIdx++];
|
155
|
+
|
156
|
+
BOOL shouldRollback = NO;
|
157
|
+
|
158
|
+
if ([[self database] startSavePointWithName:name error:&err]) {
|
159
|
+
|
160
|
+
block([self database], &shouldRollback);
|
161
|
+
|
162
|
+
if (shouldRollback) {
|
163
|
+
[[self database] rollbackToSavePointWithName:name error:&err];
|
164
|
+
}
|
165
|
+
else {
|
166
|
+
[[self database] releaseSavePointWithName:name error:&err];
|
167
|
+
}
|
168
|
+
|
169
|
+
}
|
170
|
+
});
|
171
|
+
FMDBRelease(self);
|
172
|
+
return err;
|
173
|
+
}
|
174
|
+
#endif
|
175
|
+
|
176
|
+
@end
|
data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.h
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
#import "sqlite3.h"
|
3
|
+
|
4
|
+
#ifndef __has_feature // Optional.
|
5
|
+
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#ifndef NS_RETURNS_NOT_RETAINED
|
9
|
+
#if __has_feature(attribute_ns_returns_not_retained)
|
10
|
+
#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
|
11
|
+
#else
|
12
|
+
#define NS_RETURNS_NOT_RETAINED
|
13
|
+
#endif
|
14
|
+
#endif
|
15
|
+
|
16
|
+
@class FMDatabase;
|
17
|
+
@class FMStatement;
|
18
|
+
|
19
|
+
@interface FMResultSet : NSObject {
|
20
|
+
FMDatabase *_parentDB;
|
21
|
+
FMStatement *_statement;
|
22
|
+
|
23
|
+
NSString *_query;
|
24
|
+
NSMutableDictionary *_columnNameToIndexMap;
|
25
|
+
}
|
26
|
+
|
27
|
+
@property (atomic, retain) NSString *query;
|
28
|
+
@property (readonly) NSMutableDictionary *columnNameToIndexMap;
|
29
|
+
@property (atomic, retain) FMStatement *statement;
|
30
|
+
|
31
|
+
+ (id)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB;
|
32
|
+
|
33
|
+
- (void)close;
|
34
|
+
|
35
|
+
- (void)setParentDB:(FMDatabase *)newDb;
|
36
|
+
|
37
|
+
- (BOOL)next;
|
38
|
+
- (BOOL)hasAnotherRow;
|
39
|
+
|
40
|
+
- (int)columnCount;
|
41
|
+
|
42
|
+
- (int)columnIndexForName:(NSString*)columnName;
|
43
|
+
- (NSString*)columnNameForIndex:(int)columnIdx;
|
44
|
+
|
45
|
+
- (int)intForColumn:(NSString*)columnName;
|
46
|
+
- (int)intForColumnIndex:(int)columnIdx;
|
47
|
+
|
48
|
+
- (long)longForColumn:(NSString*)columnName;
|
49
|
+
- (long)longForColumnIndex:(int)columnIdx;
|
50
|
+
|
51
|
+
- (long long int)longLongIntForColumn:(NSString*)columnName;
|
52
|
+
- (long long int)longLongIntForColumnIndex:(int)columnIdx;
|
53
|
+
|
54
|
+
- (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName;
|
55
|
+
- (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx;
|
56
|
+
|
57
|
+
- (BOOL)boolForColumn:(NSString*)columnName;
|
58
|
+
- (BOOL)boolForColumnIndex:(int)columnIdx;
|
59
|
+
|
60
|
+
- (double)doubleForColumn:(NSString*)columnName;
|
61
|
+
- (double)doubleForColumnIndex:(int)columnIdx;
|
62
|
+
|
63
|
+
- (NSString*)stringForColumn:(NSString*)columnName;
|
64
|
+
- (NSString*)stringForColumnIndex:(int)columnIdx;
|
65
|
+
|
66
|
+
- (NSDate*)dateForColumn:(NSString*)columnName;
|
67
|
+
- (NSDate*)dateForColumnIndex:(int)columnIdx;
|
68
|
+
|
69
|
+
- (NSData*)dataForColumn:(NSString*)columnName;
|
70
|
+
- (NSData*)dataForColumnIndex:(int)columnIdx;
|
71
|
+
|
72
|
+
- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx;
|
73
|
+
- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName;
|
74
|
+
|
75
|
+
// returns one of NSNumber, NSString, NSData, or NSNull
|
76
|
+
- (id)objectForColumnName:(NSString*)columnName;
|
77
|
+
- (id)objectForColumnIndex:(int)columnIdx;
|
78
|
+
|
79
|
+
- (id)objectForKeyedSubscript:(NSString *)columnName;
|
80
|
+
- (id)objectAtIndexedSubscript:(int)columnIdx;
|
81
|
+
|
82
|
+
/*
|
83
|
+
If you are going to use this data after you iterate over the next row, or after you close the
|
84
|
+
result set, make sure to make a copy of the data first (or just use dataForColumn:/dataForColumnIndex:)
|
85
|
+
If you don't, you're going to be in a world of hurt when you try and use the data.
|
86
|
+
*/
|
87
|
+
- (NSData*)dataNoCopyForColumn:(NSString*)columnName NS_RETURNS_NOT_RETAINED;
|
88
|
+
- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED;
|
89
|
+
|
90
|
+
- (BOOL)columnIndexIsNull:(int)columnIdx;
|
91
|
+
- (BOOL)columnIsNull:(NSString*)columnName;
|
92
|
+
|
93
|
+
|
94
|
+
/* Returns a dictionary of the row results mapped to case sensitive keys of the column names. */
|
95
|
+
- (NSDictionary*)resultDictionary;
|
96
|
+
|
97
|
+
/* Please use resultDictionary instead. Also, beware that resultDictionary is case sensitive! */
|
98
|
+
- (NSDictionary*)resultDict __attribute__ ((deprecated));
|
99
|
+
|
100
|
+
- (void)kvcMagic:(id)object;
|
101
|
+
|
102
|
+
|
103
|
+
@end
|
104
|
+
|
data/lib/appjam/generators/templates/blank/EiffelApplication/libs/frameworks/fmdb/FMResultSet.m
ADDED
@@ -0,0 +1,413 @@
|
|
1
|
+
#import "FMResultSet.h"
|
2
|
+
#import "FMDatabase.h"
|
3
|
+
#import "unistd.h"
|
4
|
+
|
5
|
+
@interface FMDatabase ()
|
6
|
+
- (void)resultSetDidClose:(FMResultSet *)resultSet;
|
7
|
+
@end
|
8
|
+
|
9
|
+
|
10
|
+
@implementation FMResultSet
|
11
|
+
@synthesize query=_query;
|
12
|
+
@synthesize statement=_statement;
|
13
|
+
|
14
|
+
+ (id)resultSetWithStatement:(FMStatement *)statement usingParentDatabase:(FMDatabase*)aDB {
|
15
|
+
|
16
|
+
FMResultSet *rs = [[FMResultSet alloc] init];
|
17
|
+
|
18
|
+
[rs setStatement:statement];
|
19
|
+
[rs setParentDB:aDB];
|
20
|
+
|
21
|
+
return FMDBReturnAutoreleased(rs);
|
22
|
+
}
|
23
|
+
|
24
|
+
- (void)finalize {
|
25
|
+
[self close];
|
26
|
+
[super finalize];
|
27
|
+
}
|
28
|
+
|
29
|
+
- (void)dealloc {
|
30
|
+
[self close];
|
31
|
+
|
32
|
+
FMDBRelease(_query);
|
33
|
+
_query = nil;
|
34
|
+
|
35
|
+
FMDBRelease(_columnNameToIndexMap);
|
36
|
+
_columnNameToIndexMap = nil;
|
37
|
+
|
38
|
+
#if ! __has_feature(objc_arc)
|
39
|
+
[super dealloc];
|
40
|
+
#endif
|
41
|
+
}
|
42
|
+
|
43
|
+
- (void)close {
|
44
|
+
[_statement reset];
|
45
|
+
FMDBRelease(_statement);
|
46
|
+
_statement = nil;
|
47
|
+
|
48
|
+
// we don't need this anymore... (i think)
|
49
|
+
//[_parentDB setInUse:NO];
|
50
|
+
[_parentDB resultSetDidClose:self];
|
51
|
+
_parentDB = nil;
|
52
|
+
}
|
53
|
+
|
54
|
+
- (int)columnCount {
|
55
|
+
return sqlite3_column_count([_statement statement]);
|
56
|
+
}
|
57
|
+
|
58
|
+
- (NSMutableDictionary *)columnNameToIndexMap {
|
59
|
+
if (!_columnNameToIndexMap) {
|
60
|
+
int columnCount = sqlite3_column_count([_statement statement]);
|
61
|
+
_columnNameToIndexMap = [[NSMutableDictionary alloc] initWithCapacity:(NSUInteger)columnCount];
|
62
|
+
int columnIdx = 0;
|
63
|
+
for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
|
64
|
+
[_columnNameToIndexMap setObject:[NSNumber numberWithInt:columnIdx]
|
65
|
+
forKey:[[NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)] lowercaseString]];
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return _columnNameToIndexMap;
|
69
|
+
}
|
70
|
+
|
71
|
+
- (void)kvcMagic:(id)object {
|
72
|
+
|
73
|
+
int columnCount = sqlite3_column_count([_statement statement]);
|
74
|
+
|
75
|
+
int columnIdx = 0;
|
76
|
+
for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
|
77
|
+
|
78
|
+
const char *c = (const char *)sqlite3_column_text([_statement statement], columnIdx);
|
79
|
+
|
80
|
+
// check for a null row
|
81
|
+
if (c) {
|
82
|
+
NSString *s = [NSString stringWithUTF8String:c];
|
83
|
+
|
84
|
+
[object setValue:s forKey:[NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)]];
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
#pragma clang diagnostic push
|
90
|
+
#pragma clang diagnostic ignored "-Wdeprecated-implementations"
|
91
|
+
|
92
|
+
- (NSDictionary*)resultDict {
|
93
|
+
|
94
|
+
NSUInteger num_cols = (NSUInteger)sqlite3_data_count([_statement statement]);
|
95
|
+
|
96
|
+
if (num_cols > 0) {
|
97
|
+
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];
|
98
|
+
|
99
|
+
NSEnumerator *columnNames = [[self columnNameToIndexMap] keyEnumerator];
|
100
|
+
NSString *columnName = nil;
|
101
|
+
while ((columnName = [columnNames nextObject])) {
|
102
|
+
id objectValue = [self objectForColumnName:columnName];
|
103
|
+
[dict setObject:objectValue forKey:columnName];
|
104
|
+
}
|
105
|
+
|
106
|
+
return FMDBReturnAutoreleased([dict copy]);
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
NSLog(@"Warning: There seem to be no columns in this set.");
|
110
|
+
}
|
111
|
+
|
112
|
+
return nil;
|
113
|
+
}
|
114
|
+
|
115
|
+
#pragma clang diagnostic pop
|
116
|
+
|
117
|
+
- (NSDictionary*)resultDictionary {
|
118
|
+
|
119
|
+
NSUInteger num_cols = (NSUInteger)sqlite3_data_count([_statement statement]);
|
120
|
+
|
121
|
+
if (num_cols > 0) {
|
122
|
+
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithCapacity:num_cols];
|
123
|
+
|
124
|
+
int columnCount = sqlite3_column_count([_statement statement]);
|
125
|
+
|
126
|
+
int columnIdx = 0;
|
127
|
+
for (columnIdx = 0; columnIdx < columnCount; columnIdx++) {
|
128
|
+
|
129
|
+
NSString *columnName = [NSString stringWithUTF8String:sqlite3_column_name([_statement statement], columnIdx)];
|
130
|
+
id objectValue = [self objectForColumnIndex:columnIdx];
|
131
|
+
[dict setObject:objectValue forKey:columnName];
|
132
|
+
}
|
133
|
+
|
134
|
+
return dict;
|
135
|
+
}
|
136
|
+
else {
|
137
|
+
NSLog(@"Warning: There seem to be no columns in this set.");
|
138
|
+
}
|
139
|
+
|
140
|
+
return nil;
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
- (BOOL)next {
|
148
|
+
|
149
|
+
int rc;
|
150
|
+
BOOL retry;
|
151
|
+
int numberOfRetries = 0;
|
152
|
+
do {
|
153
|
+
retry = NO;
|
154
|
+
|
155
|
+
rc = sqlite3_step([_statement statement]);
|
156
|
+
|
157
|
+
if (SQLITE_BUSY == rc || SQLITE_LOCKED == rc) {
|
158
|
+
// this will happen if the db is locked, like if we are doing an update or insert.
|
159
|
+
// in that case, retry the step... and maybe wait just 10 milliseconds.
|
160
|
+
retry = YES;
|
161
|
+
if (SQLITE_LOCKED == rc) {
|
162
|
+
rc = sqlite3_reset([_statement statement]);
|
163
|
+
if (rc != SQLITE_LOCKED) {
|
164
|
+
NSLog(@"Unexpected result from sqlite3_reset (%d) rs", rc);
|
165
|
+
}
|
166
|
+
}
|
167
|
+
usleep(20);
|
168
|
+
|
169
|
+
if ([_parentDB busyRetryTimeout] && (numberOfRetries++ > [_parentDB busyRetryTimeout])) {
|
170
|
+
|
171
|
+
NSLog(@"%s:%d Database busy (%@)", __FUNCTION__, __LINE__, [_parentDB databasePath]);
|
172
|
+
NSLog(@"Database busy");
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
else if (SQLITE_DONE == rc || SQLITE_ROW == rc) {
|
177
|
+
// all is well, let's return.
|
178
|
+
}
|
179
|
+
else if (SQLITE_ERROR == rc) {
|
180
|
+
NSLog(@"Error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([_parentDB sqliteHandle]));
|
181
|
+
break;
|
182
|
+
}
|
183
|
+
else if (SQLITE_MISUSE == rc) {
|
184
|
+
// uh oh.
|
185
|
+
NSLog(@"Error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([_parentDB sqliteHandle]));
|
186
|
+
break;
|
187
|
+
}
|
188
|
+
else {
|
189
|
+
// wtf?
|
190
|
+
NSLog(@"Unknown error calling sqlite3_step (%d: %s) rs", rc, sqlite3_errmsg([_parentDB sqliteHandle]));
|
191
|
+
break;
|
192
|
+
}
|
193
|
+
|
194
|
+
} while (retry);
|
195
|
+
|
196
|
+
|
197
|
+
if (rc != SQLITE_ROW) {
|
198
|
+
[self close];
|
199
|
+
}
|
200
|
+
|
201
|
+
return (rc == SQLITE_ROW);
|
202
|
+
}
|
203
|
+
|
204
|
+
- (BOOL)hasAnotherRow {
|
205
|
+
return sqlite3_errcode([_parentDB sqliteHandle]) == SQLITE_ROW;
|
206
|
+
}
|
207
|
+
|
208
|
+
- (int)columnIndexForName:(NSString*)columnName {
|
209
|
+
columnName = [columnName lowercaseString];
|
210
|
+
|
211
|
+
NSNumber *n = [[self columnNameToIndexMap] objectForKey:columnName];
|
212
|
+
|
213
|
+
if (n) {
|
214
|
+
return [n intValue];
|
215
|
+
}
|
216
|
+
|
217
|
+
NSLog(@"Warning: I could not find the column named '%@'.", columnName);
|
218
|
+
|
219
|
+
return -1;
|
220
|
+
}
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
- (int)intForColumn:(NSString*)columnName {
|
225
|
+
return [self intForColumnIndex:[self columnIndexForName:columnName]];
|
226
|
+
}
|
227
|
+
|
228
|
+
- (int)intForColumnIndex:(int)columnIdx {
|
229
|
+
return sqlite3_column_int([_statement statement], columnIdx);
|
230
|
+
}
|
231
|
+
|
232
|
+
- (long)longForColumn:(NSString*)columnName {
|
233
|
+
return [self longForColumnIndex:[self columnIndexForName:columnName]];
|
234
|
+
}
|
235
|
+
|
236
|
+
- (long)longForColumnIndex:(int)columnIdx {
|
237
|
+
return (long)sqlite3_column_int64([_statement statement], columnIdx);
|
238
|
+
}
|
239
|
+
|
240
|
+
- (long long int)longLongIntForColumn:(NSString*)columnName {
|
241
|
+
return [self longLongIntForColumnIndex:[self columnIndexForName:columnName]];
|
242
|
+
}
|
243
|
+
|
244
|
+
- (long long int)longLongIntForColumnIndex:(int)columnIdx {
|
245
|
+
return sqlite3_column_int64([_statement statement], columnIdx);
|
246
|
+
}
|
247
|
+
|
248
|
+
- (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName {
|
249
|
+
return [self unsignedLongLongIntForColumnIndex:[self columnIndexForName:columnName]];
|
250
|
+
}
|
251
|
+
|
252
|
+
- (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx {
|
253
|
+
return (unsigned long long int)[self longLongIntForColumnIndex:columnIdx];
|
254
|
+
}
|
255
|
+
|
256
|
+
- (BOOL)boolForColumn:(NSString*)columnName {
|
257
|
+
return [self boolForColumnIndex:[self columnIndexForName:columnName]];
|
258
|
+
}
|
259
|
+
|
260
|
+
- (BOOL)boolForColumnIndex:(int)columnIdx {
|
261
|
+
return ([self intForColumnIndex:columnIdx] != 0);
|
262
|
+
}
|
263
|
+
|
264
|
+
- (double)doubleForColumn:(NSString*)columnName {
|
265
|
+
return [self doubleForColumnIndex:[self columnIndexForName:columnName]];
|
266
|
+
}
|
267
|
+
|
268
|
+
- (double)doubleForColumnIndex:(int)columnIdx {
|
269
|
+
return sqlite3_column_double([_statement statement], columnIdx);
|
270
|
+
}
|
271
|
+
|
272
|
+
- (NSString*)stringForColumnIndex:(int)columnIdx {
|
273
|
+
|
274
|
+
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
|
275
|
+
return nil;
|
276
|
+
}
|
277
|
+
|
278
|
+
const char *c = (const char *)sqlite3_column_text([_statement statement], columnIdx);
|
279
|
+
|
280
|
+
if (!c) {
|
281
|
+
// null row.
|
282
|
+
return nil;
|
283
|
+
}
|
284
|
+
|
285
|
+
return [NSString stringWithUTF8String:c];
|
286
|
+
}
|
287
|
+
|
288
|
+
- (NSString*)stringForColumn:(NSString*)columnName {
|
289
|
+
return [self stringForColumnIndex:[self columnIndexForName:columnName]];
|
290
|
+
}
|
291
|
+
|
292
|
+
- (NSDate*)dateForColumn:(NSString*)columnName {
|
293
|
+
return [self dateForColumnIndex:[self columnIndexForName:columnName]];
|
294
|
+
}
|
295
|
+
|
296
|
+
- (NSDate*)dateForColumnIndex:(int)columnIdx {
|
297
|
+
|
298
|
+
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
|
299
|
+
return nil;
|
300
|
+
}
|
301
|
+
|
302
|
+
return [NSDate dateWithTimeIntervalSince1970:[self doubleForColumnIndex:columnIdx]];
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
- (NSData*)dataForColumn:(NSString*)columnName {
|
307
|
+
return [self dataForColumnIndex:[self columnIndexForName:columnName]];
|
308
|
+
}
|
309
|
+
|
310
|
+
- (NSData*)dataForColumnIndex:(int)columnIdx {
|
311
|
+
|
312
|
+
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
|
313
|
+
return nil;
|
314
|
+
}
|
315
|
+
|
316
|
+
int dataSize = sqlite3_column_bytes([_statement statement], columnIdx);
|
317
|
+
|
318
|
+
NSMutableData *data = [NSMutableData dataWithLength:(NSUInteger)dataSize];
|
319
|
+
|
320
|
+
memcpy([data mutableBytes], sqlite3_column_blob([_statement statement], columnIdx), dataSize);
|
321
|
+
|
322
|
+
return data;
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
- (NSData*)dataNoCopyForColumn:(NSString*)columnName {
|
327
|
+
return [self dataNoCopyForColumnIndex:[self columnIndexForName:columnName]];
|
328
|
+
}
|
329
|
+
|
330
|
+
- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx {
|
331
|
+
|
332
|
+
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
|
333
|
+
return nil;
|
334
|
+
}
|
335
|
+
|
336
|
+
int dataSize = sqlite3_column_bytes([_statement statement], columnIdx);
|
337
|
+
|
338
|
+
NSData *data = [NSData dataWithBytesNoCopy:(void *)sqlite3_column_blob([_statement statement], columnIdx) length:(NSUInteger)dataSize freeWhenDone:NO];
|
339
|
+
|
340
|
+
return data;
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
- (BOOL)columnIndexIsNull:(int)columnIdx {
|
345
|
+
return sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL;
|
346
|
+
}
|
347
|
+
|
348
|
+
- (BOOL)columnIsNull:(NSString*)columnName {
|
349
|
+
return [self columnIndexIsNull:[self columnIndexForName:columnName]];
|
350
|
+
}
|
351
|
+
|
352
|
+
- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx {
|
353
|
+
|
354
|
+
if (sqlite3_column_type([_statement statement], columnIdx) == SQLITE_NULL || (columnIdx < 0)) {
|
355
|
+
return nil;
|
356
|
+
}
|
357
|
+
|
358
|
+
return sqlite3_column_text([_statement statement], columnIdx);
|
359
|
+
}
|
360
|
+
|
361
|
+
- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName {
|
362
|
+
return [self UTF8StringForColumnIndex:[self columnIndexForName:columnName]];
|
363
|
+
}
|
364
|
+
|
365
|
+
- (id)objectForColumnIndex:(int)columnIdx {
|
366
|
+
int columnType = sqlite3_column_type([_statement statement], columnIdx);
|
367
|
+
|
368
|
+
id returnValue = nil;
|
369
|
+
|
370
|
+
if (columnType == SQLITE_INTEGER) {
|
371
|
+
returnValue = [NSNumber numberWithLongLong:[self longLongIntForColumnIndex:columnIdx]];
|
372
|
+
}
|
373
|
+
else if (columnType == SQLITE_FLOAT) {
|
374
|
+
returnValue = [NSNumber numberWithDouble:[self doubleForColumnIndex:columnIdx]];
|
375
|
+
}
|
376
|
+
else if (columnType == SQLITE_BLOB) {
|
377
|
+
returnValue = [self dataForColumnIndex:columnIdx];
|
378
|
+
}
|
379
|
+
else {
|
380
|
+
//default to a string for everything else
|
381
|
+
returnValue = [self stringForColumnIndex:columnIdx];
|
382
|
+
}
|
383
|
+
|
384
|
+
if (returnValue == nil) {
|
385
|
+
returnValue = [NSNull null];
|
386
|
+
}
|
387
|
+
|
388
|
+
return returnValue;
|
389
|
+
}
|
390
|
+
|
391
|
+
- (id)objectForColumnName:(NSString*)columnName {
|
392
|
+
return [self objectForColumnIndex:[self columnIndexForName:columnName]];
|
393
|
+
}
|
394
|
+
|
395
|
+
// returns autoreleased NSString containing the name of the column in the result set
|
396
|
+
- (NSString*)columnNameForIndex:(int)columnIdx {
|
397
|
+
return [NSString stringWithUTF8String: sqlite3_column_name([_statement statement], columnIdx)];
|
398
|
+
}
|
399
|
+
|
400
|
+
- (void)setParentDB:(FMDatabase *)newDb {
|
401
|
+
_parentDB = newDb;
|
402
|
+
}
|
403
|
+
|
404
|
+
- (id)objectAtIndexedSubscript:(int)columnIdx {
|
405
|
+
return [self objectForColumnIndex:columnIdx];
|
406
|
+
}
|
407
|
+
|
408
|
+
- (id)objectForKeyedSubscript:(NSString *)columnName {
|
409
|
+
return [self objectForColumnName:columnName];
|
410
|
+
}
|
411
|
+
|
412
|
+
|
413
|
+
@end
|