[GRASS-SVN] r73039 - grass/branches/releasebranch_7_4/db/db.connect
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Aug 3 14:18:25 PDT 2018
Author: mmetz
Date: 2018-08-03 14:18:24 -0700 (Fri, 03 Aug 2018)
New Revision: 73039
Modified:
grass/branches/releasebranch_7_4/db/db.connect/main.c
Log:
db.connect: use GRASS default, not current parameters as default answer, fix setting from default and from user options (see #3601; backport trunk r72942)
Modified: grass/branches/releasebranch_7_4/db/db.connect/main.c
===================================================================
--- grass/branches/releasebranch_7_4/db/db.connect/main.c 2018-08-03 21:15:04 UTC (rev 73038)
+++ grass/branches/releasebranch_7_4/db/db.connect/main.c 2018-08-03 21:18:24 UTC (rev 73039)
@@ -69,17 +69,28 @@
def->description = _("Overwrite current settings if already initialized");
def->guisection = _("Set");
+ /* the default answers below are GRASS default settings,
+ * not current settings */
driver = G_define_standard_option(G_OPT_DB_DRIVER);
driver->options = db_list_drivers();
- driver->answer = (char *) db_get_default_driver_name();
+ if (strcmp(DB_DEFAULT_DRIVER, "sqlite") == 0) {
+ driver->answer = "sqlite";
+ }
+ else {
+ driver->answer = "dbf";
+ }
driver->guisection = _("Set");
database = G_define_standard_option(G_OPT_DB_DATABASE);
- database->answer = (char *) db_get_default_database_name();
+ if (strcmp(DB_DEFAULT_DRIVER, "sqlite") == 0) {
+ database->answer = "$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db";
+ }
+ else {
+ database->answer = "$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/";
+ }
database->guisection = _("Set");
schema = G_define_standard_option(G_OPT_DB_SCHEMA);
- schema->answer = (char *) db_get_default_schema_name();
schema->guisection = _("Set");
group = G_define_option();
@@ -87,7 +98,6 @@
group->type = TYPE_STRING;
group->required = NO;
group->multiple = NO;
- group->answer = (char*) db_get_default_group_name();
group->description = _("Default group of database users to which "
"select privilege is granted");
group->guisection = _("Set");
@@ -179,7 +189,6 @@
exit(EXIT_SUCCESS);
}
-
if (def->answer) {
db_set_default_connection();
db_get_connection(&conn);
@@ -191,8 +200,8 @@
exit(EXIT_SUCCESS);
}
- /* set connection */
- db_get_connection(&conn); /* read current */
+ /* do not read current, set new connection from options */
+ G_zero(&conn, sizeof(dbConnection));
if (driver->answer)
conn.driverName = driver->answer;
@@ -207,7 +216,12 @@
conn.group = group->answer;
db_set_connection(&conn);
+ /* check */
+ if (db_get_connection(&conn) != DB_OK) {
+ G_fatal_error(_("Unable to set default database connection"));
+ exit(EXIT_FAILURE);
+ }
exit(EXIT_SUCCESS);
}
More information about the grass-commit
mailing list