// Shortcut to test if a table exists. bool Database::tableExists ( const char* apTableName ) { Statement query ( *this, "SELECT count(*) FROM sqlite_master WHERE type='table' AND name=?" ); query.bind ( 1, apTableName ); ( void ) query.executeStep(); // Cannot return false, as the above query always return a result const int Nb = query.getColumn ( 0 ); return ( 1 == Nb ); }
// Shortcut to execute a one step query and fetch the first column of the result. // WARNING: Be very careful with this dangerous method: you have to // make a COPY OF THE result, else it will be destroy before the next line // (when the underlying temporary Statement and Column objects are destroyed) // this is an issue only for pointer type result (ie. char* and blob) // (use the Column copy-constructor) Column Database::execAndGet ( const char* apQuery ) { Statement query ( *this, apQuery ); ( void ) query.executeStep(); // Can return false if no result, which will throw next line in getColumn() return query.getColumn ( 0 ); }