GRASS Programmer's Manual  6.4.2(2012)
 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 }