GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71785
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
delete_tab.c
Go to the documentation of this file.
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 
15 #include <grass/dbmi.h>
16 #include <grass/glocale.h>
17 #include "macros.h"
18 
19 /*!
20  \brief Delete table
21 
22  \param drvname driver name
23  \param dbname database name
24  \param tblname table name
25 
26  \return DB_OK on success
27  \return DB_FAILED on failure
28  */
29 int db_delete_table(const char *drvname, const char *dbname, const char *tblname)
30 {
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, "%s", 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:25
int db_close_database_shutdown_driver(dbDriver *driver)
Close driver/database connection.
Definition: db.c:62
#define NULL
Definition: ccmath.h:32
char * db_get_string(const dbString *x)
Get string.
Definition: string.c:140
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)
Append string to dbString.
Definition: string.c:205
int db_delete_table(const char *drvname, const char *dbname, const char *tblname)
Delete table.
Definition: delete_tab.c:29
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: debug.c:65
#define DB_FAILED
Definition: dbmi.h:72
int db_set_string(dbString *x, const char *s)
Inserts string to dbString (enlarge string)
Definition: string.c:41
#define _(str)
Definition: glocale.h:13
void G_warning(const char *msg,...)
Print a warning message to stderr.
Definition: gis/error.c:203
void db_init_string(dbString *x)
Initialize dbString.
Definition: string.c:25
#define DB_OK
Definition: dbmi.h:71