GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
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,
30  const char *tblname)
31 {
33  dbString sql;
34 
35  G_debug(3, "db_delete_table(): driver = %s, db = %s, table = %s\n", drvname,
36  dbname, tblname);
37 
38  /* Open driver and database */
39  driver = db_start_driver_open_database(drvname, dbname);
40  if (driver == NULL) {
41  G_warning(_("Unable open database <%s> by driver <%s>"), dbname,
42  drvname);
43  return DB_FAILED;
44  }
45 
46  /* Delete table */
47  /* TODO test if the tables exist */
48  db_init_string(&sql);
49  db_set_string(&sql, "drop table ");
50  db_append_string(&sql, tblname);
51  G_debug(3, "%s", db_get_string(&sql));
52 
53  if (db_execute_immediate(driver, &sql) != DB_OK) {
54  G_warning(_("Unable to drop table: '%s'"), db_get_string(&sql));
56  return DB_FAILED;
57  }
58 
60 
61  return DB_OK;
62 }
#define NULL
Definition: ccmath.h:32
#define DB_FAILED
Definition: dbmi.h:72
#define DB_OK
Definition: dbmi.h:71
dbDriver * db_start_driver_open_database(const char *, const char *)
Open driver/database connection.
Definition: db.c:28
int db_close_database_shutdown_driver(dbDriver *)
Close driver/database connection.
Definition: db.c:61
int db_set_string(dbString *, const char *)
Inserts string to dbString (enlarge string)
Definition: string.c:41
int db_execute_immediate(dbDriver *, dbString *)
Execute SQL statements.
Definition: c_execute.c:27
void db_init_string(dbString *)
Initialize dbString.
Definition: string.c:25
int db_append_string(dbString *, const char *)
Append string to dbString.
Definition: string.c:205
char * db_get_string(const dbString *)
Get string.
Definition: string.c:140
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
int db_delete_table(const char *drvname, const char *dbname, const char *tblname)
Delete table.
Definition: delete_tab.c:29
const struct driver * driver
Definition: driver/init.c:25
#define _(str)
Definition: glocale.h:10
Definition: driver.h:21