diff options
author | ccgus <gus@flyingmeat.com> | 2014-01-20 22:01:06 +0400 |
---|---|---|
committer | ccgus <gus@flyingmeat.com> | 2014-01-20 22:01:06 +0400 |
commit | 7daa30d27a0e67e1ca2032fc5a4dd934899db556 (patch) | |
tree | 61eeb8fdc427a077d7705315aa84d3f8e07a0f60 | |
parent | f7e1a9298a51c558ece7e96702d16bd8eec74ab6 (diff) |
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.
-rw-r--r-- | Tests/FMDatabaseAdditionsTests.m | 7 | ||||
-rw-r--r-- | Tests/FMDatabasePoolTests.m | 13 | ||||
-rw-r--r-- | Tests/FMDatabaseTests.m | 8 | ||||
-rw-r--r-- | src/FMDatabaseAdditions.m | 6 | ||||
-rw-r--r-- | src/fmdb.m | 6 |
5 files changed, 29 insertions, 11 deletions
diff --git a/Tests/FMDatabaseAdditionsTests.m b/Tests/FMDatabaseAdditionsTests.m index 6164847..b861ef1 100644 --- a/Tests/FMDatabaseAdditionsTests.m +++ b/Tests/FMDatabaseAdditionsTests.m @@ -94,4 +94,11 @@ XCTAssertFalse([self.db columnExists:@"c" inTableWithName:@"nulltest"]); } +- (void)testUserVersion { + + [[self db] setUserVersion:12]; + + XCTAssertTrue([[self db] userVersion] == 12); +} + @end diff --git a/Tests/FMDatabasePoolTests.m b/Tests/FMDatabasePoolTests.m index 36183c5..55ce5ea 100644 --- a/Tests/FMDatabasePoolTests.m +++ b/Tests/FMDatabasePoolTests.m @@ -36,7 +36,10 @@ [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 @@ 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; diff --git a/Tests/FMDatabaseTests.m b/Tests/FMDatabaseTests.m index 9918309..279f09f 100644 --- a/Tests/FMDatabaseTests.m +++ b/Tests/FMDatabaseTests.m @@ -91,8 +91,8 @@ - (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)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)testPragmaDatabaseList { - FMResultSet *rs = [self.db executeQuery:@"PRAGMA database_list"]; + FMResultSet *rs = [self.db executeQuery:@"pragma database_list"]; int counter = 0; while ([rs next]) { counter++; diff --git a/src/FMDatabaseAdditions.m b/src/FMDatabaseAdditions.m index b68d71f..4ab35fa 100644 --- a/src/FMDatabaseAdditions.m +++ b/src/FMDatabaseAdditions.m @@ -90,7 +90,7 @@ return ret; - (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 @@ return ret; } - (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 @@ return ret; } - (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]; @@ -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); |