Skip to content

Commit e9385a4

Browse files
committed
FMDB update
1 parent 9595411 commit e9385a4

25 files changed

+2800
-127
lines changed

LKDBHelper.xcodeproj/project.pbxproj

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
3656FD991C3A52C0008B1473 /* FMDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 3656FD861C3A52C0008B1473 /* FMDatabase.m */; };
11+
3656FD9A1C3A52C0008B1473 /* FMDatabaseAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3656FD881C3A52C0008B1473 /* FMDatabaseAdditions.m */; };
12+
3656FD9B1C3A52C0008B1473 /* FMDatabasePool.m in Sources */ = {isa = PBXBuildFile; fileRef = 3656FD8A1C3A52C0008B1473 /* FMDatabasePool.m */; };
13+
3656FD9C1C3A52C0008B1473 /* FMDatabaseQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 3656FD8C1C3A52C0008B1473 /* FMDatabaseQueue.m */; };
14+
3656FD9D1C3A52C0008B1473 /* FMResultSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 3656FD8F1C3A52C0008B1473 /* FMResultSet.m */; };
15+
3656FD9E1C3A52C0008B1473 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3656FD901C3A52C0008B1473 /* Info.plist */; };
1016
5303B79B178FEFB5007731A0 /* LKTestModels.m in Sources */ = {isa = PBXBuildFile; fileRef = 5303B79A178FEFB5007731A0 /* LKTestModels.m */; };
1117
5311E11C1762DEFE00ADBB7D /* NSObject+LKDBHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 5311E11B1762DEFE00ADBB7D /* NSObject+LKDBHelper.m */; };
1218
53226E01171B9E5A00B1A490 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 53226E00171B9E5A00B1A490 /* UIKit.framework */; };
@@ -18,12 +24,6 @@
1824
53226E13171B9E5B00B1A490 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = 53226E12171B9E5B00B1A490 /* Default.png */; };
1925
53226E15171B9E5B00B1A490 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 53226E14171B9E5B00B1A490 /* [email protected] */; };
2026
53226E17171B9E5B00B1A490 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 53226E16171B9E5B00B1A490 /* [email protected] */; };
21-
53226E32171BA09F00B1A490 /* FMDatabase+InMemoryOnDiskIO.m in Sources */ = {isa = PBXBuildFile; fileRef = 53226E26171BA09F00B1A490 /* FMDatabase+InMemoryOnDiskIO.m */; };
22-
53226E33171BA09F00B1A490 /* FMDatabase.m in Sources */ = {isa = PBXBuildFile; fileRef = 53226E29171BA09F00B1A490 /* FMDatabase.m */; };
23-
53226E34171BA09F00B1A490 /* FMDatabaseAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 53226E2B171BA09F00B1A490 /* FMDatabaseAdditions.m */; };
24-
53226E35171BA09F00B1A490 /* FMDatabasePool.m in Sources */ = {isa = PBXBuildFile; fileRef = 53226E2D171BA09F00B1A490 /* FMDatabasePool.m */; };
25-
53226E36171BA09F00B1A490 /* FMDatabaseQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 53226E2F171BA09F00B1A490 /* FMDatabaseQueue.m */; };
26-
53226E37171BA09F00B1A490 /* FMResultSet.m in Sources */ = {isa = PBXBuildFile; fileRef = 53226E31171BA09F00B1A490 /* FMResultSet.m */; };
2727
53226E3F171BA16E00B1A490 /* LKDBHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 53226E3D171BA16E00B1A490 /* LKDBHelper.m */; };
2828
53226E45171BA44100B1A490 /* LKDBUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 53226E44171BA44100B1A490 /* LKDBUtils.m */; };
2929
53226E47171BFB6900B1A490 /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 53226E46171BFB6900B1A490 /* libsqlite3.dylib */; };
@@ -33,6 +33,18 @@
3333
/* End PBXBuildFile section */
3434

