Skip to content

Commit

Permalink
Alter shp2pgsql-gui so that we use one connection per file; this make…
Browse files Browse the repository at this point in the history
…s tracking error state

on the server considerably easier, since upon abort we just disconnect from the server rather
than trying to figure out what state we are in and handle it appropriately.

git-svn-id: http://svn.osgeo.org/postgis/trunk@8743 b70326c6-7e19-0410-871a-916f4a2858ee
  • Loading branch information
Mark Cave-Ayland committed Jan 10, 2012
1 parent 25c22d2 commit 24752a4
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions loader/shp2pgsql-gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -979,8 +979,6 @@ pgui_action_import(GtkWidget *widget, gpointer data)


/* Once we've done the validation pass, now let's load the shapefile */
pg_connection = PQconnectdb(connection_string);

is_valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(list_store), &iter);
while (is_valid)
{
Expand All @@ -997,6 +995,9 @@ pgui_action_import(GtkWidget *widget, gpointer data)
import_running = TRUE;
success = FALSE;

/* One connection per file, otherwise error handling becomes tricky... */
pg_connection = PQconnectdb(connection_string);

/* Disable the button to prevent multiple imports running at the same time */
gtk_widget_set_sensitive(widget, FALSE);

Expand Down Expand Up @@ -1188,9 +1189,9 @@ pgui_action_import(GtkWidget *widget, gpointer data)
/* Import has definitely stopped running */
import_running = FALSE;

/* Make sure we abort any existing transaction */
if (!success)
pgui_exec("ABORT");
/* Close the existing connection */
PQfinish(pg_connection);
pg_connection = NULL;

/* If we didn't finish inserting all of the items (and we expected to), an error occurred */
if ((state->config->opt != 'p' && i != ShpLoaderGetRecordCount(state)) || !ret)
Expand Down Expand Up @@ -1229,10 +1230,6 @@ pgui_action_import(GtkWidget *widget, gpointer data)
while (gtk_events_pending())
gtk_main_iteration();

/* Disconnect from the database */
PQfinish(pg_connection);
pg_connection = NULL;

/* Tidy up */
free(connection_string);

Expand Down

0 comments on commit 24752a4

Please sign in to comment.