How can I determine in a table already exists before I start adding data to it again, in as few lines of code as possible?
views:
31answers:
2
Q:
iPhone, sqlite3, how can I determine is a table exists already in a few lines of code as possible?
A:
If you are using sqlite directly, you can use the following query to see if the table already exists:
SELECT name FROM sqlite_master WHERE type='table' AND name='my_table_name';
Mr. Matt
2010-09-29 09:40:57
Yeah I've seen that just wondered if there was a quicker way or an inbuilt function ?
Jules
2010-09-29 09:46:36
A:
sqlite3_stmt *statementChk;
sqlite3_prepare_v2(database, "SELECT name FROM sqlite_master WHERE type='table' AND name='util_nums';", -1, &statementChk, nil);
bool boo = FALSE;
if (sqlite3_step(statementChk) == SQLITE_ROW) {
boo = TRUE;
}
sqlite3_finalize(statementChkUN);
Jules
2010-09-29 11:57:05