PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ connection_test()

static int connection_test ( void  )
static

Definition at line 460 of file shp2pgsql-gui.c.

References _, free(), pg_connection, pgui_logf(), pgui_raise_error_dialogue(), pgui_sanitize_connection_string(), ShpDumperGetConnectionStringFromConn(), and valid_connection.

Referenced by pgui_action_connection_okay(), pgui_action_export(), pgui_action_import(), and pgui_action_open_table_dialog().

461 {
462  char *connection_string = NULL;
463  char *connection_sanitized = NULL;
464 
465  if (!(connection_string = ShpDumperGetConnectionStringFromConn(conn)))
466  {
468  valid_connection = 0;
469  return 0;
470  }
471 
472  connection_sanitized = strdup(connection_string);
473  pgui_sanitize_connection_string(connection_sanitized);
474  pgui_logf("Connecting: %s", connection_sanitized);
475  free(connection_sanitized);
476 
477  pg_connection = PQconnectdb(connection_string);
478  if (PQstatus(pg_connection) == CONNECTION_BAD)
479  {
480  pgui_logf( _("Database connection failed: %s"), PQerrorMessage(pg_connection));
481  free(connection_string);
482  PQfinish(pg_connection);
483  pg_connection = NULL;
484  valid_connection = 0;
485  return 0;
486  }
487  PQfinish(pg_connection);
488  pg_connection = NULL;
489  free(connection_string);
490 
491  valid_connection = 1;
492  return 1;
493 }
#define _(String)
Definition: shpcommon.h:24
static void pgui_logf(const char *fmt,...)
static SHPCONNECTIONCONFIG * conn
char * ShpDumperGetConnectionStringFromConn(SHPCONNECTIONCONFIG *conn)
static void pgui_sanitize_connection_string(char *connection_string)
static int valid_connection
void free(void *)
static void pgui_raise_error_dialogue(void)
static PGconn * pg_connection
Here is the call graph for this function:
Here is the caller graph for this function: