~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/db/dbmi_base/connect.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
  \file lib/db/dbmi_base/connect.c
 
3
  
 
4
  \brief DBMI Library (base) - connect to DB
 
5
  
 
6
  (C) 1999-2009, 2011 by the GRASS Development Team
 
7
  
 
8
  This program is free software under the GNU General Public License
 
9
  (>=v2). Read the file COPYING that comes with GRASS for details.
 
10
  
 
11
  \author Joel Jones (CERL/UIUC), Radim Blazek
 
12
  \author Doxygenized by Martin Landa <landa.martin gmail.com> (2011)
 
13
*/
 
14
 
1
15
#include <grass/gis.h>
2
16
#include <grass/dbmi.h>
3
17
 
4
18
/*!
5
 
   \fn int db_set_connection (dbConnection *connection )
6
 
   \brief set default db connection settings
7
 
   \return DB_OK
8
 
   \param dbConnection
 
19
  \brief Set default DB connection settings
 
20
 
 
21
  This function sets environmental variables as DB_DRIVER, DB_DATABASE,
 
22
  DB_SCHEMA, DB_GROUP.
 
23
 
 
24
  \param connection pointer to dbConnection with default settings
 
25
  
 
26
  \return DB_OK
9
27
 */
10
28
int db_set_connection(dbConnection * connection)
11
29
{
41
59
}
42
60
 
43
61
/*!
44
 
   \fn int db_get_connection (dbConnection *connection )
45
 
   \brief get default db connection settings
46
 
   \return DB_OK
47
 
   \param dbConnection
 
62
  \brief Get default DB connection settings
 
63
  
 
64
  \param[out] connection pointer to dbConnection to be modified
 
65
 
 
66
  \return DB_OK
 
67
  \return DB_FAILED
48
68
 */
49
69
int db_get_connection(dbConnection * connection)
50
70
{
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");
 
71
    G_zero(connection, sizeof(dbConnection));
 
72
    
 
73
    connection->driverName = (char *)G_getenv_nofatal2("DB_DRIVER", G_VAR_MAPSET);
 
74
    connection->databaseName = (char *)G_getenv_nofatal2("DB_DATABASE", G_VAR_MAPSET);
 
75
    
 
76
    if (connection->driverName == NULL ||
 
77
        connection->databaseName == NULL)
 
78
        return DB_FAILED;
 
79
    
 
80
    connection->schemaName = (char *)G_getenv_nofatal2("DB_SCHEMA", G_VAR_MAPSET);
 
81
    connection->group = (char *)G_getenv_nofatal2("DB_GROUP", G_VAR_MAPSET);
 
82
 
 
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");
63
88
     */
64
89
 
 
90
    /* try to get user/password */
 
91
    db_get_login(connection->driverName, connection->databaseName,
 
92
                 (const char **) &(connection->user),
 
93
                 (const char **) &(connection->password));
 
94
    
65
95
    return DB_OK;
66
96
}