Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ccgus/fmdb into threadtests
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed May 25, 2012
2 parents eef8842 + 46614e2 commit 00ed465
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
18 changes: 18 additions & 0 deletions README.markdown
Expand Up @@ -189,6 +189,24 @@ The history and changes are availbe on its [GitHub page](https://github.com/ccgu

The contributors to FMDB are contained in the "Contributors.txt" file.

## Reporting bugs

Reduce your bug down to the smallest amount of code possible. You want to make it super easy for the developers to see and reproduce your bug. If it helps, pretend that the person who can fix your bug is active on shipping 3 major products, works on a handful of open source projects, has a newborn baby, and is generally very very busy.

And we've even added a template function to main.m (FMDBReportABugFunction) in the FMDB distribution to help you out:

* Open up fmdb project in Xcode.
* Open up main.m and modify the FMDBReportABugFunction to reproduce your bug.
* Setup your table(s) in the code.
* 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:**

Figure out where the bug is, fix it, and send a patch in or bring that up on the mailing list. Make sure all the other tests run after your modifications.

## License

The license for FMDB is contained in the "License.txt" file.
11 changes: 9 additions & 2 deletions src/FMDatabase.m
Expand Up @@ -288,8 +288,15 @@ - (int)lastErrorCode {
return sqlite3_errcode(_db);
}


- (NSError*)errorWithMessage:(NSString*)message {
NSDictionary* errorMessage = [NSDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];

return [NSError errorWithDomain:@"FMDatabase" code:sqlite3_errcode(_db) userInfo:errorMessage];
}

- (NSError*)lastError {
return [NSError errorWithDomain:@"FMDatabase" code:sqlite3_errcode(_db) userInfo:[NSDictionary dictionaryWithObject:[self lastErrorMessage] forKey:NSLocalizedDescriptionKey]];
return [self errorWithMessage:[self lastErrorMessage]];
}

- (sqlite_int64)lastInsertRowId {
Expand Down Expand Up @@ -725,7 +732,7 @@ - (BOOL)executeUpdate:(NSString*)sql error:(NSError**)outErr withArgumentsInArra
sqlite3_finalize(pStmt);

if (outErr) {
*outErr = [NSError errorWithDomain:[NSString stringWithUTF8String:sqlite3_errmsg(_db)] code:rc userInfo:nil];
*outErr = [self errorWithMessage:[NSString stringWithUTF8String:sqlite3_errmsg(_db)]];
}

_isExecutingStatement = NO;
Expand Down
56 changes: 55 additions & 1 deletion src/fmdb.m
Expand Up @@ -7,11 +7,13 @@
#define FMDBQuickCheck(SomeBool) { if (!(SomeBool)) { NSLog(@"Failure on line %d", __LINE__); abort(); } }

void testPool(NSString *dbPath);
void FMDBReportABugFunction();

int main (int argc, const char * argv[]) {

@autoreleasepool {


FMDBReportABugFunction();

NSString *dbPath = @"/tmp/tmp.db";

Expand Down Expand Up @@ -1173,3 +1175,55 @@ void testPool(NSString *dbPath) {
#endif

}


/*
What is this function for? Think of it as a template which a developer can use
to report bugs.
If you have a bug, make it reproduce in this function and then let the
developer(s) know either via the github bug reporter or the mailing list.
*/

void FMDBReportABugFunction() {

NSString *dbPath = @"/tmp/bugreportsample.db";

// delete the old db if it exists
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:dbPath error:nil];

FMDatabaseQueue *queue = [FMDatabaseQueue databaseQueueWithPath:dbPath];

[queue inDatabase:^(FMDatabase *db) {

/*
Change the contents of this block to suit your needs.
*/

BOOL worked = [db executeUpdate:@"create table test (a text, b text, c integer, d double, e double)"];
FMDBQuickCheck(worked);


worked = [db executeUpdate:@"insert into test values ('a', 'b', 1, 2.2, 2.3)"];
FMDBQuickCheck(worked);

FMResultSet *rs = [db executeQuery:@"select * from test"];
FMDBQuickCheck([rs next]);
[rs close];

}];


[queue close];


// uncomment the following line if you don't want to run through all the other tests.
//exit(0);

}





0 comments on commit 00ed465

Please sign in to comment.