delete_tab.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. * \file db/dbmi_client/delete_tab.c
  3. *
  4. * \brief DBMI Library (client) - delete table
  5. *
  6. * (C) 1999-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public
  9. * License (>=v2). Read the file COPYING that comes with GRASS
  10. * for details.
  11. *
  12. * \author Joel Jones (CERL/UIUC), Radim Blazek
  13. */
  14. #include <grass/dbmi.h>
  15. #include <grass/glocale.h>
  16. #include "macros.h"
  17. /*!
  18. \brief Delete table
  19. \param drvname driver name
  20. \param dbname database name
  21. \param tblname table name
  22. \return DB_OK on success
  23. \return DB_FAILED on failure
  24. */
  25. int db_delete_table(const char *drvname, const char *dbname, const char *tblname)
  26. {
  27. dbDriver *driver;
  28. dbString sql;
  29. G_debug(3, "db_delete_table(): driver = %s, db = %s, table = %s\n",
  30. drvname, dbname, tblname);
  31. /* Open driver and database */
  32. driver = db_start_driver_open_database(drvname, dbname);
  33. if (driver == NULL) {
  34. G_warning(_("Unable open database <%s> by driver <%s>"), dbname,
  35. drvname);
  36. return DB_FAILED;
  37. }
  38. /* Delete table */
  39. /* TODO test if the tables exist */
  40. db_init_string(&sql);
  41. db_set_string(&sql, "drop table ");
  42. db_append_string(&sql, tblname);
  43. G_debug(3, "%s", db_get_string(&sql));
  44. if (db_execute_immediate(driver, &sql) != DB_OK) {
  45. G_warning(_("Unable to drop table: '%s'"),
  46. db_get_string(&sql));
  47. db_close_database_shutdown_driver(driver);
  48. return DB_FAILED;
  49. }
  50. db_close_database_shutdown_driver(driver);
  51. return DB_OK;
  52. }