[GRASS-SVN] r72942 - grass/trunk/db/db.connect

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 2 09:41:14 PDT 2018


Author: mmetz
Date: 2018-07-02 09:41:14 -0700 (Mon, 02 Jul 2018)
New Revision: 72942

Modified:
   grass/trunk/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)

Modified: grass/trunk/db/db.connect/main.c
===================================================================
--- grass/trunk/db/db.connect/main.c	2018-07-02 16:40:02 UTC (rev 72941)
+++ grass/trunk/db/db.connect/main.c	2018-07-02 16:41:14 UTC (rev 72942)
@@ -69,17 +69,18 @@
     def->description = _("Overwrite current settings if already initialized");
     def->guisection = _("Set");
 
+    /* the default answers below for driver, database, schema, and group
+     * are current settings, not GRASS default settings */
     driver = G_define_standard_option(G_OPT_DB_DRIVER);
     driver->options = db_list_drivers();
-    driver->answer = (char *) db_get_default_driver_name();
+    driver->answer = "sqlite";
     driver->guisection = _("Set");
 
     database = G_define_standard_option(G_OPT_DB_DATABASE);
-    database->answer = (char *) db_get_default_database_name();
+    database->answer = "$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite/sqlite.db";
     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 +88,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 +179,6 @@
 	exit(EXIT_SUCCESS);
     }
 
-
     if (def->answer) {
 	db_set_default_connection();
 	db_get_connection(&conn);
@@ -191,8 +190,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 +206,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