Fix connection failure handling

If the connection fails, bail early.  Otherwise the processing of the
queued SQL statements will cause an infinite loop by continually pushing
the same statement into the queue due to lack of connection.

Also add a local variable for the connection for clarity and
performance.

Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
This commit is contained in:
Kevin Locke
2017-04-08 13:33:13 -06:00
parent 68d8ead5ad
commit 7c4d76a0b6

View File

@ -91,15 +91,15 @@
$pg_connstr = $GLOBALS['pg4wp_connstr'].' dbname='.$dbname;
// Note: pg_connect returns existing connection for same connstr
$GLOBALS['pg4wp_conn'] = pg_connect($pg_connstr);
if( $GLOBALS['pg4wp_conn'])
{
$ver = pg_version($GLOBALS['pg4wp_conn']);
if( isset($ver['server']))
$GLOBALS['pg4wp_version'] = $ver['server'];
}
$GLOBALS['pg4wp_conn'] = $conn = pg_connect($pg_connstr);
if( !$conn)
return $conn;
$ver = pg_version($conn);
if( isset($ver['server']))
$GLOBALS['pg4wp_version'] = $ver['server'];
// Now we should be connected, we "forget" about the connection parameters (if this is not a "test" connection)
if( !defined('WP_INSTALLING') || !WP_INSTALLING)
$GLOBALS['pg4wp_connstr'] = '';
@ -109,7 +109,7 @@
foreach( $GLOBALS['pg4wp_pre_sql'] as $sql2run)
wpsql_query( $sql2run);
return $GLOBALS['pg4wp_conn'];
return $conn;
}
function wpsql_fetch_array($result)