| Index: sql/connection.cc
|
| ===================================================================
|
| --- sql/connection.cc (revision 113546)
|
| +++ sql/connection.cc (working copy)
|
| @@ -268,14 +268,24 @@
|
| }
|
|
|
| bool Connection::DoesTableExist(const char* table_name) const {
|
| + return DoesTableOrIndexExist(table_name, "table");
|
| +}
|
| +
|
| +bool Connection::DoesIndexExist(const char* index_name) const {
|
| + return DoesTableOrIndexExist(index_name, "index");
|
| +}
|
| +
|
| +bool Connection::DoesTableOrIndexExist(
|
| + const char* name, const char* type) const {
|
| // GetUniqueStatement can't be const since statements may modify the
|
| // database, but we know ours doesn't modify it, so the cast is safe.
|
| Statement statement(const_cast<Connection*>(this)->GetUniqueStatement(
|
| "SELECT name FROM sqlite_master "
|
| - "WHERE type='table' AND name=?"));
|
| + "WHERE type=? AND name=?"));
|
| if (!statement)
|
| return false;
|
| - statement.BindString(0, table_name);
|
| + statement.BindString(0, type);
|
| + statement.BindString(1, name);
|
| return statement.Step(); // Table exists if any row was returned.
|
| }
|
|
|
|
|