GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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 }
void db_init_string(dbString *)
Initialize dbString.
Definition: string.c:25
char * db_get_string(const dbString *)
Get string.
Definition: string.c:140
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
Definition: db.c:28
#define NULL
Definition: ccmath.h:32
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
Definition: string.c:41
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
Definition: db.c:62
int db_append_string(dbString *, const char *)
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 db_execute_immediate(dbDriver *, dbString *)
Execute SQL statements.
Definition: c_execute.c:27
const struct driver * driver
Definition: driver/init.c:25
#define DB_FAILED
Definition: dbmi.h:72
void G_warning(const char *,...) __attribute__((format(printf
#define _(str)
Definition: glocale.h:10
int G_debug(int, const char *,...) __attribute__((format(printf
#define DB_OK
Definition: dbmi.h:71