Code Monkey home page Code Monkey logo

fmdb's People

Contributors

5at5ish avatar antons avatar ccgus avatar clemensg avatar cnoon avatar cutz avatar danoranges avatar davedelong avatar dodikk avatar fjohn666 avatar grahamdennis avatar incanus avatar jason-gabriele avatar jhammer avatar jonathan-edsitech avatar leonatan avatar nemesis avatar newyankeecodeshop avatar p2 avatar r4n avatar reiz avatar rimasm avatar rob2468 avatar robertmryan avatar rupey avatar snooc avatar tiennou avatar tstump-phunware avatar username0x0a avatar v01dzer0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fmdb's Issues

-[FMResultSet columnIsNull:] is misleading

According to the SQLite documentation, the use of the function sqlite3_column_type() returns the base type of the column. It says:

The sqlite3_column_type() routine returns the datatype code for the initial data type of the result column. The returned value is one of SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, or SQLITE_NULL. The value returned by sqlite3_column_type() is only meaningful if no type conversions have occurred as described below. After a type conversion, the value returned by sqlite3_column_type() is undefined. Future versions of SQLite may change the behavior of sqlite3_column_type() following a type conversion.

As it currently stands, the name of the method seems to imply that it is referring to the value of the column in the current tuple, and not the type of the column.

An "async" version of "inTransaction:" ? + a design question

Hi.
I was about to implement the FMDatabaseQueue stuff myself before I discovered it's just been added to fmdb.
But I see all the transactions are done with a "dispatch_sync" which doesn't return until all the stuff is made.

In my code I would need an "async" version of it. That is, schedule the block to the serial queue, and move on immediately. The crucial point is the serial nature of the queue to avoid multi-threaded collisions. But not the way you schedule blocks to it.

The implementation of the async version could virtually be identical to the sync one, apart from the dispatch function, and the absence of need to make a retain/release (for non-arc code), since a Block_copy() is made in dispatch_aync.

To the contrary of the sync version however, there could be some difficulties if you need to perform some actions once the block is done on success, or when it has failed. We can imagine other block arguments, that could be performed on the main global queue (just a suggestion) after the rollback / commit.

Also, I wonder the meaning of passing "db" as an argument of the block of transactions, and always calling [self database] inside the method implementation. What happens if they are different?

