Why use prepare() at all?  In my app, I am simply doing a query() on
one of the tables that I know must exist and have a row:

    protected boolean isValid(File file)
    {
        boolean ok = false;
        SQLiteDatabase _database = null;
        Cursor cursor = null;

        if (file.isFile())
        {
            try
            {
                _database =
SQLiteDatabase.openDatabase(file.getAbsolutePath(), null,
SQLiteDatabase.OPEN_READONLY);
                cursor = _database.query("MyTable", null, null, null,
null, null, null);

                if (cursor.moveToFirst())
                    ok = true;
            }
            catch (SQLiteException e)
            {
                // not ok
            }
            finally
            {
                if (cursor != null)
                    cursor.close();

                if ((_database != null) && _database.isOpen())
                    _database.close();
            }
        }

        return ok;
    }


On Oct 6, 6:36 am, Bret Foreman <[email protected]> wrote:
> The following code (used to verify that a table exists) generates an
> SQLITE_SCHEMA exception occasionally. This means the schema has
> changed since the SQL statement was compiled.
>
> It's noted in the SQLite documents that this only happens when using
> sqlite3_prepare() and one should use sqlite3_prepare_v2() instead to
> avoid this problem. Those function names refer to the C interface, not
> Android Java. Does anyone know if Android's SQLiteDatabase.query
> method uses sqlite3_prepare_v2() underneath? It would seem not. If
> not, what is the recommended way to reliably query the list of tables
> in a database?
>
>                 String[] col = {"name"};
>                 cursor = myDatabase.query(
>                                 /* table name */ "sqlite_master",
>                             /* columns */ col,
>                             /* select */ "type == 'table' AND name == '" + 
> tableName +
> "'",
>                             /* selection args */ null ,
>                             /* no grouping */ null,
>                             /* no grouping filter */ null,
>                             /* ordering */ null
>                           );

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to