GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
delete_tab.c
Go to the documentation of this file.
1 
15 #include <grass/dbmi.h>
16 #include <grass/glocale.h>
17 #include "macros.h"
18 
29 int db_delete_table(const char *drvname, const char *dbname, const char *tblname)
30 {
31  dbDriver *driver;
32  dbString sql;
33 
34  G_debug(3, "db_delete_table(): driver = %s, db = %s, table = %s\n",
35  drvname, dbname, tblname);
36 
37  /* Open driver and database */
38  driver = db_start_driver_open_database(drvname, dbname);
39  if (driver == NULL) {
40  G_warning(_("Unable open database <%s> by driver <%s>"), dbname,
41  drvname);
42  return DB_FAILED;
43  }
44 
45  /* Delete table */
46  /* TODO test if the tables exist */
47  db_init_string(&sql);
48  db_set_string(&sql, "drop table ");
49  db_append_string(&sql, tblname);
50  G_debug(3, db_get_string(&sql));
51 
52  if (db_execute_immediate(driver, &sql) != DB_OK) {
53  G_warning(_("Unable to drop table: '%s'"),
54  db_get_string(&sql));
56  return DB_FAILED;
57  }
58 
60 
61  return DB_OK;
62 }
dbDriver * db_start_driver_open_database(const char *drvname, const char *dbname)
Open driver/database connection.
Definition: db.c:28
struct driver * driver
Definition: driver/init.c:26
int db_close_database_shutdown_driver(dbDriver *driver)
Close driver/database connection.
Definition: db.c:62
int db_execute_immediate(dbDriver *driver, dbString *SQLstatement)
Execute SQL statements.
Definition: c_execute.c:27
int db_append_string(dbString *x, const char *s)
Definition: string.c:193
int db_delete_table(const char *drvname, const char *dbname, const char *tblname)
Delete table.
Definition: delete_tab.c:29
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
char * db_get_string(dbString *x)
Definition: string.c:131
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
int db_set_string(dbString *x, const char *s)
Definition: string.c:33
void db_init_string(dbString *x)
Definition: string.c:11