2
\file lib/db/dbmi_base/connect.c
4
\brief DBMI Library (base) - connect to DB
6
(C) 1999-2009, 2011 by the GRASS Development Team
8
This program is free software under the GNU General Public License
9
(>=v2). Read the file COPYING that comes with GRASS for details.
11
\author Joel Jones (CERL/UIUC), Radim Blazek
12
\author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
1
15
#include <grass/gis.h>
2
16
#include <grass/dbmi.h>
5
\fn int db_set_connection (dbConnection *connection )
6
\brief set default db connection settings
19
\brief Set default DB connection settings
21
This function sets environmental variables as DB_DRIVER, DB_DATABASE,
24
\param connection pointer to dbConnection with default settings
10
28
int db_set_connection(dbConnection * connection)
44
\fn int db_get_connection (dbConnection *connection )
45
\brief get default db connection settings
62
\brief Get default DB connection settings
64
\param[out] connection pointer to dbConnection to be modified
49
69
int db_get_connection(dbConnection * connection)
51
/* TODO: add checks and return DB_* error code if needed */
53
connection->driverName = G__getenv2("DB_DRIVER", G_VAR_MAPSET);
54
connection->databaseName = G__getenv2("DB_DATABASE", G_VAR_MAPSET);
55
connection->schemaName = G__getenv2("DB_SCHEMA", G_VAR_MAPSET);
56
connection->group = G__getenv2("DB_GROUP", G_VAR_MAPSET);
58
/* below commented due to new mechanism:
59
connection->hostName = G__getenv("DB_HOST");
60
connection->location = G__getenv("DB_LOCATION");
61
connection->user = G__getenv("DB_USER");
62
connection->password = G__getenv("DB_PASSWORD");
71
G_zero(connection, sizeof(dbConnection));
73
connection->driverName = (char *)G_getenv_nofatal2("DB_DRIVER", G_VAR_MAPSET);
74
connection->databaseName = (char *)G_getenv_nofatal2("DB_DATABASE", G_VAR_MAPSET);
76
if (connection->driverName == NULL ||
77
connection->databaseName == NULL)
80
connection->schemaName = (char *)G_getenv_nofatal2("DB_SCHEMA", G_VAR_MAPSET);
81
connection->group = (char *)G_getenv_nofatal2("DB_GROUP", G_VAR_MAPSET);
83
/* below commented due to new mechanism: see db_get_login()
84
connection->hostName = G_getenv_nofatal("DB_HOST");
85
connection->location = G_getenv_nofatal("DB_LOCATION");
86
connection->user = G_getenv_nofatal("DB_USER");
87
connection->password = G_getenv_nofatal("DB_PASSWORD");
90
/* try to get user/password */
91
db_get_login(connection->driverName, connection->databaseName,
92
(const char **) &(connection->user),
93
(const char **) &(connection->password));