3535
/* Begin PBXFileReference section */
36+
3656FD851C3A52C0008B1473 /* FMDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabase.h; sourceTree = "<group>"; };
37+
3656FD861C3A52C0008B1473 /* FMDatabase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMDatabase.m; sourceTree = "<group>"; };
38+
3656FD871C3A52C0008B1473 /* FMDatabaseAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabaseAdditions.h; sourceTree = "<group>"; };
39+
3656FD881C3A52C0008B1473 /* FMDatabaseAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMDatabaseAdditions.m; sourceTree = "<group>"; };
40+
3656FD891C3A52C0008B1473 /* FMDatabasePool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabasePool.h; sourceTree = "<group>"; };
41+
3656FD8A1C3A52C0008B1473 /* FMDatabasePool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMDatabasePool.m; sourceTree = "<group>"; };
42+
3656FD8B1C3A52C0008B1473 /* FMDatabaseQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabaseQueue.h; sourceTree = "<group>"; };
43+
3656FD8C1C3A52C0008B1473 /* FMDatabaseQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMDatabaseQueue.m; sourceTree = "<group>"; };
44+
3656FD8D1C3A52C0008B1473 /* FMDB.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDB.h; sourceTree = "<group>"; };
45+
3656FD8E1C3A52C0008B1473 /* FMResultSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMResultSet.h; sourceTree = "<group>"; };
46+
3656FD8F1C3A52C0008B1473 /* FMResultSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMResultSet.m; sourceTree = "<group>"; };
47+
3656FD901C3A52C0008B1473 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3648
5303B799178FEFB5007731A0 /* LKTestModels.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKTestModels.h; sourceTree = "<group>"; };
3749
5303B79A178FEFB5007731A0 /* LKTestModels.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKTestModels.m; sourceTree = "<group>"; };
3850
5311E11A1762DEFE00ADBB7D /* NSObject+LKDBHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+LKDBHelper.h"; sourceTree = "<group>"; };
@@ -50,18 +62,6 @@
5062
53226E12171B9E5B00B1A490 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
5163
53226E14171B9E5B00B1A490 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
5264
53226E16171B9E5B00B1A490 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
53-
53226E25171BA09F00B1A490 /* FMDatabase+InMemoryOnDiskIO.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "FMDatabase+InMemoryOnDiskIO.h"; sourceTree = "<group>"; };
54-
53226E26171BA09F00B1A490 /* FMDatabase+InMemoryOnDiskIO.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "FMDatabase+InMemoryOnDiskIO.m"; sourceTree = "<group>"; };
55-
53226E28171BA09F00B1A490 /* FMDatabase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabase.h; sourceTree = "<group>"; };
56-
53226E29171BA09F00B1A490 /* FMDatabase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMDatabase.m; sourceTree = "<group>"; };
57-
53226E2A171BA09F00B1A490 /* FMDatabaseAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabaseAdditions.h; sourceTree = "<group>"; };
58-
53226E2B171BA09F00B1A490 /* FMDatabaseAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMDatabaseAdditions.m; sourceTree = "<group>"; };
59-
53226E2C171BA09F00B1A490 /* FMDatabasePool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabasePool.h; sourceTree = "<group>"; };
60-
53226E2D171BA09F00B1A490 /* FMDatabasePool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMDatabasePool.m; sourceTree = "<group>"; };
61-
53226E2E171BA09F00B1A490 /* FMDatabaseQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMDatabaseQueue.h; sourceTree = "<group>"; };
62-
53226E2F171BA09F00B1A490 /* FMDatabaseQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMDatabaseQueue.m; sourceTree = "<group>"; };
63-
53226E30171BA09F00B1A490 /* FMResultSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FMResultSet.h; sourceTree = "<group>"; };
64-
53226E31171BA09F00B1A490 /* FMResultSet.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FMResultSet.m; sourceTree = "<group>"; };
6565
53226E3C171BA16E00B1A490 /* LKDBHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKDBHelper.h; sourceTree = "<group>"; };
6666
53226E3D171BA16E00B1A490 /* LKDBHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LKDBHelper.m; sourceTree = "<group>"; };
6767
53226E43171BA44100B1A490 /* LKDBUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LKDBUtils.h; sourceTree = "<group>"; };
@@ -89,6 +89,33 @@
8989
/* End PBXFrameworksBuildPhase section */
9090

