Kaynağa Gözat

Added a version to the code, and added an API to it as well.

August Mueller 11 yıl önce
ebeveyn
işleme
5e21152188
3 değiştirilmiş dosya ile 41 ekleme ve 0 silme
  1. 4 0
      Tests/FMDatabaseTests.m
  2. 5 0
      src/fmdb/FMDatabase.h
  3. 32 0
      src/fmdb/FMDatabase.m

+ 4 - 0
Tests/FMDatabaseTests.m

@@ -832,6 +832,10 @@ - (void)testApplicationID
 }
 #endif
 
+- (void)testVersionNumber {
+    XCTAssertTrue([FMDatabase FMDBVersion] == 0x0230); // this is going to break everytime we bump it.
+}
+
 - (void)testExecuteStatements
 {
     BOOL success;

+ 5 - 0
src/fmdb/FMDatabase.h

@@ -855,6 +855,11 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
 + (NSString*)sqliteLibVersion;
 
 
++ (NSString*)FMDBUserVersion;
+
++ (SInt32)FMDBVersion;
+
+
 ///------------------------
 /// @name Make SQL function
 ///------------------------

+ 32 - 0
src/fmdb/FMDatabase.m

@@ -66,6 +66,38 @@ - (NSString *)databasePath {
     return _databasePath;
 }
 
++ (NSString*)FMDBUserVersion {
+    return @"2.3";
+}
+
+// returns 0x0230 for version 2.3.  This makes it super easy to do things like:
+// /* need to make sure to do X with FMDB version 2.3 or later */
+// if ([FMDatabase FMDBVersion] >= 0x0230) { … }
+
++ (SInt32)FMDBVersion {
+    
+    // we go through these hoops so that we only have to change the version number in a single spot.
+    static dispatch_once_t once;
+    static SInt32 FMDBVersionVal = 0;
+    
+    dispatch_once(&once, ^{
+        NSString *prodVersion = [self FMDBUserVersion];
+        
+        if ([[prodVersion componentsSeparatedByString:@"."] count] < 3) {
+            prodVersion = [prodVersion stringByAppendingString:@".0"];
+        }
+        
+        NSString *junk = [prodVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
+        
+        char *e = nil;
+        FMDBVersionVal = (int) strtoul([junk UTF8String], &e, 16);
+        
+    });
+    
+
+    return FMDBVersionVal;
+}
+
 #pragma mark SQLite information
 
 + (NSString*)sqliteLibVersion {