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 like SELECT * 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 from DROP 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).
It would be nice to have a way to drop a table which may not exist other than
which is used now in SOCI's own tests. Of course, most databases support
DROP TABLE IF EXISTSnowadays, but some of them don't and I wonder if we can provide workarounds for them.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.if exists, does have RECREATE TABLE.if exists.if existssince 23c, this SO answer shows how to ignore exception fromDROP TABLE.if exists.if exists.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 tablewithout throwing (and catching).