[GRASS-SVN] r64390 - in grass/branches/releasebranch_7_0/vector: v.overlay v.patch v.reclass v.vect.stats
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 2 00:08:49 PST 2015
Author: mmetz
Date: 2015-02-02 00:08:49 -0800 (Mon, 02 Feb 2015)
New Revision: 64390
Modified:
grass/branches/releasebranch_7_0/vector/v.overlay/main.c
grass/branches/releasebranch_7_0/vector/v.patch/main.c
grass/branches/releasebranch_7_0/vector/v.reclass/main.c
grass/branches/releasebranch_7_0/vector/v.vect.stats/main.c
Log:
v.patch v.reclass v.overlay v.vect.stats: accommodate SQLite (backport from trunk)
Modified: grass/branches/releasebranch_7_0/vector/v.overlay/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.overlay/main.c 2015-02-02 08:02:05 UTC (rev 64389)
+++ grass/branches/releasebranch_7_0/vector/v.overlay/main.c 2015-02-02 08:08:49 UTC (rev 64390)
@@ -237,8 +237,6 @@
Fi->database, Fi->driver);
}
db_set_error_handler_driver(driver);
-
- db_begin_transaction(driver);
}
else {
driver = NULL;
@@ -392,12 +390,20 @@
continue;
}
- in_driver =
- db_start_driver_open_database(inFi->driver, inFi->database);
- if (in_driver == NULL) {
- G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
- inFi->database, inFi->driver);
+ /* Open input driver and database */
+ if (strcmp(inFi->driver, Fi->driver) == 0
+ && strcmp(inFi->database, Vect_subst_var(Fi->database, &Out)) == 0) {
+ G_debug(3, "Use the same driver");
+ in_driver = driver;
}
+ else {
+ in_driver =
+ db_start_driver_open_database(inFi->driver, inFi->database);
+ if (in_driver == NULL) {
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ inFi->database, inFi->driver);
+ }
+ }
sprintf(buf, "select * from %s", inFi->table);
db_set_string(&sql, buf);
@@ -538,7 +544,8 @@
db_table_to_sql(Table, &sql);
- db_close_database_shutdown_driver(in_driver);
+ if (in_driver != driver)
+ db_close_database_shutdown_driver(in_driver);
}
}
@@ -583,6 +590,8 @@
/* Table created, now we can write dblink */
Vect_map_add_dblink(&Out, ofield[0], NULL, Fi->table, GV_KEY_COLUMN,
Fi->database, Fi->driver);
+
+ db_begin_transaction(driver);
}
/* AREA x AREA */
Modified: grass/branches/releasebranch_7_0/vector/v.patch/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.patch/main.c 2015-02-02 08:02:05 UTC (rev 64389)
+++ grass/branches/releasebranch_7_0/vector/v.patch/main.c 2015-02-02 08:08:49 UTC (rev 64390)
@@ -120,6 +120,8 @@
}
table_out = NULL;
+ fi_in = NULL;
+ fi_out = NULL;
/* Check input table structures */
if (do_table) {
if (append->answer) {
@@ -284,7 +286,8 @@
if (fi_out) {
driver_out =
db_start_driver_open_database(fi_out->driver,
- fi_out->database);
+ Vect_subst_var(fi_out->database,
+ &OutMap));
if (!driver_out) {
G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
fi_out->database, fi_out->driver);
@@ -315,6 +318,9 @@
Vect_map_add_dblink(&OutMap, 1, NULL, fi_out->table,
fi_in->key, fi_out->database, fi_out->driver);
+
+ /* avoid Vect_subst_var() below */
+ fi_out = Vect_get_field(&OutMap, 1);
}
}
@@ -353,22 +359,31 @@
if (do_table) {
fi_in = Vect_get_field(&InMap, 1);
if (fi_in) {
- driver_in =
- db_start_driver_open_database(fi_in->driver,
- fi_in->database);
- if (!driver_in) {
- G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
- fi_in->database, fi_in->driver);
+
+ /* SQLite does not like to have the same database opened twice */
+ if (strcmp(fi_in->driver, fi_out->driver) == 0
+ && strcmp(fi_in->database, fi_out->database) == 0) {
+ G_debug(3, "Use the same driver");
+ driver_in = driver_out;
}
- db_set_error_handler_driver(driver_in);
+ else {
+ driver_in =
+ db_start_driver_open_database(fi_in->driver,
+ fi_in->database);
+ if (!driver_in) {
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ fi_in->database, fi_in->driver);
+ }
+ db_set_error_handler_driver(driver_in);
+ }
db_set_string(&table_name_in, fi_in->table);
copy_records(driver_in, &table_name_in,
driver_out, &table_name_out, keycol, add_cat);
- db_close_database_shutdown_driver(driver_in);
+ if (driver_in != driver_out)
+ db_close_database_shutdown_driver(driver_in);
}
-
}
Vect_close(&InMap);
Modified: grass/branches/releasebranch_7_0/vector/v.reclass/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.reclass/main.c 2015-02-02 08:02:05 UTC (rev 64389)
+++ grass/branches/releasebranch_7_0/vector/v.reclass/main.c 2015-02-02 08:08:49 UTC (rev 64390)
@@ -171,12 +171,22 @@
Vect_map_add_dblink(&Out, field, NULL, NewFi->table, GV_KEY_COLUMN,
NewFi->database, NewFi->driver);
- Driver2 = db_start_driver_open_database(NewFi->driver,
- Vect_subst_var(NewFi->
- database,
- &Out));
- db_set_error_handler_driver(Driver2);
+ /* Open output driver and database */
+ if (strcmp(Fi->driver, NewFi->driver) == 0
+ && strcmp(Fi->database,
+ Vect_subst_var(NewFi->database, &Out)) == 0) {
+ G_debug(3, "Use the same driver");
+ Driver2 = Driver;
+ }
+ else {
+ Driver2 = db_start_driver_open_database(NewFi->driver,
+ Vect_subst_var(NewFi->
+ database,
+ &Out));
+ db_set_error_handler_driver(Driver2);
+ }
+
/* get string column length */
db_set_string(&stmt, Fi->table);
if (db_describe_table(Driver, &stmt, &table) != DB_OK) {
@@ -317,7 +327,8 @@
G_fatal_error(_("Unable to grant privileges on table <%s>"),
NewFi->table);
}
- db_close_database_shutdown_driver(Driver2);
+ if (Driver2 != Driver)
+ db_close_database_shutdown_driver(Driver2);
qsort((void *)cvarr.value, nrows, sizeof(dbCatVal), cmpcat);
}
Modified: grass/branches/releasebranch_7_0/vector/v.vect.stats/main.c
===================================================================
--- grass/branches/releasebranch_7_0/vector/v.vect.stats/main.c 2015-02-02 08:02:05 UTC (rev 64389)
+++ grass/branches/releasebranch_7_0/vector/v.vect.stats/main.c 2015-02-02 08:08:49 UTC (rev 64390)
@@ -371,11 +371,20 @@
G_fatal_error(_("Database connection not defined for layer %d"),
point_field);
- Pdriver = db_start_driver_open_database(PFi->driver, PFi->database);
- if (Pdriver == NULL)
- G_fatal_error(_("Unable to open database <%s> with driver <%s>"),
- PFi->database, PFi->driver);
+ /* Open points map driver and database */
+ if (Adriver && strcmp(AFi->driver, PFi->driver) == 0
+ && strcmp(AFi->database, PFi->database) == 0) {
+ G_debug(3, "Use the same driver");
+ Pdriver = Adriver;
+ }
+ else {
+ Pdriver = db_start_driver_open_database(PFi->driver, PFi->database);
+ if (Pdriver == NULL)
+ G_fatal_error(_("Unable to open database <%s> with driver <%s>"),
+ PFi->database, PFi->driver);
+ }
+
/* check if point column exists */
db_get_column(Pdriver, PFi->table, point_column_opt->answer, &column);
if (column) {
@@ -402,7 +411,9 @@
nrec = db_select_CatValArray(Pdriver, PFi->table, PFi->key,
point_column_opt->answer, NULL, &cvarr);
G_debug(1, "selected values = %d", nrec);
- db_close_database_shutdown_driver(Pdriver);
+
+ if (Pdriver != Adriver)
+ db_close_database_shutdown_driver(Pdriver);
}
Points = Vect_new_line_struct();
More information about the grass-commit
mailing list