Procedure
AdaBase.Driver.Base.[DB].query_drop_table (tables : String; when_exists : Boolean := False; cascade : Boolean := False)

The procedure constructs and an appropriate and driver-specific query to drop a table in the connected database. Existence checks and cascading deletions only occur if explicitly requested. Multiple tables can be dropped simulaneously by separating them with commas (however this is not supported by all drivers (e.g. Firebird, SQLite), so it's more portable to issue multiple single table query_drop_table commands).

with AdaBase;
with Connect;
with Ada.Text_IO;
with AdaBase.Logger.Facility;

procedure Wipe_Out is

   package CON renames Connect;
   package TIO renames Ada.Text_IO;
   package ALF renames AdaBase.Logger.Facility;

   numrows : AdaBase.Affected_Rows;

   bfast : constant String := "breakfast";
   cmd1  : constant String := "CREATE TABLE " & bfast &
                              " AS SELECT id, fruit FROM fruits";

begin

   CON.DR.command_standard_logger (device => ALF.screen, action => ALF.attach);

   CON.connect_database;

   --  delete breakfast table if it already exists
   --  No need to set cascade; it illustrates logging on MySQL (only)
   CON.DR.query_drop_table (tables      => bfast,
                            cascade     => True,
                            when_exists => True);

   --  create breakfast table
   numrows := CON.DR.execute (sql => cmd1);

   --  clear contents of breakfast table
   CON.DR.query_clear_table (table => bfast);

   --  drop breakfast table again (minimal arguments)
   CON.DR.query_drop_table (tables => bfast);

   CON.DR.commit;
   CON.DR.disconnect;

end Wipe_Out;

Example code: testcases/wipe_out/wipe_out.adb


2016-04-25 07:11:51    mysql :       Connect : Connection to adabase_examples database succeeded.
2016-04-25 07:11:51    mysql :          Note : Requested CASCADE has no effect on MySQL
2016-04-25 07:11:51    mysql :       Execute : DROP TABLE IF EXISTS breakfast CASCADE
2016-04-25 07:11:51    mysql :       Execute : CREATE TABLE breakfast AS SELECT id, fruit FROM fruits
2016-04-25 07:11:51    mysql :       Execute : TRUNCATE breakfast
2016-04-25 07:11:51    mysql :       Execute : DROP TABLE breakfast
2016-04-25 07:11:51    mysql :    Disconnect : Disconnect From database

Output using the MySQL driver


2016-05-12 21:13:19   sqlite :       Connect : Connection to file:///home/marino/adabase.sqlite database succeeded.
2016-05-12 21:13:19   sqlite :          Note : Requested CASCADE has no effect on SQLite
2016-05-12 21:13:19   sqlite :       Execute : DROP TABLE IF EXISTS breakfast
2016-05-12 21:13:19   sqlite :       Execute : CREATE TABLE breakfast AS SELECT id, fruit FROM fruits
2016-05-12 21:13:19   sqlite :       Execute : DELETE FROM breakfast
2016-05-12 21:13:19   sqlite :       Execute : DROP TABLE breakfast
2016-05-12 21:13:19   sqlite :    Disconnect : Disconnect From database

Output using the SQLite driver


2016-05-25 17:39:24    pgsql :       Connect : Connection to adabase_examples database succeeded.
NOTICE:  table "breakfast" does not exist, skipping
2016-05-25 17:39:24    pgsql :       Execute : DROP TABLE IF EXISTS breakfast CASCADE
2016-05-25 17:39:24    pgsql :       Execute : CREATE TABLE breakfast AS SELECT id, fruit FROM fruits
2016-05-25 17:39:24    pgsql :       Execute : TRUNCATE breakfast
2016-05-25 17:39:24    pgsql :       Execute : DROP TABLE breakfast
2016-05-25 17:39:24    pgsql :   Transaction : END TRANSACTION (COMMIT)
2016-05-25 17:39:24    pgsql :    Disconnect : Disconnect From database

Output using the PostgreSQL driver


[DB] is "MySQL.MySQL_Driver", "PostgreSQL.PostgreSQL_Driver", or "SQLite.SQLite_Driver"

See Also