Переглянути джерело

Revert "Framework branch"

August "Gus" Mueller 10 роки тому
батько
коміт
5eeda4f0b5

+ 0 - 1
FMDB.podspec

@@ -12,7 +12,6 @@ Pod::Spec.new do |s|
 
   s.subspec 'common' do |ss|
     ss.source_files = 'src/fmdb/FM*.{h,m}'
-    ss.private_header_files = 'src/fmdb/*Private.h'
     ss.exclude_files = 'src/fmdb.m'
   end
 

+ 1 - 72
README.markdown

@@ -319,78 +319,6 @@ if let rs = database.executeQuery("select x, y, z from test", withArgumentsInArr
 database.close()
 ```
 
-Then you can bring it up on the FMDB mailing list by showing your nice and compact FMDBReportABugFunction, or you can report the bug via the github FMDB bug reporter.
-
-## Using FMDB in a framework
-
-1. Clone FMDB repo.
-
-2. Switch to “framework” branch.
-
-3. In your project create a new target (“File” - “New” - “Target…”) and choose “Framework". Call this new target “FMDB” (and make sure to specify language of Objective-C, regardless of the base language for your main project)
-
-4. Copy the contents of the `src/fmdb` directory into your new framework target. **Do not copy the `FMDB.h` file, though.**
-
-5. Edit the `FMDB.h` file in the framework to include whatever headers you want, e.g. 
-
- ```//
-//  FMDB.h
-//  FMDB
-//
-//  Created by You on 8/2/15.
-//  Copyright (c) 2015 You. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-//! Project version number for FMDB.
-FOUNDATION_EXPORT double FMDBVersionNumber;
-
-//! Project version string for FMDB.
-FOUNDATION_EXPORT const unsigned char FMDBVersionString[];
-
-// In this header, you should import all the public headers of your framework using statements like #import <FMDB/PublicHeader.h>
-
-#import "FMDatabase.h"
-#import "FMResultSet.h"
-#import "FMDatabaseAdditions.h"
-#import "FMDatabaseQueue.h"
-```
-
-6. Whichever headers you include in this `FMDB.h` must be changed to “public” headers as discussed here: http://stackoverflow.com/a/24317456/1271826
-
-7. Remember to link the `libsqlite3.dylib` with your new FMDB framework target.
-
-8. You can now use this new FMDB framework from your main target. For example, in Swift:
-
-        import UIKit
-        import FMDB
-
-        class ViewController: UIViewController {
-
-            override func viewDidLoad() {
-                super.viewDidLoad()
-
-                let documents = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first as! String
-                let path = documents.stringByAppendingPathComponent("test.sqlite")
-                NSFileManager.defaultManager().removeItemAtPath(path, error: nil)
-
-                let queue = FMDatabaseQueue(path: path)
-
-                queue.inDatabase { db in
-                    db.executeUpdate("create table foo (bar text)", withArgumentsInArray: nil)
-                    db.executeUpdate("insert into foo (bar) values (?)", withArgumentsInArray: ["baz"])
-
-                    if let rs = db.executeQuery("select * from foo", withArgumentsInArray: nil) {
-                        while rs.next() {
-                            println(rs.resultDictionary())
-                        }
-                    }
-                }
-            }
-        }
-
-
 ## History
 
 The history and changes are availbe on its [GitHub page](https://github.com/ccgus/fmdb) and are summarized in the "CHANGES_AND_TODO_LIST.txt" file.
@@ -420,6 +348,7 @@ And we've even added a template function to main.m (FMDBReportABugFunction) in t
     * Make your query or update(s).
     * Add some assertions which demonstrate the bug.
 
+Then you can bring it up on the FMDB mailing list by showing your nice and compact FMDBReportABugFunction, or you can report the bug via the github FMDB bug reporter.
 
 **Optional:**
 

+ 0 - 6
fmdb.xcodeproj/project.pbxproj

@@ -16,7 +16,6 @@
 		6290CBB7188FE836009790F8 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6290CBB6188FE836009790F8 /* Foundation.framework */; };
 		67CB1E3019AD27D000A3CA7F /* FMDatabaseFTS3Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 67CB1E2F19AD27D000A3CA7F /* FMDatabaseFTS3Tests.m */; };
 		8314AF3318CD73D600EC0E25 /* FMDB.h in Headers */ = {isa = PBXBuildFile; fileRef = 8314AF3218CD73D600EC0E25 /* FMDB.h */; };
-		83D9D8CF1B6E7DC50083E17F /* FMDatabase+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 83D9D8CE1B6E7DC50083E17F /* FMDatabase+Private.h */; };
 		8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
 		8DD76F9F0486AA7600D96B5E /* fmdb.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859EA3029092ED04C91782 /* fmdb.1 */; };
 		BF5D041918416BB2008C5AA9 /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF5D041818416BB2008C5AA9 /* XCTest.framework */; };
@@ -100,8 +99,6 @@
 		831DE6FD175B7C9C001F7317 /* README.markdown */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.markdown; sourceTree = "<group>"; };
 		832F502419EC4C6B0087DCBF /* FMDatabaseVariadic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FMDatabaseVariadic.swift; path = "src/extra/Swift extensions/FMDatabaseVariadic.swift"; sourceTree = "<group>"; };
 		8352D5AC1A73DCEA003A8E09 /* FMDatabaseAdditionsVariadic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = FMDatabaseAdditionsVariadic.swift; path = "src/extra/Swift extensions/FMDatabaseAdditionsVariadic.swift"; sourceTree = "<group>"; };
-		83D9D8CE1B6E7DC50083E17F /* FMDatabase+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "FMDatabase+Private.h"; path = "src/fmdb/FMDatabase+Private.h"; sourceTree = "<group>"; };
-		83D9D8D01B6E7F6D0083E17F /* FMDB.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = FMDB.podspec; sourceTree = "<group>"; };
 		8DD76FA10486AA7600D96B5E /* fmdb */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fmdb; sourceTree = BUILT_PRODUCTS_DIR; };
 		BF5D041618416BB2008C5AA9 /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		BF5D041818416BB2008C5AA9 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
@@ -190,7 +187,6 @@
 				CC8C138B0E3135C400FBE1E7 /* LICENSE.txt */,
 				CC8C138A0E3135C400FBE1E7 /* CHANGES_AND_TODO_LIST.txt */,
 				CC8C138C0E3135C400FBE1E7 /* CONTRIBUTORS.txt */,
-				83D9D8D01B6E7F6D0083E17F /* FMDB.podspec */,
 				08FB7795FE84155DC02AAC07 /* Source */,
 				C6859EA2029092E104C91782 /* Documentation */,
 				08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
@@ -251,7 +247,6 @@
 				8314AF3218CD73D600EC0E25 /* FMDB.h */,
 				CCC24EBA0A13E34D00A6D3E3 /* FMDatabase.h */,
 				CCC24EBB0A13E34D00A6D3E3 /* FMDatabase.m */,
-				83D9D8CE1B6E7DC50083E17F /* FMDatabase+Private.h */,
 				CCC24EBF0A13E34D00A6D3E3 /* FMResultSet.h */,
 				CCC24EC00A13E34D00A6D3E3 /* FMResultSet.m */,
 				CC47A00D148581E9002CCDAB /* FMDatabaseQueue.h */,
@@ -356,7 +351,6 @@
 				EE42910712B42FC90088BD94 /* FMDatabase.h in Headers */,
 				EE42910612B42FC30088BD94 /* FMDatabaseAdditions.h in Headers */,
 				EE42910912B42FD00088BD94 /* FMResultSet.h in Headers */,
-				83D9D8CF1B6E7DC50083E17F /* FMDatabase+Private.h in Headers */,
 				8314AF3318CD73D600EC0E25 /* FMDB.h in Headers */,
 				CC9E4EBA13B31188005F9210 /* FMDatabasePool.h in Headers */,
 				CC47A00F148581E9002CCDAB /* FMDatabaseQueue.h in Headers */,

+ 0 - 39
src/fmdb/FMDatabase+Private.h

@@ -1,39 +0,0 @@
-//
-//  FMDatabase+Private.h
-//  deleteme2
-//
-//  Created by Robert Ryan on 8/2/15.
-//  Copyright (c) 2015 Robert Ryan. All rights reserved.
-//
-
-#ifndef deleteme2_FMDatabase_Private_h
-#define deleteme2_FMDatabase_Private_h
-
-#import <sqlite3.h>
-
-@class FMDatabase;
-@class FMStatement;
-
-@interface FMDatabase (Private)
-
-/** SQLite sqlite3
- 
- @see [`sqlite3`](http://www.sqlite.org/c3ref/sqlite3.html)
- */
-
-@property (nonatomic, assign, readonly) sqlite3 *db;
-
-@end
-
-@interface FMStatement (Private)
-
-/** SQLite sqlite3_stmt
- 
- @see [`sqlite3_stmt`](http://www.sqlite.org/c3ref/stmt.html)
- */
-
-@property (nonatomic, assign) sqlite3_stmt *statement;
-
-@end
-
-#endif

+ 12 - 6
src/fmdb/FMDatabase.h

@@ -1,4 +1,5 @@
 #import <Foundation/Foundation.h>
+#import "sqlite3.h"
 #import "FMResultSet.h"
 #import "FMDatabasePool.h"
 
@@ -72,6 +73,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
 
 @interface FMDatabase : NSObject  {
     
+    sqlite3*            _db;
     NSString*           _databasePath;
     BOOL                _logsErrors;
     BOOL                _crashOnErrors;
@@ -215,12 +217,12 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
  @see [sqlite3_open_v2()](http://sqlite.org/c3ref/open.html)
  @see open
  @see close
- 
- @warning Requires SQLite 3.5
  */
 
+#if SQLITE_VERSION_NUMBER >= 3005000
 - (BOOL)openWithFlags:(int)flags;
 - (BOOL)openWithFlags:(int)flags vfs:(NSString *)vfsName;
+#endif
 
 /** Closing a database connection
  
@@ -438,7 +440,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
 
  */
 
-- (long long int)lastInsertRowId;
+- (sqlite_int64)lastInsertRowId;
 
 /** The number of rows changed by prior SQL statement.
  
@@ -728,7 +730,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
  
  */
 
-- (void*)sqliteHandle;
+- (sqlite3*)sqliteHandle;
 
 
 ///-----------------------------
@@ -792,6 +794,8 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
 - (NSTimeInterval)maxBusyRetryTimeInterval;
 
 
+#if SQLITE_VERSION_NUMBER >= 3007000
+
 ///------------------
 /// @name Save points
 ///------------------
@@ -853,6 +857,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
 
 - (NSError*)inSavePoint:(void (^)(BOOL *rollback))block;
 
+#endif
 
 ///----------------------------
 /// @name SQLite library status
@@ -930,7 +935,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
  @see [sqlite3_create_function()](http://sqlite.org/c3ref/create_function.html)
  */
 
-- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(void *context, int argc, void **argv))block;
+- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(sqlite3_context *context, int argc, sqlite3_value **argv))block;
 
 
 ///---------------------
@@ -1034,6 +1039,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
  */
 
 @interface FMStatement : NSObject {
+    sqlite3_stmt *_statement;
     NSString *_query;
     long _useCount;
     BOOL _inUse;
@@ -1056,7 +1062,7 @@ typedef int(^FMDBExecuteStatementsCallbackBlock)(NSDictionary *resultsDictionary
  @see [`sqlite3_stmt`](http://www.sqlite.org/c3ref/stmt.html)
  */
 
-@property (atomic, assign) void *statement;
+@property (atomic, assign) sqlite3_stmt *statement;
 
 /** Indication of whether the statement is in use */
 

+ 4 - 11
src/fmdb/FMDatabase.m

@@ -1,12 +1,9 @@
 #import "FMDatabase.h"
 #import "unistd.h"
 #import <objc/runtime.h>
-#import "FMDatabase+Private.h"
 
 @interface FMDatabase ()
 
-@property (nonatomic, assign) sqlite3 *db;
-
 - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
 - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
 
@@ -112,7 +109,7 @@ + (BOOL)isSQLiteThreadSafe {
     return sqlite3_threadsafe() != 0;
 }
 
-- (void*)sqliteHandle {
+- (sqlite3*)sqliteHandle {
     return _db;
 }
 
@@ -152,11 +149,11 @@ - (BOOL)open {
     return YES;
 }
 
+#if SQLITE_VERSION_NUMBER >= 3005000
 - (BOOL)openWithFlags:(int)flags {
     return [self openWithFlags:flags vfs:nil];
 }
 - (BOOL)openWithFlags:(int)flags vfs:(NSString *)vfsName; {
-#if SQLITE_VERSION_NUMBER >= 3005000
     if (_db) {
         return YES;
     }
@@ -173,12 +170,8 @@ - (BOOL)openWithFlags:(int)flags vfs:(NSString *)vfsName; {
     }
     
     return YES;
-#else 
-    NSLog(@"Requires SQLite 3.5; will just open");
-    return [self open];
-#endif
-
 }
+#endif
 
 
 - (BOOL)close {
@@ -1371,7 +1364,7 @@ void FMDBBlockSQLiteCallBackFunction(sqlite3_context *context, int argc, sqlite3
 }
 
 
-- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(void *context, int argc, void **argv))block {
+- (void)makeFunctionNamed:(NSString*)name maximumArguments:(int)count withBlock:(void (^)(sqlite3_context *context, int argc, sqlite3_value **argv))block {
     
     if (!_openFunctions) {
         _openFunctions = [NSMutableSet new];

+ 4 - 0
src/fmdb/FMDatabaseAdditions.h

@@ -209,6 +209,8 @@
 - (BOOL)validateSQL:(NSString*)sql error:(NSError**)error;
 
 
+#if SQLITE_VERSION_NUMBER >= 3007017
+
 ///-----------------------------------
 /// @name Application identifier tasks
 ///-----------------------------------
@@ -252,6 +254,8 @@
 - (void)setApplicationIDString:(NSString*)string;
 #endif
 
+#endif
+
 ///-----------------------------------
 /// @name user version identifier tasks
 ///-----------------------------------

+ 5 - 6
src/fmdb/FMDatabaseAdditions.m

@@ -9,7 +9,6 @@
 #import "FMDatabase.h"
 #import "FMDatabaseAdditions.h"
 #import "TargetConditionals.h"
-#import "FMDatabase+Private.h"
 
 @interface FMDatabase (PrivateStuff)
 - (FMResultSet *)executeQuery:(NSString *)sql withArgumentsInArray:(NSArray*)arrayArgs orDictionary:(NSDictionary *)dictionaryArgs orVAList:(va_list)args;
@@ -120,9 +119,10 @@ - (BOOL)columnExists:(NSString*)columnName inTableWithName:(NSString*)tableName
 }
 
 
+#if SQLITE_VERSION_NUMBER >= 3007017
+
 - (uint32_t)applicationID {
     
-#if SQLITE_VERSION_NUMBER >= 3007017
     uint32_t r = 0;
     
     FMResultSet *rs = [self executeQuery:@"pragma application_id"];
@@ -132,18 +132,15 @@ - (uint32_t)applicationID {
     }
     
     [rs close];
-#endif
     
     return r;
 }
 
 - (void)setApplicationID:(uint32_t)appID {
-#if SQLITE_VERSION_NUMBER >= 3007017
     NSString *query = [NSString stringWithFormat:@"pragma application_id=%d", appID];
     FMResultSet *rs = [self executeQuery:query];
     [rs next];
     [rs close];
-#endif
 }
 
 
@@ -169,8 +166,10 @@ - (void)setApplicationIDString:(NSString*)s {
     [self setApplicationID:NSHFSTypeCodeFromFileType([NSString stringWithFormat:@"'%@'", s])];
 }
 
+
 #endif
 
+#endif
 
 - (uint32_t)userVersion {
     uint32_t r = 0;
@@ -206,7 +205,7 @@ - (BOOL)validateSQL:(NSString*)sql error:(NSError**)error {
     sqlite3_stmt *pStmt = NULL;
     BOOL validationSucceeded = YES;
     
-    int rc = sqlite3_prepare_v2(self.db, [sql UTF8String], -1, &pStmt, 0);
+    int rc = sqlite3_prepare_v2(_db, [sql UTF8String], -1, &pStmt, 0);
     if (rc != SQLITE_OK) {
         validationSucceeded = NO;
         if (error) {

+ 4 - 0
src/fmdb/FMDatabasePool.h

@@ -7,6 +7,7 @@
 //
 
 #import <Foundation/Foundation.h>
+#import "sqlite3.h"
 
 @class FMDatabase;
 
@@ -155,6 +156,8 @@
 
 - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block;
 
+#if SQLITE_VERSION_NUMBER >= 3007000
+
 /** Synchronously perform database operations in pool using save point.
 
  @param block The code to be run on the `FMDatabasePool` pool.
@@ -165,6 +168,7 @@
 */
 
 - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
+#endif
 
 @end
 

+ 4 - 8
src/fmdb/FMDatabasePool.m

@@ -8,7 +8,6 @@
 
 #import "FMDatabasePool.h"
 #import "FMDatabase.h"
-#import "FMDatabase+Private.h"
 
 @interface FMDatabasePool()
 
@@ -239,13 +238,9 @@ - (void)inDeferredTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
 - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
     [self beginTransaction:NO withBlock:block];
 }
-
+#if SQLITE_VERSION_NUMBER >= 3007000
 - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
     
-    NSError *err = 0x00;
-
-#if SQLITE_VERSION_NUMBER >= 3007000
-
     static unsigned long savePointIdx = 0;
     
     NSString *name = [NSString stringWithFormat:@"savePoint%ld", savePointIdx++];
@@ -254,6 +249,8 @@ - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
     
     FMDatabase *db = [self db];
     
+    NSError *err = 0x00;
+    
     if (![db startSavePointWithName:name error:&err]) {
         [self pushDatabaseBackInPool:db];
         return err;
@@ -269,9 +266,8 @@ - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
     
     [self pushDatabaseBackInPool:db];
     
-#endif
-    
     return err;
 }
+#endif
 
 @end

+ 3 - 0
src/fmdb/FMDatabaseQueue.h

@@ -7,6 +7,7 @@
 //
 
 #import <Foundation/Foundation.h>
+#import "sqlite3.h"
 
 @class FMDatabase;
 
@@ -174,9 +175,11 @@
  @param block The code to be run on the queue of `FMDatabaseQueue`
  */
 
+#if SQLITE_VERSION_NUMBER >= 3007000
 // NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
 // If you need to nest, use FMDatabase's startSavePointWithName:error: instead.
 - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block;
+#endif
 
 @end
 

+ 3 - 7
src/fmdb/FMDatabaseQueue.m

@@ -8,7 +8,6 @@
 
 #import "FMDatabaseQueue.h"
 #import "FMDatabase.h"
-#import "FMDatabase+Private.h"
 
 /*
  
@@ -205,13 +204,11 @@ - (void)inTransaction:(void (^)(FMDatabase *db, BOOL *rollback))block {
     [self beginTransaction:NO withBlock:block];
 }
 
+#if SQLITE_VERSION_NUMBER >= 3007000
 - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
     
-    __block NSError *err = 0x00;
-
-#if SQLITE_VERSION_NUMBER >= 3007000
-
     static unsigned long savePointIdx = 0;
+    __block NSError *err = 0x00;
     FMDBRetain(self);
     dispatch_sync(_queue, ^() { 
         
@@ -232,9 +229,8 @@ - (NSError*)inSavePoint:(void (^)(FMDatabase *db, BOOL *rollback))block {
         }
     });
     FMDBRelease(self);
-
-#endif
     return err;
 }
+#endif
 
 @end

+ 1 - 0
src/fmdb/FMResultSet.h

@@ -1,4 +1,5 @@
 #import <Foundation/Foundation.h>
+#import "sqlite3.h"
 
 #ifndef __has_feature      // Optional.
 #define __has_feature(x) 0 // Compatibility with non-clang compilers.

+ 0 - 1
src/fmdb/FMResultSet.m

@@ -1,7 +1,6 @@
 #import "FMResultSet.h"
 #import "FMDatabase.h"
 #import "unistd.h"
-#import "FMDatabase+Private.h"
 
 @interface FMDatabase ()
 - (void)resultSetDidClose:(FMResultSet *)resultSet;