The example given in the README of fmdb is confusing. Imagine you have another "FMDatabase" called db2. Nothing prevent you to write (it's a mistake I agree), inside the "inTransaction" block: "[db2 executeUpdate:...]". Then the whole transaction is meaningless.

In fact, to me, the "inTransaction" method should be a method of the FMDatabase instance itself. In fact, instead of a new class FMDatabaseQueue, every "standard" update and query should be done on the underlying serial queue in the FMDatabaseInstance, and then the whole FMDB lib would be thread-safe thanks to GDB.

My 2-cents.

[Feature] Fast enumeration for FMResultSet

It's going to be even nicer to have an opportunity to iterate FMResultSet in native ObjectiveC manner :

for ( FMRow* row in fmResultSet )
{
// do the work with the row
}

executeUpdate should autobox primitive values

Hit me by chance that adding a plain integer to executeUpdate just crashes at like 772 in FMDatabase.m ( obj = va_arg(args, id);) ... we could be a little smarter and provide auto-boxing for such cases.

If this is interesting, I might send a pull request.

XCode 4.1 / Lion: Expected declaration specifiers

Until yesterday I had no problems using FMDB, but today I upgraded to Lion/xcode4.1
and I get tons of errors before every method declaration in the FMDB Classes like:

"Expected declaration specifiers before '+' token"

Do I miss something here?

Unable to use 'id' with any va_arg use in iOS5 Beta 3

New XCode preview gives a " "Second argument to 'va_arg' is of non-POD type 'id' error.

All 3 uses in FMDatabase.m

- (void)_extractSQL:(NSString *)sql argumentsList:(va_list)args intoString:(NSMutableString *)cleanedSQL arguments:(NSMutableArray *)arguments {

    NSUInteger length = [sql length];
    unichar last = '\0';
    for (NSUInteger i = 0; i < length; ++i) {
        id arg = nil;
        unichar current = [sql characterAtIndex:i];
        unichar add = current;
        if (last == '%') {
            switch (current) {
                case '@':
                    arg = va_arg(args, id); 
                    break;
                    ....

How can I get previous row

for example:

rs = [db executeQuery:@"SELECT * FROM table"];

[rs next];
.....................//Get data

[rs next];
.....................//Get data

this time I want to back
How can I get previous row and get data?
Why no[[rs previous] method........

FMResultSet -stringForColumnIndex: memory leak?

Perhaps I am not doing something right. I'm running the profiler in Xcode 4 and getting a memory leak:

-(NSString *)stringForColumnIndex:(int)columnIdx
leaking at return statement (currently line 258): return [NSString stringWithUTF8String:c];

Leaked object: NSCFString (Foundation->[NSPlaceholderString initWithBytes:length:encoding:])

Is this me or something in FMDB?

Thanks!

New to FMDB

Hellow everybody,

I found on different topics that its better to use FMDB for a database than a direct sqlite.
I am new there, so idownloaded the source code to compil it with Xcode 3.2. The problem is that i get a lot of errors and warning
so i think i need an older version. Anyone know where can i get one?

Thanks for your answers and
Sorry for my english. Thanks

FMDatabase returns a confusing "out of memory" error when attempting to use an unopened database

copied over from google code: http://code.google.com/p/flycode/issues/detail?id=20#c1

What steps will reproduce the problem?

  1. myDb = [[FMDatabase alloc] initWithPath:dbPath];
  2. don't bother calling [myDb open];
  3. [myDb executeQuery:myQuery]

What is the expected output? What do you see instead?
I see an "out of memory" error. I would expect to see a "database not open, dummy" error.

What version of the product are you using? On what operating system?
iPhone OS 3.2

Please provide any additional information below.

Apply attached patch to raise an error if an update is attempted without opening the database.

FMDatabaseAdditions: getTableSchema: enhancement?

Hiyas

I'm not directly sure if this qualifies as bug, but changing it would make my life incredibly better. Shouldn't

  • (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]];
    return rs;
    }

be rather

  • (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]];
    return rs;
    }

quoting the table name? I ask because in my project, we use tables that use a GUID as name and, naturally, a GUID can start with a number and not a letter (actually this is rather the default case) and a table_info() with a table starting with a non-alphabetic character startles up sqlite.

FMDatabasePool causing DB getting locked

Hi,

I have an app which now uses several threads, so I needed to use to the FMDatabasePool.
I get my app locked, and debugging I see 2 threads stopped in the usleep(20) because the DB is 'SQLITE_BUSY', one in an executeUpdate, and other in 'FMResultSet:next.

As you can imagine, that was not happening when I used just 1 thread approach.

Any idea what is going on?

Kind regards

dateForColumn since1970

Hi,

I deal with CoreDate sqlite where real data is from [NSDate dateWithTimeIntervalSinceReferenceDate:] intead of [NSDate dateWithTimeIntervalSince1970:]. Don't know if it's common, but this is how it work with CoreData Data columns.

bulk insert

Would it be possible to process bulk insert into sqlite using FMDB? Any example would be appreciated.
Thanks
Hung

sqlite can be non-reenterant

Just found that running a resultset in one thread and executeQuery in another often causes crash in the sqlite code. Typical crash stack is:

Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsqlite3.dylib 0x3265929c sqlite3_extended_errcode + 18104
1 libsqlite3.dylib 0x32659342 sqlite3_extended_errcode + 18270
2 libsqlite3.dylib 0x3266cc08 sqlite3_column_bytes16 + 7160
3 libsqlite3.dylib 0x32687002 sqlite3_open16 + 42242
4 libsqlite3.dylib 0x32644954 sqlite3_step + 56
5 iGlomp 0x00010d46 -FMResultSet next

Well, it might depend on the sqlite version, but I'd better add a mutex to all sqlite calls. Does a new thread contain a workaround fot it already?

all column names get lowercased

I really wouldn't say that would be the expected behavior. I have my column names set in the database, I'd expect them to come to my Objective-C code untouched.

fmdb -rollback never returns

In the following code fragment,

[mDatabase beginTransaction];
if ([mDatabase executeUpdate:sqlStatement])
{
    [mDatabase commit];
}
else
{
    NSLog(@"Error in SQL: %@", [mDatabase lastErrorMessage]);
    [mDatabase rollback];
}

the -rollback never returns.

I wanted to test my error handling, by making the sqlStatement something intentionally faulty, like SELECT humbug();, where humbug() is an undefined function. Tracing the weird behaviour of -rollback above shows that sqlite thinks its DB file is locked and FMDB code loops endlessly in that situation.

Did I do something wrong here?

database locks after sqlite3_step

this is related to my old question about insert, i think i know where things are going wrong..

so i tried a simple insert, and stepped through the execution, and realize that the database locks right after line 704 of FMDatabase.m, which is

/* Call sqlite3_step() to run the virtual machine. Since the SQL being
 ** executed is not a SELECT statement, we assume no data will be returned.
 */
numberOfRetries = 0;
do {
    rc      = sqlite3_step(pStmt); <--- this one
    retry   = NO;

this is after the binding happens successfully, i can provide you with a video capture of the stepping if needed.

I close the database and then open it right before i open it again to run the update statement..

i looked around the web, and people suggest that it is a sqlite issue with NFS drives file locking mechanism, i have a mac os 10.6.8, and drive is autofs, which is a type of nfs i believe.

i am not expecting a fix from you, but some comments if you have any off the top of your head, i will to try this on a different machine as soon as i get the chance to.

thanks!

isaac

Too many arguments for NSAssert

When I compile FMDB (threadtest branch) in a Mac OS X project, I get the following error:

../FMDB/src/FMDatabase.m:859:78: error: too many arguments provided to function-like macro invocation [2]
NSAssert(NO, @"A executeUpdate is being called with a query string", 0x00);

NSAssert expects only two parameters, so I wonder where this "0x00" comes from?

insert does not work

I might be doing something wrong, but i have a dao on top of fmdb, i am trying to insert records into the databse. first fmdb seems to be copying the database file to some temporary location and is not performing the inserts on the database file i open (i.e. the one included in the project), and second, insert is work ok no errors and returns a successful result, but the insert does not happen in the database, even in the db location fmdb is writing to.

i am openning the databse everytime i do the insert, i will change that eventually, but any ideas why this is happening. i know i am posting enough details, but any hints would be ver much appreciated.

Thanks!

Isaac

_openResultSets Question

I just updated to the latest version to use the new pooling / queue paradigm, but I keep running into an error when I close the database. The closeOpenResultSets keeps erroring out with invalid objects in _openResultSets... Debugging the code shows that I have hundreds of resultSets in the _openResultSets object. While I do create many resultSets, I close them all and I have verified that all executeQueries are surrounded with @try/finally blocks.

Furthermore, a breakpoint in resultSetDidClose is never fired, so it looks like the result set is never removed from the object.

Does anyone have any ideas?

Thank you!

executeUpdateWithFormat: with %s and nil fails

When using executeUpdateWithFormat with %s and a char* that's actually nil, the method fails. I would have thought it should insert NULL.

    NSString* sql = @"CREATE TABLE Test (name TEXT);";
    BOOL ok = [db executeUpdate:sql];

    NSString* s = nil;
    const char* cs = [s UTF8String];
    sql = @"INSERT INTO Test (name) VALUES (%s)";
    ok = [db executeUpdateWithFormat:sql, cs];

Observed:

2012-03-08 12:33:46.887 tpq[3592:fb03] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[NSString stringWithUTF8String:]: NULL cString'

Expected:

Insert NULL in DB.

Thanks for making this great small library!

[db executeUpdate:@"PRAGMA journal_mode=OFF"] crashes

When I use [db executeUpdate:@"PRAGMA journal_mode=OFF"]; the app crashes, in FMDatabase.m:

Assertion failed: (rc!=SQLITE_ROW), function -[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:], file /Users/trasch/Projects/route-me/MapView/Map/FMDB/FMDatabase.m, line 744.

Using executeQuery, it works:
[db executeQuery:@"PRAGMA journal_mode=OFF"];

(at least, it doesn't crash...)

Tag release versions

I recently added FMDB to the CocoaPods package manager.

Since FMDB doesn't currently have a discreet version, I treated the current commit as the 1.0.0 release. Would it be possible to have this commit tagged as v1.0.0 (or whatever version you feel comfortable with)? This will help greatly in dependency resolution.

Thanks!

DB fails to close after -executeQuery

Hey,
Here's a sample program where the DB will fail to close if you try to close it before emptying an autorelease pool, because an FMResultSet is autoreleased by calling -executeQuery:, and the FMResultSet won't finalize its FMStatement until it is released. Sorry, it's confusing to explain!

#import <Foundation/Foundation.h>
#import "FMDatabase.h"


int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager removeItemAtPath:@"/tmp/tmp.db" error:nil];

    FMDatabase* db = [FMDatabase databaseWithPath:@"/tmp/tmp.db"];
    if (![db open]) {
        NSLog(@"Could not open db.");
        [pool release];
        return 0;
    }

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

    FMResultSet *set = [db executeQuery:@"select * from test"];

    // At this point:
    // a) set has been autoreleased, but won't be released until the current
    //    autorelease pool is emptied.
    // b) set is retaining the FMStatement, which has an sqlite statement
    //

    [db close]; // this will loop in -[FMDatabase close] because you can't close
                // a db with un-finalized statements


    [pool release];
    return 0;
}

This doesn't happen if you either use -setShouldCacheStatements: YES, or if you close result set. However, it's still a confusing issue to run in to.

Autorelease

I got problems using FMDB, I create only one DB instance in my iPad application, after a few calls the DB was released, so I was unable to use it (application crash).

I removed autorelease in databaseWithPath:

  • (id)databaseWithPath:(NSString*)aPath {
    // return [[[self alloc] initWithPath:aPath] autorelease]; // tolto AUTORELEASE genera problemi

    return [[self alloc] initWithPath:aPath];
    }

this solved my problem.

another user reported the same problem: http://w-i-l-t.tumblr.com/post/521270162/fixing-fmdb-crashes-on-iphone

No Such Table issue

i've included the database in my project , and also i've used fmdb before , i tried to copy my code from my old project but still it says "No such table"

here is the console log : "
DB Error: 1 "no such table: ANIMALS"
DB Query: SELECT * FROM ANIMALS WHERE Name = 'koyun'
DB Path: (null)"

and here is my code :

        NSString *path = [[NSBundle mainBundle] pathForResource:@"HayvanlarM" ofType:@"sqlite"];

        FMDatabase *database = [FMDatabase databaseWithPath:path];

        [database setLogsErrors:TRUE];

        [database open];

        NSString *anQuery = [[NSString alloc]initWithFormat:@"SELECT * FROM ANIMALS WHERE Name = '%@' ",[[bBackG objectAtIndex:0]stringByDeletingPathExtension]];

        FMResultSet *results = [database executeQuery:anQuery];


        while([results next]) {

            NSString *animalName = [results stringForColumn:@"TR"];

            //gjText.text = animalName;
            NSLog(@"animalName: %@",animalName);
        }



        [database close];
        database = nil;

could anyone tell me what's the problem in my code ?
i tried to create my db through firefox sqlite manager , and i tried lita , but both gave me same error ( no such table )

Problems using group by

I have two tables related with item_id foreign key:

Table Item:

CREATE TABLE "Item" ("item_id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE DEFAULT 0, "name" VARCHAR NOT NULL , "image_name" VARCHAR, "features" TEXT)

Table ItemAttributes:

CREATE TABLE "ItemAttributes" ("date" DATETIME DEFAULT CURRENT_DATE NOT NULL, "store_name" VARCHAR NOT NULL, "price" INTEGER NOT NULL, "latitude" FLOAT NOT NULL, "longitude" FLOAT NOT NULL, "item_id" INTEGER NOT NULL DEFAULT 0)

The content on both tables:

SELECT * FROM Item

"15","bistec","357132712847402.png","Carn més o menys bona"
"16","patata","357751697149282.png","Patata de prades"
"17","tomaquet","358065632272838.png","Tomaquet de l'hort"

SELECT * FROM ItemAttributes

"2012-04-26","Carrefour","1200","37.78583526611328","-122.40641784667969","15"
"2012-04-26","SUMA","1300","0","0","15"
"2012-05-03","Botigueta barri","50","37.78583526611328","-122.40641784667969","16"
"2012-05-07","Botiga","12","37.78583526611328","-122.40641784667969","15"
"2012-05-07","Botigueta","120","37.78583526611328","-122.40641784667969","16"
"2012-05-07","Mercat","130","37.78583526611328","-122.40641784667969","17"
"2012-05-07","Carrefour","100","37.78583526611328","-122.40641784667969","17"

When I execute in SQLite Manager:

SELECT i.item_id, i.name, i.image_name, i.features, ia.date, ia.store_name, MIN(ia.price) AS price, ia.latitude, ia.longitude FROM Item i, ItemAttributes ia WHERE i.item_id=ia.item_id GROUP BY i.name ORDER BY i.name

I get the expected output:

"15","bistec","357132712847402.png","Carn més o menys bona","2012-05-07","Botiga","12","37.78583526611328","-122.40641784667969"
"16","patata","357751697149282.png","Patata de prades","2012-05-07","Botigueta","50","37.78583526611328","-122.40641784667969"
"17","tomaquet","358065632272838.png","Tomaquet de l'hort","2012-05-07","Carrefour","100","37.78583526611328","-122.40641784667969"

But using FMDB, I get the erroneous output:

name: bistec, store_name: Botiga
name: patata, store_name: Botigueta
name:tomaquet, store_name: Mercat

the last output should have as store_name 'Carrefour' not 'Mercat'

logging toggle?

Are you open to a #define for whether NSLog should be active or not? I've found it useful to comment out various NSLog calls and having this FMDB-wide would be nice. I could hack it up and submit a pull request.

Doesn't work with Garbage Collection

It looks like FMStatement somehow stays rooted and then prevents the database from closing. This can be confirmed with the sample code as well.

can't use FMDB with Xcode 4

I created a vergine project on Xcode 4, I imported FMDB (like I did with xcode 3 few months ago) just drugging the source folder, then I add libsqlite3.0.dylib on "Build Phases-> Link Binary With Libraries"

I got this error:
"ld: duplicate symbol _main in /Users/luca/Library/Developer/Xcode/DerivedData/prova4-dsulhpfwtyiffieremqmsufplmzn/Build/Intermediates/prova4.build/Debug-iphonesimulator/prova4.build/Objects-normal/i386/fmdb.o and /Users/luca/Library/Developer/Xcode/DerivedData/prova4-dsulhpfwtyiffieremqmsufplmzn/Build/Intermediates/prova4.build/Debug-iphonesimulator/prova4.build/Objects-normal/i386/main.o for architecture i386
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1"

any suggestion? I really cannot find anything useful anywhere I really want to go on this stuff I'm doing
thank you

while ( [rs next ] )

I'm working on a hello_world project consisting of more than 9 classes. Each class do some (select * limit 1) queries. So far so good.

But now when I wrote a method to read several lines doing while loop. The app is crashing with an error pointing on sqlite3_finalize in . (EXC_BAD_ACCESS)

  • (void)close {
    if (_statement) {
    sqlite3_finalize(_statement);
    _statement = 0x00;
    }
    }

When I'm sleep(5) just before the end of the while loop, the method is working fine. Am I missing something ?

EXC_BAD_ACCESS when binding to NSInteger (issue with binding to primitives?)

Not sure if this is a known issue or if I'm just being stupid (I'm fairly new to objective c), but if I attempt to

     NSInteger someInt = 1;
     FMResultSet *s = [db
                      executeQuery:@"select foo from bar where baz = ?,
                      1];

I end up with EXC_BAD_ACCESS inside executeQuery at line 532

    [self bindObject:obj toColumn:idx inStatement:pStmt];

or if traceExecution = YES, line 527

    NSLog(@"obj: %@", obj);

So basically, it seems to be expecting a non-primitive type as a binding parameter as obj is an ID. Is that the intended functionality? If so, is there a better way to protect against this kind of mistake?

update:error:bind: method, isn't it broken?

looks like the arg 'bindArgs' is getting lost here:

- (BOOL)update:(NSString*)sql error:(NSError**)outErr bind:(id)bindArgs, ... {
    va_list args;
    va_start(args, bindArgs);

    BOOL result = [self executeUpdate:sql error:outErr withArgumentsInArray:nil orVAList:args];

    va_end(args);
    return result;
}

So i changed the method signature, which AFAIK is the only way to fix this problem easily.

- (BOOL)update:(NSString*)sql withErrorAndBindings:(NSError**)outErr, ... {
    va_list args;
    va_start(args, outErr);

    BOOL result = [self executeUpdate:sql error:outErr withArgumentsInArray:nil orVAList:args];

    va_end(args);
    return result;
}

[FMDatabase.m] - Wrong error domain ?

There is a mismatch in error handling within FMDatabase.m ( see code below )
Is it a bug? If not, what's the point of doing so?

[code]
-(NSError*)lastError
[ NSError errorWithDomain:@"FMDatabase"
code:sqlite3_errcode(_db)

-(BOOL)executeUpdate:error:withArgumentsInArray:orDictionary:orVAList:
[ NSError errorWithDomain:[NSString stringWithUTF8String:sqlite3_errmsg(_db)]
code:sqlite3_errcode(_db)
[/code]

How to turn on foreign keys in FMDatabase?

Just stumbled upon the fact foreign keys are disabled by default in sqlite. I have "on delete casdade" foreign key and deleting parent table records does not delete child records. Various posts indicate you need to enable that on each connection "PRAGMA foreign_keys = ON; ". So, where to enable it in FMDatabase? I would prefer setting some setting instead of running the command before each SQL stmt. PS. I'm using FMDatabaseQueue.

Incorrect decrement of reference count

I'm getting this warning when I'm analyzing my code built on the tutorial in your manual.

FMDatabase *db = [FMDatabase databaseWithPath:[CJohnny getdbpath]];
if ( ![db open] )
{
    if ( db ) [db release];
    return NO;
}

The warning is pointing at (((( if (db) [db release]; )))))))

executeUpdateWithFormat fails with "EXC_BAD_INSTRUCTION"

fmdb.m[line 472] FMDBQuickCheck(([db executeUpdateWithFormat:@"insert into t5 values (%s, %d, %@, %c, %lld)", "text", 42, @"BLOB", 'd', 12345678901234])); fail with EXC_BAD_INSTRUCTION

my env :ios 4 xcode 4.0.2

would please fix it?

statement caching doesn't work in all cases

Statement caching (FMDatabase shouldCacheStatements) currently keys off of the sql of the query that the statement is based on. However it doesn't take into account parameter values. This means that similar queries having differing parameters will overwrite each others result-sets.

Consider the following, with statement caching ON:

BOOL b;
FMResultSet* rs1 = [myDB executeQuery: @"SELECT rowid FROM myTable WHERE myColumn = ?", [NSNumber numberWithLong: 1]]; // results in > 10 rows...
b = [rs1 next]; // success

FMResultSet* rs2 = [myDB executeQuery: @"SELECT rowid FROM myTable WHERE myColumn = ?", [NSNumber numberWithLong: 2]]; // results in 1 row
b = [rs2 next]; // success

b = [rs1 next]; // failure (returns FALSE), even though there should be more rows...

The reason for the failure is that the sqlite statement used by rs1 was altered when same query (but with different parameters) was subsequently executed. In the end, rs1 and rs2 are using the same statement and the results for the original query are lost.

With statement caching off, the testcase above works out fine.

Insert and update

Hi,
I have a scenario where I first begin inserting several thousands of records into sqlite. Later on I need to come back and update these records. Although I am trying to wrap that in a single transaction by invoking the begintransaction method, it's going pretty slow. The inserting process by itself happens very fast but not when combining with the updating process. Any advice?
Hung

Documentation conflicts

Documentation says to use executeUpdate:... withArgumentsInDictionary:..., however autocomplete shows executeUpdate:... withParameterDictionary:...

cannot compile with xcode4

Undefined symbols for architecture i386:
"_sqlite3_libversion", referenced from:
+[FMDatabase sqliteLibVersion] in FMDatabase.o
"_sqlite3_open", referenced from:
-[FMDatabase open] in FMDatabase.o
"_sqlite3_open_v2", referenced from:
-[FMDatabase openWithFlags:] in FMDatabase.o
"_sqlite3_close", referenced from:
-[FMDatabase close] in FMDatabase.o
"_sqlite3_finalize", referenced from:
-[FMDatabase close] in FMDatabase.o
-[FMDatabase executeQuery:withArgumentsInArray:orVAList:] in FMDatabase.o
-[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o
-[FMStatement close] in FMDatabase.o
-[FMDatabase(FMDatabaseAdditions) validateSQL:error:] in FMDatabaseAdditions.o
"_sqlite3_next_stmt", referenced from:
-[FMDatabase close] in FMDatabase.o
"_sqlite3_errmsg", referenced from:
-[FMDatabase lastErrorMessage] in FMDatabase.o
-[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o
-[FMResultSet next] in FMResultSet.o
"_sqlite3_errcode", referenced from:
-[FMDatabase lastErrorCode] in FMDatabase.o
-[FMResultSet hasAnotherRow] in FMResultSet.o
"_sqlite3_last_insert_rowid", referenced from:
-[FMDatabase lastInsertRowId] in FMDatabase.o
"_sqlite3_changes", referenced from:
-[FMDatabase changes] in FMDatabase.o
"_sqlite3_bind_null", referenced from:
-[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o
"_sqlite3_bind_blob", referenced from:
-[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o
"_sqlite3_bind_double", referenced from:
-[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o
"_sqlite3_bind_int", referenced from:
-[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o
"_sqlite3_bind_int64", referenced from:
-[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o
"_sqlite3_bind_text", referenced from:
-[FMDatabase bindObject:toColumn:inStatement:] in FMDatabase.o
"_sqlite3_prepare_v2", referenced from:
-[FMDatabase executeQuery:withArgumentsInArray:orVAList:] in FMDatabase.o
-[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o
-[FMDatabase(FMDatabaseAdditions) validateSQL:error:] in FMDatabaseAdditions.o
"_sqlite3_bind_parameter_count", referenced from:
-[FMDatabase executeQuery:withArgumentsInArray:orVAList:] in FMDatabase.o
-[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o
"_sqlite3_step", referenced from:
-[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o
-[FMResultSet next] in FMResultSet.o
"_sqlite3_reset", referenced from:
-[FMDatabase executeUpdate:error:withArgumentsInArray:orVAList:] in FMDatabase.o
-[FMStatement reset] in FMDatabase.o
-[FMResultSet next] in FMResultSet.o
"_sqlite3_threadsafe", referenced from:
+[FMDatabase isThreadSafe] in FMDatabase.o
"_sqlite3_column_count", referenced from:
-[FMResultSet columnCount] in FMResultSet.o
-[FMResultSet setupColumnNames] in FMResultSet.o
-[FMResultSet kvcMagic:] in FMResultSet.o
"_sqlite3_column_name", referenced from:
-[FMResultSet setupColumnNames] in FMResultSet.o
-[FMResultSet kvcMagic:] in FMResultSet.o
-[FMResultSet columnNameForIndex:] in FMResultSet.o
"_sqlite3_column_text", referenced from:
-[FMResultSet kvcMagic:] in FMResultSet.o
-[FMResultSet stringForColumnIndex:] in FMResultSet.o
-[FMResultSet UTF8StringForColumnIndex:] in FMResultSet.o
"_sqlite3_data_count", referenced from:
-[FMResultSet resultDict] in FMResultSet.o
"_sqlite3_column_int", referenced from:
-[FMResultSet intForColumnIndex:] in FMResultSet.o
"_sqlite3_column_int64", referenced from:
-[FMResultSet longForColumnIndex:] in FMResultSet.o
-[FMResultSet longLongIntForColumnIndex:] in FMResultSet.o
"_sqlite3_column_double", referenced from:
-[FMResultSet doubleForColumnIndex:] in FMResultSet.o
"_sqlite3_column_type", referenced from:
-[FMResultSet stringForColumnIndex:] in FMResultSet.o
-[FMResultSet dateForColumnIndex:] in FMResultSet.o
-[FMResultSet dataForColumnIndex:] in FMResultSet.o
-[FMResultSet dataNoCopyForColumnIndex:] in FMResultSet.o
-[FMResultSet columnIndexIsNull:] in FMResultSet.o
-[FMResultSet UTF8StringForColumnIndex:] in FMResultSet.o
-[FMResultSet objectForColumnIndex:] in FMResultSet.o
...
"_sqlite3_column_bytes", referenced from:
-[FMResultSet dataForColumnIndex:] in FMResultSet.o
-[FMResultSet dataNoCopyForColumnIndex:] in FMResultSet.o
"_sqlite3_column_blob", referenced from:
-[FMResultSet dataForColumnIndex:] in FMResultSet.o
-[FMResultSet dataNoCopyForColumnIndex:] in FMResultSet.o
ld: symbol(s) not found for architecture i386

i am thinking it's a target/platform issue.. but i am new at this and no idea how to fix it..

thanks in advance,

Isaac

transactions over multithreading.

I need to access to the database by different threads and them have to make some transaction (involving different method calls).
Do I have to use different FMDB instances?

Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.