Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ccgus/fmdb.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ryan <robert.ryan@mindspring.com>2021-03-25 22:26:24 +0300
committerRobert Ryan <robert.ryan@mindspring.com>2021-03-25 22:26:24 +0300
commitc183a1fdce904a188b54ea5864476e4fffb148b2 (patch)
tree78c745cd2e97632aa4cf2484209bd0afcf1e3575
parent3e5efdf6690cf7dce0a914c370507deee8740d33 (diff)
Add typeForColumn functions
* Add `typeForColumn` and `typeForColumnIndex` methods and tests * Update warnings in `dataForColumn` and `dataForColumnIndex` to describe SQLite behavior re zero-length blobs * Bump version to 2.7.8 This should permit accurate handling of zero-length BLOBs, e.g., in Swift: ```swift let fileURL = URL(fileURLWithPath: NSTemporaryDirectory()) .appendingPathComponent("test.sqlite") do { let db = FMDatabase(url: fileURL) db.open() try db.executeUpdate("CREATE TABLE test (data BLOB)", values: nil) let data = "foo".data(using: .utf8)! let sql = "INSERT INTO test (data) VALUES (?)" try db.executeUpdate(sql, values: [data]) try db.executeUpdate(sql, values: [Data()]) try db.executeUpdate(sql, values: [NSNull()]) let rs = try db.executeQuery("SELECT * FROM test", values: nil) while rs.next() { let type = rs.type(forColumnIndex: 0) switch type { case .blob: if let data = rs.data(forColumnIndex: 0) { print("blob with \(data.count) bytes") } else { print("blob but no data") } case .null: print("Null") default: print("type is \(type)") } } } catch { print(error) } ``` That will produce: ``` blob with 3 bytes blob but no data Null ```
-rw-r--r--CHANGES_AND_TODO_LIST.txt3
-rw-r--r--FMDB.podspec2
-rw-r--r--README.markdown2
-rw-r--r--Tests/FMDatabaseTests.m12
-rw-r--r--Tests/FMResultSetTests.m37
-rw-r--r--fmdb.xcodeproj/project.pbxproj4
-rw-r--r--fmdb.xcodeproj/xcshareddata/xcschemes/FMDB MacOS.xcscheme2
-rw-r--r--fmdb.xcodeproj/xcshareddata/xcschemes/FMDB iOS.xcscheme2
-rw-r--r--fmdb.xcodeproj/xcshareddata/xcschemes/FMDB watchOS.xcscheme11
-rw-r--r--src/fmdb/FMDatabase.h10
-rw-r--r--src/fmdb/FMDatabase.m2
-rw-r--r--src/fmdb/FMResultSet.h35
-rw-r--r--src/fmdb/FMResultSet.m8
-rw-r--r--src/fmdb/Info.plist2
14 files changed, 101 insertions, 31 deletions
diff --git a/CHANGES_AND_TODO_LIST.txt b/CHANGES_AND_TODO_LIST.txt
index 0783142..7e1ab37 100644
--- a/CHANGES_AND_TODO_LIST.txt
+++ b/CHANGES_AND_TODO_LIST.txt
@@ -3,6 +3,9 @@ Zip, nada, zilch. Got any ideas?
If you would like to contribute some code ... awesome! I just ask that you make it conform to the coding conventions already set in here, and to add the necessary of tests for your new code to tests target. And of course, the code should be of general use to more than just a couple of folks. Send your patches to gus@flyingmeat.com.
+2020.03.25 Version 2.7.8
+ Add `valueForColumn` functions to expose `sqlite3_column_type`. Add comments to `dataForColumn` re SQL behavior of zero-length BLOBs.
+
2020.05.06 Version 2.7.7
Add `prepare` and `bind` methods so you can prepare a statement once and bind values repeatedly.
diff --git a/FMDB.podspec b/FMDB.podspec
index 62859bc..6f91084 100644
--- a/FMDB.podspec
+++ b/FMDB.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'FMDB'
- s.version = '2.7.7'
+ s.version = '2.7.8'
s.summary = 'A Cocoa / Objective-C wrapper around SQLite.'
s.homepage = 'https://github.com/ccgus/fmdb'
s.license = 'MIT'
diff --git a/README.markdown b/README.markdown
index c1fef18..6aa06ed 100644
--- a/README.markdown
+++ b/README.markdown
@@ -78,7 +78,7 @@ Declare FMDB as a package dependency.
.package(
name: "FMDB",
url: "https://github.com/ccgus/fmdb",
- .upToNextMinor(from: "2.7.7")),
+ .upToNextMinor(from: "2.7.8")),
```
Use FMDB in target dependencies
diff --git a/Tests/FMDatabaseTests.m b/Tests/FMDatabaseTests.m
index 8ca2df5..0378741 100644
--- a/Tests/FMDatabaseTests.m
+++ b/Tests/FMDatabaseTests.m
@@ -1123,12 +1123,16 @@
}
-- (void)testVersionNumber {
- XCTAssertEqual([FMDatabase FMDBVersion], 0x0277); // this is going to break everytime we bump it.
-}
+/* This is deprecated, and as such, should be excluded from tests
+ *
+ * - (void)testVersionNumber {
+ * XCTAssertEqual([FMDatabase FMDBVersion], 0x0278); // this is going to break every time we bump it.
+ * }
+ *
+ */
- (void)testUserVersion {
- NSComparisonResult result = [[FMDatabase FMDBUserVersion] compare:@"2.7.7" options:NSNumericSearch];
+ NSComparisonResult result = [[FMDatabase FMDBUserVersion] compare:@"2.7.8" options:NSNumericSearch];
XCTAssertEqual(result, NSOrderedSame);
}
diff --git a/Tests/FMResultSetTests.m b/Tests/FMResultSetTests.m
index fdc7450..d646218 100644
--- a/Tests/FMResultSetTests.m
+++ b/Tests/FMResultSetTests.m
@@ -8,7 +8,6 @@
#import "FMDBTempDBTests.h"
#import "FMDatabase.h"
-#import "FMResultSet.h"
#if FMDB_SQLITE_STANDALONE
#import <sqlite3/sqlite3.h>
@@ -93,4 +92,40 @@
XCTAssertEqual(error.code, SQLITE_MISUSE, @"SQLITE_MISUSE should be the last error");
}
+- (void)testColumnTypes
+{
+ [self.db executeUpdate:@"CREATE TABLE testTable (intValue INTEGER, floatValue FLOAT, textValue TEXT, blobValue BLOB)"];
+ NSString *sql = @"INSERT INTO testTable (intValue, floatValue, textValue, blobValue) VALUES (?, ?, ?, ?)";
+ NSError *error;
+ NSData *data = [@"foo" dataUsingEncoding:NSUTF8StringEncoding];
+ NSData *zeroLengthData = [NSData data];
+ NSNull *null = [NSNull null];
+ [self.db executeUpdate:sql values:@[@42, @M_PI, @"test", data] error:&error];
+ [self.db executeUpdate:sql values:@[null, null, null, null] error:&error];
+ [self.db executeUpdate:sql values:@[null, null, null, zeroLengthData] error:&error];
+
+ FMResultSet *resultSet = [self.db executeQuery:@"SELECT * FROM testTable"];
+ XCTAssertNotNil(resultSet);
+
+ XCTAssertTrue([resultSet next]);
+ XCTAssertEqual([resultSet typeForColumn:@"intValue"], SqliteValueTypeInteger);
+ XCTAssertEqual([resultSet typeForColumn:@"floatValue"], SqliteValueTypeFloat);
+ XCTAssertEqual([resultSet typeForColumn:@"textValue"], SqliteValueTypeText);
+ XCTAssertEqual([resultSet typeForColumn:@"blobValue"], SqliteValueTypeBlob);
+ XCTAssertNotNil([resultSet dataForColumn:@"blobValue"]);
+
+ XCTAssertTrue([resultSet next]);
+ XCTAssertEqual([resultSet typeForColumn:@"intValue"], SqliteValueTypeNull);
+ XCTAssertEqual([resultSet typeForColumn:@"floatValue"], SqliteValueTypeNull);
+ XCTAssertEqual([resultSet typeForColumn:@"textValue"], SqliteValueTypeNull);
+ XCTAssertEqual([resultSet typeForColumn:@"blobValue"], SqliteValueTypeNull);
+ XCTAssertNil([resultSet dataForColumn:@"blobValue"]);
+
+ XCTAssertTrue([resultSet next]);
+ XCTAssertEqual([resultSet typeForColumn:@"blobValue"], SqliteValueTypeBlob);
+ XCTAssertNil([resultSet dataForColumn:@"blobValue"]);
+
+ [resultSet close];
+}
+
@end
diff --git a/fmdb.xcodeproj/project.pbxproj b/fmdb.xcodeproj/project.pbxproj
index da1896c..00e2a50 100644
--- a/fmdb.xcodeproj/project.pbxproj
+++ b/fmdb.xcodeproj/project.pbxproj
@@ -606,7 +606,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
- LastUpgradeCheck = 1140;
+ LastUpgradeCheck = 1240;
TargetAttributes = {
83C73EFD1C326AB000FFC730 = {
CreatedOnToolsVersion = 7.2;
@@ -1106,6 +1106,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ MARKETING_VERSION = 2.7.8;
MTL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "com.flyingmeat.FMDB-iOS";
PRODUCT_NAME = FMDB;
@@ -1147,6 +1148,7 @@
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
+ MARKETING_VERSION = 2.7.8;
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "com.flyingmeat.FMDB-iOS";
PRODUCT_NAME = FMDB;
diff --git a/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB MacOS.xcscheme b/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB MacOS.xcscheme
index d55ae5f..baa0cab 100644
--- a/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB MacOS.xcscheme
+++ b/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB MacOS.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "1140"
+ LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
diff --git a/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB iOS.xcscheme b/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB iOS.xcscheme
index ca61f31..70ed170 100644
--- a/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB iOS.xcscheme
+++ b/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB iOS.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "1140"
+ LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
diff --git a/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB watchOS.xcscheme b/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB watchOS.xcscheme
index 9b880e9..3453c82 100644
--- a/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB watchOS.xcscheme
+++ b/fmdb.xcodeproj/xcshareddata/xcschemes/FMDB watchOS.xcscheme
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "1140"
+ LastUpgradeVersion = "1240"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -27,15 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
- <MacroExpansion>
- <BuildableReference
- BuildableIdentifier = "primary"
- BlueprintIdentifier = "83C73EFD1C326AB000FFC730"
- BuildableName = "FMDB.framework"
- BlueprintName = "FMDB iOS"
- ReferencedContainer = "container:fmdb.xcodeproj">
- </BuildableReference>
- </MacroExpansion>
<Testables>
</Testables>
</TestAction>
diff --git a/src/fmdb/FMDatabase.h b/src/fmdb/FMDatabase.h
index 44e9df7..2a4ead2 100644
--- a/src/fmdb/FMDatabase.h
+++ b/src/fmdb/FMDatabase.h
@@ -1123,7 +1123,7 @@ func executeUpdate(sql: String, values: [Any]?) throws -> Bool { }
+ (NSString*)sqliteLibVersion;
-/// The FMDB version number as a string in the form of @c "2.7.7" .
+/// The FMDB version number as a string in the form of @c "2.7.8" .
///
/// If you want to compare version number strings, you can use NSNumericSearch option:
///
@@ -1194,14 +1194,6 @@ NSAssert(rs, @"Error %@", [db lastErrorMessage]);
- (void)makeFunctionNamed:(NSString *)name maximumArguments:(int)count withBlock:(void (^)(void *context, int argc, void * _Nonnull * _Nonnull argv))block __deprecated_msg("Use makeFunctionNamed:arguments:block:");
-typedef NS_ENUM(int, SqliteValueType) {
- SqliteValueTypeInteger = 1,
- SqliteValueTypeFloat = 2,
- SqliteValueTypeText = 3,
- SqliteValueTypeBlob = 4,
- SqliteValueTypeNull = 5
-};
-
- (SqliteValueType)valueType:(void *)argv;
/**
diff --git a/src/fmdb/FMDatabase.m b/src/fmdb/FMDatabase.m
index b03e3a8..d2fdfc0 100644
--- a/src/fmdb/FMDatabase.m
+++ b/src/fmdb/FMDatabase.m
@@ -112,7 +112,7 @@ NS_ASSUME_NONNULL_END
}
+ (NSString*)FMDBUserVersion {
- return @"2.7.7";
+ return @"2.7.8";
}
+ (SInt32)FMDBVersion {
diff --git a/src/fmdb/FMResultSet.h b/src/fmdb/FMResultSet.h
index bf48e6e..0832451 100644
--- a/src/fmdb/FMResultSet.h
+++ b/src/fmdb/FMResultSet.h
@@ -17,6 +17,16 @@ NS_ASSUME_NONNULL_BEGIN
@class FMDatabase;
@class FMStatement;
+/** Types for columns in a result set.
+ */
+typedef NS_ENUM(int, SqliteValueType) {
+ SqliteValueTypeInteger = 1,
+ SqliteValueTypeFloat = 2,
+ SqliteValueTypeText = 3,
+ SqliteValueTypeBlob = 4,
+ SqliteValueTypeNull = 5
+};
+
/** Represents the results of executing a query on an @c FMDatabase .
See also
@@ -304,6 +314,9 @@ NS_ASSUME_NONNULL_BEGIN
@param columnIdx Zero-based index for column.
+ @warning For zero length BLOBs, this will return `nil`. Use `typeForColumn` to determine whether this was really a zero
+ length BLOB or `NULL`.
+
@return Data value of the result set's column.
*/
@@ -313,6 +326,9 @@ NS_ASSUME_NONNULL_BEGIN
@param columnName @c NSString value of the name of the column.
+ @warning For zero length BLOBs, this will return `nil`. Use `typeForColumnIndex` to determine whether this was really a zero
+ length BLOB or `NULL`.
+
@return `(const unsigned char *)` value of the result set's column.
*/
@@ -342,6 +358,25 @@ NS_ASSUME_NONNULL_BEGIN
- (id _Nullable)objectForColumnName:(NSString*)columnName __deprecated_msg("Use objectForColumn instead");
+/** Column type by column name.
+
+ @param columnName Name of the column.
+
+ @return The `SqliteValueType` of the value in this column.
+ */
+
+- (SqliteValueType)typeForColumn:(NSString*)columnName;
+
+/** Column type by column index.
+
+ @param columnIdx Index of the column.
+
+ @return The `SqliteValueType` of the value in this column.
+ */
+
+- (SqliteValueType)typeForColumnIndex:(int)columnIdx;
+
+
/** Result set object for column.
@param columnIdx Zero-based index for column.
diff --git a/src/fmdb/FMResultSet.m b/src/fmdb/FMResultSet.m
index 1f32473..f8ce917 100644
--- a/src/fmdb/FMResultSet.m
+++ b/src/fmdb/FMResultSet.m
@@ -432,6 +432,14 @@
return [self objectForColumnIndex:[self columnIndexForName:columnName]];
}
+- (SqliteValueType)typeForColumn:(NSString*)columnName {
+ return sqlite3_column_type([_statement statement], [self columnIndexForName:columnName]);
+}
+
+- (SqliteValueType)typeForColumnIndex:(int)columnIdx {
+ return sqlite3_column_type([_statement statement], columnIdx);
+}
+
// returns autoreleased NSString containing the name of the column in the result set
- (NSString*)columnNameForIndex:(int)columnIdx {
return [NSString stringWithUTF8String: sqlite3_column_name([_statement statement], columnIdx)];
diff --git a/src/fmdb/Info.plist b/src/fmdb/Info.plist
index 502f085..ca23c84 100644
--- a/src/fmdb/Info.plist
+++ b/src/fmdb/Info.plist
@@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
- <string>2.7.7</string>
+ <string>$(MARKETING_VERSION)</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>