sqlite with multiple tables?

What's the cleanest way to deal with accessing multiple tables defined by the user?
All the examples I've seen deal with hard coded table names and the prepare statement doesn't care to have a ? for a table to be binded later.
Thanks.

G5 2.5Ghz, MacBook Pro, Mac OS X (10.5.2)

Posted on May 30, 2008 1:32 PM

Reply
2 replies

May 30, 2008 3:44 PM in response to Scott Squires1

i don't think sql in general works like that. i've only ever seen bindings to parameters. that being said, you could use a string format for table names:


CrudStmtHolder *holder;
sqlite3_stmt *stmt;
NSSring *selectSmt = [NSString stringWithFormat:@"select * from %@ where id = ?", tableName];
sqlite3preparev2(database, [selectStmt UTF8String], -1, &stmt, NULL);
holder.select = stmt;
// do same for create update & delete


then, if you knew there was going to be a reasonably small number of different select, inserts and deletes, you could use a dictionary to hold your prepared statements. CrudStmtHolder could be a class that holds the different statement types for a given table name and the dictionary could be keyed by table name.

is that the type of thing you are lookin for?

Message was edited by: johne-dm who needs to start using the "preview" function

May 30, 2008 4:52 PM in response to johne-dm

I'm doing something like that now and saving statements since I'm not constantly changing tables.
Just thought there would be a cleaner way of doing it.

sqlite supports multiple tables that's why I'm using them. I could make a different file for each table but that's questionable for some apps. I could ID them with a group ID but that makes it messy.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

sqlite with multiple tables?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.