GRASS 8 Programmer's Manual 8.6.0dev(2026)-1878fdfec5
Loading...
Searching...
No Matches
db.c
Go to the documentation of this file.
1/*!
2 * \file db/dbmi_client/db.c
3 *
4 * \brief DBMI Library (client) - open/close driver/database connection
5 *
6 * SPDX-FileCopyrightText: 1999-2009 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author Joel Jones (CERL/UIUC), Radim Blazek
10 */
11
12#include <grass/dbmi.h>
13#include <grass/glocale.h>
14#include "macros.h"
15
16/*!
17 \brief Open driver/database connection
18
19 \param drvname driver name
20 \param dbname database name
21
22 \return pointer to dbDriver structure
23 \return NULL on failure
24 */
25dbDriver *db_start_driver_open_database(const char *drvname, const char *dbname)
26{
27 dbHandle handle;
29
30 G_debug(3, "db_start_driver_open_database(): drvname='%s', dbname='%s'",
31 drvname, dbname);
32
33 db_init_handle(&handle);
34
36 if (driver == NULL) {
37 G_warning(_("Unable to start driver <%s>"), drvname);
38 return NULL;
39 }
40 db_set_handle(&handle, dbname, NULL);
41 if (db_open_database(driver, &handle) != DB_OK) {
42 G_warning(_("Unable to open database <%s> by driver <%s>"), dbname,
43 drvname);
45 return NULL;
46 }
47
48 return driver;
49}
50
51/*!
52 \brief Close driver/database connection
53
54 \param driver db driver
55
56 \return DB_OK or DB_FAILED
57 */
59{
60 int status;
61
62 status = db_close_database(driver);
63 G_debug(2, "db_close_database() result: %d (%d means success)", status,
64 DB_OK);
65
66 if (db_shutdown_driver(driver) != 0) {
67 status = DB_FAILED;
68 G_debug(2, "db_shutdown_driver() failed");
69 }
70
71 return status;
72}
#define NULL
Definition ccmath.h:32
dbDriver * db_start_driver_open_database(const char *drvname, const char *dbname)
Open driver/database connection.
Definition db.c:25
int db_close_database_shutdown_driver(dbDriver *driver)
Close driver/database connection.
Definition db.c:58
Main header of GRASS DataBase Management Interface.
#define DB_FAILED
Definition dbmi.h:70
#define DB_OK
Definition dbmi.h:69
int db_shutdown_driver(dbDriver *)
Closedown the driver, and free the driver structure.
Definition shutdown.c:33
int db_open_database(dbDriver *, dbHandle *)
Open database connection.
Definition c_opendb.c:24
int db_set_handle(dbHandle *, const char *, const char *)
Set handle (database and schema name)
Definition handle.c:36
int db_close_database(dbDriver *)
Close database connection.
Definition c_closedb.c:23
dbDriver * db_start_driver(const char *)
Initialize a new dbDriver for db transaction.
Definition start.c:48
void db_init_handle(dbHandle *)
Initialize handle (i.e database/schema)
Definition handle.c:20
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
#define _(str)
Definition glocale.h:10