table.c 948 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*!
  2. * \file table.c
  3. *
  4. * \brief Low level drop table function.
  5. *
  6. * This program is free software under the GNU General Public License
  7. * (>=v2). Read the file COPYING that comes with GRASS for details.
  8. *
  9. * \author Martin Landa <landa.martin gmail.com>
  10. *
  11. * \date 2015
  12. */
  13. #include <grass/gis.h>
  14. #include <grass/dbmi.h>
  15. #include <grass/glocale.h>
  16. #include "globals.h"
  17. #include "proto.h"
  18. /*!
  19. * \brief Low level driver drop table from database.
  20. *
  21. * \param name table name to drop
  22. * \return DB_FAILED on error; DB_OK on success
  23. */
  24. int db__driver_drop_table(dbString *name)
  25. {
  26. PGresult *res;
  27. char cmd[DB_SQL_MAX];
  28. sprintf(cmd, "DROP TABLE %s", db_get_string(name));
  29. res = PQexec(pg_conn, cmd);
  30. if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) {
  31. db_d_append_error("%s\n%s",
  32. _("Unable to execute():"),
  33. PQerrorMessage(pg_conn));
  34. db_d_report_error();
  35. return DB_FAILED;
  36. }
  37. return DB_OK;
  38. }