views:

31

answers:

2

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?

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
Yeah I've seen that just wondered if there was a quicker way or an inbuilt function ?
Jules
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