GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
db.c
Go to the documentation of this file.
1 
15 #include <grass/dbmi.h>
16 #include <grass/glocale.h>
17 #include "macros.h"
18 
28 dbDriver *db_start_driver_open_database(const char *drvname,
29  const char *dbname)
30 {
31  dbHandle handle;
32  dbDriver *driver;
33 
34  G_debug(3, "db_start_driver_open_database():\n drvname = %s, dbname = %s",
35  drvname, dbname);
36 
37  db_init_handle(&handle);
38 
39  driver = db_start_driver(drvname);
40  if (driver == NULL) {
41  G_warning(_("Unable to start driver <%s>"), drvname);
42  return NULL;
43  }
44  db_set_handle(&handle, dbname, NULL);
45  if (db_open_database(driver, &handle) != DB_OK) {
46  G_warning(_("Unable to open database <%s> by driver <%s>"),
47  dbname, drvname);
48  db_shutdown_driver(driver);
49  return NULL;
50  }
51 
52  return driver;
53 }
54 
63 {
64  int status;
65 
66  status = db_close_database(driver);
67  G_debug(2, "db_close_database() result: %d (%d means success)",
68  status, DB_OK);
69 
70  if (db_shutdown_driver(driver) != 0) {
71  status = DB_FAILED;
72  G_debug(2, "db_shutdown_driver() failed");
73  }
74 
75  return status;
76 }
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_shutdown_driver(dbDriver *driver)
Closedown the driver, and free the driver structure.
Definition: shutdown.c:36
int db_close_database(dbDriver *driver)
Close database connection.
Definition: c_closedb.c:26
int db_set_handle(dbHandle *handle, const char *dbName, const char *dbSchema)
Definition: handle.c:22
return NULL
Definition: dbfopen.c:1394
Definition: driver.h:25
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
void db_init_handle(dbHandle *handle)
Definition: handle.c:10
int db_open_database(dbDriver *driver, dbHandle *handle)
Open database connection.
Definition: c_opendb.c:27
dbDriver * db_start_driver(const char *name)
Initialize a new dbDriver for db transaction.
Definition: start.c:43