9191
/* Begin PBXGroup section */
92+
3656FD761C3A52C0008B1473 /* src */ = {
93+
isa = PBXGroup;
94+
children = (
95+
3656FD841C3A52C0008B1473 /* fmdb */,
96+
);
97+
path = src;
98+
sourceTree = "<group>";
99+
};
100+
3656FD841C3A52C0008B1473 /* fmdb */ = {
101+
isa = PBXGroup;
102+
children = (
103+
3656FD851C3A52C0008B1473 /* FMDatabase.h */,
104+
3656FD861C3A52C0008B1473 /* FMDatabase.m */,
105+
3656FD871C3A52C0008B1473 /* FMDatabaseAdditions.h */,
106+
3656FD881C3A52C0008B1473 /* FMDatabaseAdditions.m */,
107+
3656FD891C3A52C0008B1473 /* FMDatabasePool.h */,
108+
3656FD8A1C3A52C0008B1473 /* FMDatabasePool.m */,
109+
3656FD8B1C3A52C0008B1473 /* FMDatabaseQueue.h */,
110+
3656FD8C1C3A52C0008B1473 /* FMDatabaseQueue.m */,
111+
3656FD8D1C3A52C0008B1473 /* FMDB.h */,
112+
3656FD8E1C3A52C0008B1473 /* FMResultSet.h */,
113+
3656FD8F1C3A52C0008B1473 /* FMResultSet.m */,
114+
3656FD901C3A52C0008B1473 /* Info.plist */,
115+
);
116+
path = fmdb;
117+
sourceTree = "<group>";
118+
};
92119
53226DF4171B9E5A00B1A490 = {
93120
isa = PBXGroup;
94121
children = (
@@ -149,38 +176,11 @@
149176
53226E23171BA09F00B1A490 /* FMDB */ = {
150177
isa = PBXGroup;
151178
children = (
152-
53226E24171BA09F00B1A490 /* extra */,
153-
53226E27171BA09F00B1A490 /* src */,
179+
3656FD761C3A52C0008B1473 /* src */,
154180
);
155181
path = FMDB;
156182
sourceTree = "<group>";
157183
};
158-
53226E24171BA09F00B1A490 /* extra */ = {
159-
isa = PBXGroup;
160-
children = (
161-
53226E25171BA09F00B1A490 /* FMDatabase+InMemoryOnDiskIO.h */,
162-
53226E26171BA09F00B1A490 /* FMDatabase+InMemoryOnDiskIO.m */,
163-
);
164-
path = extra;
165-
sourceTree = "<group>";
166-
};
167-
53226E27171BA09F00B1A490 /* src */ = {
168-
isa = PBXGroup;
169-
children = (
170-
53226E28171BA09F00B1A490 /* FMDatabase.h */,
171-
53226E29171BA09F00B1A490 /* FMDatabase.m */,
172-
53226E2A171BA09F00B1A490 /* FMDatabaseAdditions.h */,
173-
53226E2B171BA09F00B1A490 /* FMDatabaseAdditions.m */,
174-
53226E2C171BA09F00B1A490 /* FMDatabasePool.h */,
175-
53226E2D171BA09F00B1A490 /* FMDatabasePool.m */,
176-
53226E2E171BA09F00B1A490 /* FMDatabaseQueue.h */,
177-
53226E2F171BA09F00B1A490 /* FMDatabaseQueue.m */,
178-
53226E30171BA09F00B1A490 /* FMResultSet.h */,
179-
53226E31171BA09F00B1A490 /* FMResultSet.m */,
180-
);
181-
path = src;
182-
sourceTree = "<group>";
183-
};
184184
53226E39171BA10800B1A490 /* Helper */ = {
185185
isa = PBXGroup;
186186
children = (
@@ -252,6 +252,7 @@
252252
files = (
253253
53226E0B171B9E5B00B1A490 /* InfoPlist.strings in Resources */,
254254
53226E13171B9E5B00B1A490 /* Default.png in Resources */,
255+
3656FD9E1C3A52C0008B1473 /* Info.plist in Resources */,
255256
53226E15171B9E5B00B1A490 /* [email protected] in Resources */,
256257
53226E17171B9E5B00B1A490 /* [email protected] in Resources */,
257258
53226E4C171C207F00B1A490 /* 41.png in Resources */,
@@ -266,19 +267,18 @@
266267
buildActionMask = 2147483647;
267268
files = (
268269
53226E0D171B9E5B00B1A490 /* main.m in Sources */,
270+
3656FD991C3A52C0008B1473 /* FMDatabase.m in Sources */,
269271
53226E11171B9E5B00B1A490 /* LKAppDelegate.m in Sources */,
270-
53226E32171BA09F00B1A490 /* FMDatabase+InMemoryOnDiskIO.m in Sources */,
271-
53226E33171BA09F00B1A490 /* FMDatabase.m in Sources */,
272-
53226E34171BA09F00B1A490 /* FMDatabaseAdditions.m in Sources */,
273-
53226E35171BA09F00B1A490 /* FMDatabasePool.m in Sources */,
274-
53226E36171BA09F00B1A490 /* FMDatabaseQueue.m in Sources */,
275-
53226E37171BA09F00B1A490 /* FMResultSet.m in Sources */,
272+
3656FD9D1C3A52C0008B1473 /* FMResultSet.m in Sources */,
276273
53226E3F171BA16E00B1A490 /* LKDBHelper.m in Sources */,
277274
53226E45171BA44100B1A490 /* LKDBUtils.m in Sources */,
278275
53226E4A171C1F0400B1A490 /* NSObject+LKModel.m in Sources */,
279276
5311E11C1762DEFE00ADBB7D /* NSObject+LKDBHelper.m in Sources */,
280277
534D38D81772FA6A00E24E96 /* LKDB+Mapping.m in Sources */,
278+
3656FD9B1C3A52C0008B1473 /* FMDatabasePool.m in Sources */,
279+
3656FD9C1C3A52C0008B1473 /* FMDatabaseQueue.m in Sources */,
281280
5303B79B178FEFB5007731A0 /* LKTestModels.m in Sources */,
281+
3656FD9A1C3A52C0008B1473 /* FMDatabaseAdditions.m in Sources */,
282282
);
283283
runOnlyForDeploymentPostprocessing = 0;
284284
};
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//
2+
// FMDatabaseAdditionsVariadic.swift
3+
// FMDB
4+
//
5+
6+
import Foundation
7+
8+
extension FMDatabase {
9+
10+
/// Private generic function used for the variadic renditions of the FMDatabaseAdditions methods
11+
///
12+
/// - parameter sql: The SQL statement to be used.
13+
/// - parameter values: The NSArray of the arguments to be bound to the ? placeholders in the SQL.
14+
/// - parameter completionHandler: The closure to be used to call the appropriate FMDatabase method to return the desired value.
15+
///
16+
/// - returns: This returns the T value if value is found. Returns nil if column is NULL or upon error.
17+
18+
private func valueForQuery<T>(sql: String, values: [AnyObject]?, completionHandler:(FMResultSet)->(T!)) -> T! {
19+
var result: T!
20+
21+
if let rs = executeQuery(sql, withArgumentsInArray: values) {
22+
if rs.next() {
23+
let obj: AnyObject! = rs.objectForColumnIndex(0)
24+
if !(obj is NSNull) {
25+
result = completionHandler(rs)
26+
}
27+
}
28+
rs.close()
29+
}
30+
31+
return result
32+
}
33+
34+
/// This is a rendition of stringForQuery that handles Swift variadic parameters
35+
/// for the values to be bound to the ? placeholders in the SQL.
36+
///
37+
/// - parameter sql: The SQL statement to be used.
38+
/// - parameter values: The values to be bound to the ? placeholders
39+
///
40+
/// - returns: This returns string value if value is found. Returns nil if column is NULL or upon error.
41+
42+
func stringForQuery(sql: String, _ values: AnyObject...) -> String! {
43+
return valueForQuery(sql, values: values) { $0.stringForColumnIndex(0) }
44+
}
45+
46+
/// This is a rendition of intForQuery that handles Swift variadic parameters
47+
/// for the values to be bound to the ? placeholders in the SQL.
48+
///
49+
/// - parameter sql: The SQL statement to be used.
50+
/// - parameter values: The values to be bound to the ? placeholders
51+
///
52+
/// - returns: This returns integer value if value is found. Returns nil if column is NULL or upon error.
53+
54+
func intForQuery(sql: String, _ values: AnyObject...) -> Int32! {
55+
return valueForQuery(sql, values: values) { $0.intForColumnIndex(0) }
56+
}
57+
58+
/// This is a rendition of longForQuery that handles Swift variadic parameters
59+
/// for the values to be bound to the ? placeholders in the SQL.
60+
///
61+
/// - parameter sql: The SQL statement to be used.
62+
/// - parameter values: The values to be bound to the ? placeholders
63+
///
64+
/// - returns: This returns long value if value is found. Returns nil if column is NULL or upon error.
65+
66+
func longForQuery(sql: String, _ values: AnyObject...) -> Int! {
67+
return valueForQuery(sql, values: values) { $0.longForColumnIndex(0) }
68+
}
69+
70+
/// This is a rendition of boolForQuery that handles Swift variadic parameters
71+
/// for the values to be bound to the ? placeholders in the SQL.
72+
///
73+
/// - parameter sql: The SQL statement to be used.
74+
/// - parameter values: The values to be bound to the ? placeholders
75+
///
76+
/// - returns: This returns Bool value if value is found. Returns nil if column is NULL or upon error.
77+
78+
func boolForQuery(sql: String, _ values: AnyObject...) -> Bool! {
79+
return valueForQuery(sql, values: values) { $0.boolForColumnIndex(0) }
80+
}
81+
82+
/// This is a rendition of doubleForQuery that handles Swift variadic parameters
83+
/// for the values to be bound to the ? placeholders in the SQL.
84+
///
85+
/// - parameter sql: The SQL statement to be used.
86+
/// - parameter values: The values to be bound to the ? placeholders
87+
///
88+
/// - returns: This returns Double value if value is found. Returns nil if column is NULL or upon error.
89+
90+
func doubleForQuery(sql: String, _ values: AnyObject...) -> Double! {
91+
return valueForQuery(sql, values: values) { $0.doubleForColumnIndex(0) }
92+
}
93+
94+
/// This is a rendition of dateForQuery that handles Swift variadic parameters
95+
/// for the values to be bound to the ? placeholders in the SQL.
96+
///
97+
/// - parameter sql: The SQL statement to be used.
98+
/// - parameter values: The values to be bound to the ? placeholders
99+
///
100+
/// - returns: This returns NSDate value if value is found. Returns nil if column is NULL or upon error.
101+
102+
func dateForQuery(sql: String, _ values: AnyObject...) -> NSDate! {
103+
return valueForQuery(sql, values: values) { $0.dateForColumnIndex(0) }
104+
}
105+
106+
/// This is a rendition of dataForQuery that handles Swift variadic parameters
107+
/// for the values to be bound to the ? placeholders in the SQL.
108+
///
109+
/// - parameter sql: The SQL statement to be used.
110+
/// - parameter values: The values to be bound to the ? placeholders
111+
///
112+
/// - returns: This returns NSData value if value is found. Returns nil if column is NULL or upon error.
113+
114+
func dataForQuery(sql: String, _ values: AnyObject...) -> NSData! {
115+
return valueForQuery(sql, values: values) { $0.dataForColumnIndex(0) }
116+
}
117+
}

0 commit comments

Comments
 (0)