Преглед на файлове

Cleanup, and then while debugging a test, noticed that sqlite3_busy_timeout doesn't retry a sqlite3_step for you automatically. So that's a problem that I'll need to fix.

ccgus преди 12 години
родител
ревизия
7daa30d27a
променени са 5 файла, в които са добавени 29 реда и са изтрити 11 реда
  1. 7 0
      Tests/FMDatabaseAdditionsTests.m
  2. 12 1
      Tests/FMDatabasePoolTests.m
  3. 4 4
      Tests/FMDatabaseTests.m
  4. 3 3
      src/FMDatabaseAdditions.m
  5. 3 3
      src/fmdb.m

+ 7 - 0
Tests/FMDatabaseAdditionsTests.m

@@ -94,4 +94,11 @@ - (void)testColumnExists
     XCTAssertFalse([self.db columnExists:@"c" inTableWithName:@"nulltest"]);
 }
 
+- (void)testUserVersion {
+    
+    [[self db] setUserVersion:12];
+    
+    XCTAssertTrue([[self db] userVersion] == 12);
+}
+
 @end

+ 12 - 1
Tests/FMDatabasePoolTests.m

@@ -36,7 +36,10 @@ - (void)setUp
     [super setUp];
     // Put setup code here. This method is called before the invocation of each test method in the class.
     
-    self.pool = [FMDatabasePool databasePoolWithPath:self.databasePath];
+    [self setPool:[FMDatabasePool databasePoolWithPath:self.databasePath]];
+    
+    [[self pool] setDelegate:self];
+    
 }
 
 - (void)tearDown
@@ -249,6 +252,14 @@ - (void)testStressTest
     XCTAssert([self.pool countOfOpenDatabases] < 64, @"There should be significantly less than 64 databases after that stress test");
 }
 
+
+- (BOOL)databasePool:(FMDatabasePool*)pool shouldAddDatabaseToPool:(FMDatabase*)database {
+    [database setRetryTimeout:.1];
+    [database setCrashOnErrors:YES];
+    #pragma message "FIXME: Gus - we need to check for a SQLITE_BUSY when we call sqlite3_step.  sqlite will sleep for the retry amount - BUT, it won't just try the step again.  We'll have to put the old loops back in.  testReadWriteStressTest shows this mistake."
+    return YES;
+}
+
 - (void)testReadWriteStressTest
 {
     int ops = 16;

+ 4 - 4
Tests/FMDatabaseTests.m

@@ -91,8 +91,8 @@ - (void)testFailOnBadStatementWithError
 
 - (void)testPragmaJournalMode
 {
-    FMResultSet *ps = [self.db executeQuery:@"PRAGMA journal_mode=delete"];
-    XCTAssertFalse([self.db hadError], @"PRAGMA should have succeeded");
+    FMResultSet *ps = [self.db executeQuery:@"pragma journal_mode=delete"];
+    XCTAssertFalse([self.db hadError], @"pragma should have succeeded");
     XCTAssertNotNil(ps, @"Result set should be non-nil");
     XCTAssertTrue([ps next], @"Result set should have a next result");
     [ps close];
@@ -101,7 +101,7 @@ - (void)testPragmaJournalMode
 - (void)testPragmaPageSize
 {
     [self.db executeUpdate:@"PRAGMA page_size=2048"];
-    XCTAssertFalse([self.db hadError], @"PRAGMA should have succeeded");
+    XCTAssertFalse([self.db hadError], @"pragma should have succeeded");
 }
 
 - (void)testVacuum
@@ -670,7 +670,7 @@ - (void)testNamedParameters
 
 - (void)testPragmaDatabaseList
 {
-    FMResultSet *rs = [self.db executeQuery:@"PRAGMA database_list"];
+    FMResultSet *rs = [self.db executeQuery:@"pragma database_list"];
     int counter = 0;
     while ([rs next]) {
         counter++;

+ 3 - 3
src/FMDatabaseAdditions.m

@@ -90,7 +90,7 @@ - (FMResultSet*)getSchema {
 - (FMResultSet*)getTableSchema:(NSString*)tableName {
     
     //result colums: cid[INTEGER], name,type [STRING], notnull[INTEGER], dflt_value[],pk[INTEGER]
-    FMResultSet *rs = [self executeQuery:[NSString stringWithFormat: @"PRAGMA table_info('%@')", tableName]];
+    FMResultSet *rs = [self executeQuery:[NSString stringWithFormat: @"pragma table_info('%@')", tableName]];
     
     return rs;
 }
@@ -137,7 +137,7 @@ - (uint32_t)applicationID {
 }
 
 - (void)setApplicationID:(uint32_t)appID {
-    NSString *query = [NSString stringWithFormat:@"PRAGMA application_id=%d", appID];
+    NSString *query = [NSString stringWithFormat:@"pragma application_id=%d", appID];
     FMResultSet *rs = [self executeQuery:query];
     [rs next];
     [rs close];
@@ -185,7 +185,7 @@ - (uint32_t)userVersion {
 }
 
 - (void)setUserVersion:(uint32_t)version {
-    NSString *query = [NSString stringWithFormat:@"PRAGMA user_version=%d", version];
+    NSString *query = [NSString stringWithFormat:@"pragma user_version = %d", version];
     FMResultSet *rs = [self executeQuery:query];
     [rs next];
     [rs close];

+ 3 - 3
src/fmdb.m

@@ -73,14 +73,14 @@ int main (int argc, const char * argv[]) {
     
     
     // how do we do pragmas?  Like so:
-    FMResultSet *ps = [db executeQuery:@"PRAGMA journal_mode=delete"];
+    FMResultSet *ps = [db executeQuery:@"pragma journal_mode=delete"];
     FMDBQuickCheck(![db hadError]);
     FMDBQuickCheck(ps);
     FMDBQuickCheck([ps next]);
     [ps close];
     
     // oh, but some pragmas require updates?
-    [db executeUpdate:@"PRAGMA page_size=2048"];
+    [db executeUpdate:@"pragma page_size=2048"];
     FMDBQuickCheck(![db hadError]);
     
     // what about a vacuum?
@@ -824,7 +824,7 @@ int main (int argc, const char * argv[]) {
     }
     
     // just for fun.
-    rs = [db executeQuery:@"PRAGMA database_list"];
+    rs = [db executeQuery:@"pragma database_list"];
     while ([rs next]) {
         NSString *file = [rs stringForColumn:@"file"];
         NSLog(@"database_list: %@", file);