-
Notifications
You must be signed in to change notification settings - Fork 498
Open
Description
It would be nice to have a way to drop a table which may not exist other than
try {
sql << "drop table soci_test";
}
catch (...) {}
which is used now in SOCI's own tests. Of course, most databases support DROP TABLE IF EXISTS
nowadays, but some of them don't and I wonder if we can provide workarounds for them.
- DB2: no
if exists
, can do something likeSELECT * FROM information_schema.tables WHERE TABLE_SCHEMA = 'MY_SCHEMA' AND TABLE_NAME = 'MY_TABLE';
according to this SO answer. - Firebird: doesn't seem to have support for
if exists
, does have RECREATE TABLE. - MySQL: supports
if exists
. - Oracle: only supports
if exists
since 23c, this SO answer shows how to ignore exception fromDROP TABLE
. - PostgreSQL: supports
if exists
. - SQLite: supports
if exists
. - SQL Server (via ODBC): can use
select object_id('table_name','u')
to check if it exists.
Thinking more about this, maybe what we really want is a way to execute an SQL statement without throwing an exception on error, so that we could use it to ignore the error from drop table
without throwing (and catching).
Metadata
Metadata
Assignees
Labels
No labels