Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mikezang

macrumors 6502a
Original poster
May 22, 2010
939
41
Tokyo, Japan
I try to create a Sqlite3 wrapper class for easy to use.

I can get the select result in NSArray with NSDictionary items using as code as below, my question is what I want to instead of NSMutableDictionary *row to MyDatatClass *row, and MyDataClass is not fixed, I want to this wrapper class can be used for all of my data class, what can I do?:
Code:
-(NSArray *) selectData:(NSString *) sql {
    NSMutableArray *rows = [NSMutableArray array];

    sqlite3_stmt *statement = NULL;
	
    if (sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL) == SQLITE) {
        while (sqlite3_step(statement) == SQLITE_ROW) {
            NSMutableDictionary *row = [[NSMutableDictionary alloc] init];

            [self copyValuesFromStatement:statement toRow:row];
            [rows addObject:row];
            [row release];
        }
    }

    sqlite3_finalize(statement);
    return rows;
}
 
Do you mean this site New Home for FMDB ?
it was stopped in 2008, are you sure?

Don't stop at the first google result. And read the page's links.

If you did that, you'd see it as the second result in this search:
http://www.google.com/search?client=safari&rls=en&q=fmdb&ie=UTF-8&oe=UTF-8

And the google-code project was updated in July 2010:
http://code.google.com/p/flycode/source/browse/trunk/fmdb

If you read its Project Home page, you'll see it was moved to github, and last updated in Aug 2010.
 
Don't stop at the first google result. And read the page's links.

If you did that, you'd see it as the second result in this search:
http://www.google.com/search?client=safari&rls=en&q=fmdb&ie=UTF-8&oe=UTF-8

And the google-code project was updated in July 2010:
http://code.google.com/p/flycode/source/browse/trunk/fmdb

If you read its Project Home page, you'll see it was moved to github, and last updated in Aug 2010.
Thanks, I browsed new page and I found text there "Formatting updates, along with a new method for getting a dictionary back from a result set. ", this result is what I got, I want to get a result with a custom class, not NSDictionary, may I make sense?
 
If your question is: can I use FMDB to get a data set back from sqlite where the results are stored in my custom class, the answer is YES.

FMDB is short on docs and examples, but you do get all the source code. If you look at the example app you should see how you get back values from a db and you can store them in a custom class if you want. Personally I almost always put them either directly into a dictionary or into a custom container class that uses a dictionary for storage. It's extremely flexible that way and matches the concept of a row in a db very closely.

Also, fwiw, I haven't used the latest method that you mention to automatically get back a dictionary. I access the result set to read out its contents and then store them in the dictionary (usually).
 
Well, I also found there is a sample to wrapper SQLite3 and get data for Model in book "iPhone Advanced Projects", it is very simple, then FMDB has too many contents so the performance maybe not good...

I want to know which way is better? FMDB or sample in that book?
 
Well, I also found there is a sample to wrapper SQLite3 and get data for Model in book "iPhone Advanced Projects", it is very simple, then FMDB has too many contents so the performance maybe not good...

I want to know which way is better? FMDB or sample in that book?

You'll have to measure them yourself. On the devices that matter to you.

You're the only one who can do this, because you're the only one who knows what all your data is, how it's represented, how it's indexed, how it's retrieved, and what all the relevant performance constraints are.

You ask the question as if there's one answer. There isn't. Every situation is different. Data representations, indexes, select clauses, etc. all have an effect.
 
You'll have to measure them yourself. On the devices that matter to you.

You're the only one who can do this, because you're the only one who knows what all your data is, how it's represented, how it's indexed, how it's retrieved, and what all the relevant performance constraints are.

You ask the question as if there's one answer. There isn't. Every situation is different. Data representations, indexes, select clauses, etc. all have an effect.
Thanks for this suggestion.

You are right, I have to confirm it by myself.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.