GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
connect.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 #include <grass/dbmi.h>
3 
10 int db_set_connection(dbConnection * connection)
11 {
12  /* TODO: add checks and return DB_* error code if needed */
13 
14  if (connection->driverName)
15  G_setenv2("DB_DRIVER", connection->driverName, G_VAR_MAPSET);
16 
17  if (connection->databaseName)
18  G_setenv2("DB_DATABASE", connection->databaseName, G_VAR_MAPSET);
19 
20  if (connection->schemaName)
21  G_setenv2("DB_SCHEMA", connection->schemaName, G_VAR_MAPSET);
22 
23  if (connection->group)
24  G_setenv2("DB_GROUP", connection->group, G_VAR_MAPSET);
25 
26  /* below commented due to new mechanism:
27  if ( connection->hostName )
28  G_setenv("DB_HOST", connection->hostName);
29 
30  if ( connection->location )
31  G_setenv("DB_LOCATION", connection->location);
32 
33  if ( connection->user )
34  G_setenv("DB_USER", connection->user);
35 
36  if ( connection->password )
37  G_setenv("DB_PASSWORD", connection->password);
38  */
39 
40  return DB_OK;
41 }
42 
49 int db_get_connection(dbConnection * connection)
50 {
51  /* TODO: add checks and return DB_* error code if needed */
52 
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);
57 
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");
63  */
64 
65  return DB_OK;
66 }
int G_setenv2(const char *name, const char *value, int loc)
Set environment variable from specific place.
Definition: env.c:372
char * G__getenv2(const char *name, int loc)
Get environment variable from specific place.
Definition: env.c:331
int db_get_connection(dbConnection *connection)
get default db connection settings
Definition: connect.c:49
int db_set_connection(dbConnection *connection)
set default db connection settings
Definition: connect.c:10