2
/****************************************************************************
5
* AUTHOR(S): Soeren Gebbert, based on db.connect
7
* PURPOSE: Prints/sets general temporal GIS database connection for current mapset.
8
* COPYRIGHT: (C) 2002-2010 by the GRASS Development Team
10
* This program is free software under the GNU General Public
11
* License (>=v2). Read the file COPYING that comes with GRASS
14
*****************************************************************************/
18
#include <grass/gis.h>
19
#include <grass/temporal.h>
20
#include <grass/glocale.h>
22
int main(int argc, char *argv[])
25
struct Flag *print, *check_set_default, *def, *sh;
26
struct Option *driver, *database;
27
struct GModule *module;
29
/* Initialize the GIS calls */
33
module = G_define_module();
34
G_add_keyword(_("database"));
35
G_add_keyword(_("attribute table"));
36
G_add_keyword(_("connection settings"));
38
_("Prints/sets general temporal GIS database connection for current mapset.");
40
print = G_define_flag();
42
print->description = _("Print current connection parameters and exit");
43
print->guisection = _("Print");
45
check_set_default = G_define_flag();
46
check_set_default->key = 'c';
47
check_set_default->description =
48
_("Check connection parameters, set if uninitialized, and exit");
49
check_set_default->guisection = _("Set");
51
def = G_define_flag();
53
def->label = _("Set from default settings and exit");
54
def->description = _("Overwrite current settings if initialized");
55
def->guisection = _("Set");
59
sh->description = _("Print current connection parameter in shell style and exit");
60
sh->guisection = _("Set");
62
driver = G_define_standard_option(G_OPT_DB_DRIVER);
63
driver->options = "sqlite,pg";
64
driver->answer = (char *) tgis_get_default_driver_name();
65
driver->guisection = _("Set");
67
database = G_define_standard_option(G_OPT_DB_DATABASE);
68
database->answer = (char *) tgis_get_default_database_name();
69
database->guisection = _("Set");
71
if (G_parser(argc, argv))
76
if (tgis_get_connection(&conn) == DB_OK) {
77
fprintf(stdout, "driver=%s\n",
78
conn.driverName ? conn.driverName : "");
79
fprintf(stdout, "database=%s\n",
80
conn.databaseName ? conn.databaseName : "");
83
G_fatal_error(_("Temporal GIS database connection not defined. "
87
/* get and print connection */
88
if (tgis_get_connection(&conn) == DB_OK) {
89
fprintf(stdout, "driver:%s\n",
90
conn.driverName ? conn.driverName : "");
91
fprintf(stdout, "database:%s\n",
92
conn.databaseName ? conn.databaseName : "");
95
G_fatal_error(_("Temporal GIS database connection not defined. "
102
if (check_set_default->answer) {
103
/* check connection and set to system-wide default in required */
104
tgis_get_connection(&conn);
106
if (!conn.driverName && !conn.databaseName) {
108
tgis_set_default_connection();
109
tgis_get_connection(&conn);
111
G_important_message(_("Default TGIS driver / database set to:\n"
112
"driver: %s\ndatabase: %s"), conn.driverName,
115
/* they must be a matched pair, so if one is set but not the other
116
then give up and let the user figure it out */
117
else if (!conn.driverName) {
118
G_fatal_error(_("Default TGIS driver is not set"));
120
else if (!conn.databaseName) {
121
G_fatal_error(_("Default TGIS database is not set"));
124
/* connection either already existed or now exists */
130
tgis_set_default_connection();
131
tgis_get_connection(&conn);
133
G_important_message(_("Default driver / database set to:\n"
134
"driver: %s\ndatabase: %s"), conn.driverName,
140
tgis_get_connection(&conn); /* read current */
143
conn.driverName = driver->answer;
145
if (database->answer)
146
conn.databaseName = database->answer;
148
tgis_set_connection(&conn);