Skip to content

Commit 6a929c9

Browse files
committed
New test fixes
1 parent fae9bcf commit 6a929c9

7 files changed

+49
-46
lines changed

ext/pgsql/pgsql.c

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,20 @@ static void pgsql_link_free(pgsql_link_handle *link)
167167
while ((res = PQgetResult(link->conn))) {
168168
PQclear(res);
169169
}
170-
PQfinish(link->conn);
170+
if (!link->persistent) {
171+
PQfinish(link->conn);
172+
}
171173
PGG(num_links)--;
172174

173175
zend_hash_del(&PGG(regular_list), link->hash);
174176

175177
link->conn = NULL;
176178
zend_string_release(link->hash);
179+
177180
if (link->notices) {
178181
zend_hash_destroy(link->notices);
182+
FREE_HASHTABLE(link->notices);
183+
link->notices = NULL;
179184
}
180185
}
181186

@@ -293,48 +298,45 @@ static inline char * _php_pgsql_trim_result(PGconn * pgsql, char **buf)
293298

294299
static void php_pgsql_set_default_link(pgsql_link_handle *link)
295300
{
296-
if (PGG(default_link) != NULL) {
297-
pgsql_link_free(FETCH_DEFAULT_LINK());
298-
}
299-
300301
PGG(default_link) = link;
301302
}
302303

303304
static void _close_pgsql_plink(zend_resource *rsrc)
304305
{
305-
PGconn *link = (PGconn *)rsrc->ptr;
306-
PGresult *res;
306+
if (rsrc->ptr) {
307+
PGconn *link = (PGconn *)rsrc->ptr;
308+
PGresult *res;
307309

308-
while ((res = PQgetResult(link))) {
309-
PQclear(res);
310+
while ((res = PQgetResult(link))) {
311+
PQclear(res);
312+
}
313+
PQfinish(link);
314+
PGG(num_persistent)--;
315+
PGG(num_links)--;
316+
rsrc->ptr = NULL;
310317
}
311-
PQfinish(link);
312-
PGG(num_persistent)--;
313-
PGG(num_links)--;
314318
}
315319

316-
static void _php_pgsql_notice_handler(void *link, const char *message)
320+
static void _php_pgsql_notice_handler(void *l, const char *message)
317321
{
318-
HashTable *notices, tmp_notices;
322+
pgsql_link_handle *link;
319323
zval tmp;
320324
char *trimmed_message;
321325
size_t trimmed_message_len;
322326

323327
if (! PGG(ignore_notices)) {
324-
notices = ((pgsql_link_handle *) link)->notices;
325-
if (!notices) {
326-
zend_hash_init(&tmp_notices, 1, NULL, ZVAL_PTR_DTOR, 0);
327-
notices = &tmp_notices;
328+
link = ((pgsql_link_handle *) l);
329+
if (!link->notices) {
330+
link->notices = zend_new_array(1);
328331
}
329332
trimmed_message = _php_pgsql_trim_message(message, &trimmed_message_len);
330333
if (PGG(log_notices)) {
331334
php_error_docref(NULL, E_NOTICE, "%s", trimmed_message);
332335
}
333336

334337
ZVAL_STRINGL(&tmp, trimmed_message, trimmed_message_len);
335-
zend_hash_next_index_insert(notices, &tmp);
338+
zend_hash_next_index_insert(link->notices, &tmp);
336339
efree(trimmed_message);
337-
zval_ptr_dtor(&tmp);
338340
}
339341
}
340342

@@ -344,8 +346,9 @@ static int _rollback_transactions(zval *el)
344346
PGresult *res;
345347
zend_resource *rsrc = Z_RES_P(el);
346348

347-
if (rsrc->type != le_plink)
348-
return 0;
349+
if (rsrc->type != le_plink) {
350+
return ZEND_HASH_APPLY_KEEP;
351+
}
349352

350353
link = (PGconn *) rsrc->ptr;
351354

@@ -365,7 +368,7 @@ static int _rollback_transactions(zval *el)
365368
PGG(ignore_notices) = orig;
366369
}
367370

368-
return 0;
371+
return ZEND_HASH_APPLY_KEEP;
369372
}
370373

371374
static void _free_ptr(zend_resource *rsrc)
@@ -413,7 +416,6 @@ static PHP_GINIT_FUNCTION(pgsql)
413416
ZEND_TSRMLS_CACHE_UPDATE();
414417
#endif
415418
memset(pgsql_globals, 0, sizeof(zend_pgsql_globals));
416-
/* Initialize notice message hash at MINIT only */
417419
zend_hash_init(&pgsql_globals->regular_list, 0, NULL, ZVAL_PTR_DTOR, 1);
418420
}
419421

@@ -599,8 +601,6 @@ PHP_RINIT_FUNCTION(pgsql)
599601

600602
PHP_RSHUTDOWN_FUNCTION(pgsql)
601603
{
602-
/* clean up notice messages */
603-
zend_hash_clean(&PGG(regular_list));
604604
/* clean up persistent connection */
605605
zend_hash_apply(&EG(persistent_list), (apply_func_t) _rollback_transactions);
606606
return SUCCESS;
@@ -720,6 +720,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
720720
link->conn = pgsql;
721721
link->hash = zend_string_copy(str.s);
722722
link->notices = NULL;
723+
link->persistent = 1;
723724
} else { /* Non persistent connection */
724725
zval *index_ptr, new_index_ptr;
725726

@@ -767,6 +768,7 @@ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
767768
link->conn = pgsql;
768769
link->hash = zend_string_copy(str.s);
769770
link->notices = NULL;
771+
link->persistent = 0;
770772

771773
/* add it to the hash */
772774
ZVAL_COPY(&new_index_ptr, return_value);
@@ -844,15 +846,16 @@ PHP_FUNCTION(pg_close)
844846
if (!pgsql_link) {
845847
link = FETCH_DEFAULT_LINK();
846848
CHECK_DEFAULT_LINK(link);
849+
zend_hash_del(&PGG(regular_list), link->hash);
847850
PGG(default_link) = NULL;
848-
pgsql_link_free(link);
849851
RETURN_TRUE;
850852
}
851853

852854
link = Z_PGSQL_LINK_P(pgsql_link);
853855
CHECK_PGSQL_LINK(link);
854856

855857
if (link == FETCH_DEFAULT_LINK()) {
858+
zend_hash_del(&PGG(regular_list), link->hash);
856859
PGG(default_link) = NULL;
857860
}
858861
pgsql_link_free(link);
@@ -3372,7 +3375,6 @@ PHP_FUNCTION(pg_escape_bytea)
33723375
RETURN_THROWS();
33733376
}
33743377
link = FETCH_DEFAULT_LINK();
3375-
CHECK_DEFAULT_LINK(link);
33763378
break;
33773379
default:
33783380
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Os", &pgsql_link, pgsql_link_ce, &from, &from_len) == FAILURE) {

ext/pgsql/php_pgsql.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ typedef struct pgsql_link_handle {
149149
zend_string *hash;
150150
HashTable *notices;
151151
zend_object std;
152+
bool persistent;
152153
} pgsql_link_handle;
153154

154155
typedef struct pgLofp {

ext/pgsql/tests/02connection.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include('config.inc');
1010

1111
$db = pg_pconnect($conn_str);
1212
var_dump($db);
13-
13+
exit;
1414
if (pg_connection_status($db) != PGSQL_CONNECTION_OK)
1515
{
1616
echo "pg_connection_status() error\n";

ext/pgsql/tests/13pg_select_9.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ $fields = array('num'=>'1234', 'str'=>'ABC', 'bin'=>'XYZ');
1818
$ids = array('num'=>'1234');
1919

2020
$res = pg_select($db, $table_name, $ids) or print "Error\n";
21-
var_dump(pg_last_error($db));
2221
var_dump($res);
2322
echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n";
2423
echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";

ext/pgsql/tests/80_bug32223b.phpt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,41 @@ pgsql.ignore_notice=0
2323
require_once('config.inc');
2424
require_once('lcmess.inc');
2525

26-
define('dbh', pg_connect($conn_str));
27-
if (!dbh) {
28-
die ("Could not connect to the server");
26+
$dbh = pg_connect($conn_str);
27+
if (!$dbh) {
28+
die ("Could not connect to the server");
2929
}
3030

3131
_set_lc_messages();
3232

33-
$res = pg_query(dbh, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
33+
$res = pg_query($dbh, "CREATE OR REPLACE FUNCTION test_notice() RETURNS boolean AS '
3434
begin
3535
RAISE NOTICE ''11111'';
3636
return ''f'';
3737
end;
3838
' LANGUAGE plpgsql;");
3939

40-
$res = pg_query(dbh, 'SET client_min_messages TO NOTICE;');
40+
$res = pg_query($dbh, 'SET client_min_messages TO NOTICE;');
4141
var_dump($res);
4242

43-
function tester() {
44-
$res = pg_query(dbh, 'SELECT test_notice()');
43+
function tester($dbh) {
44+
$res = pg_query($dbh, 'SELECT test_notice()');
4545
$row = pg_fetch_row($res, 0);
4646
var_dump($row);
4747
pg_free_result($res);
4848
if ($row[0] == 'f')
4949
{
50-
var_dump(pg_last_notice(dbh));
50+
var_dump(pg_last_notice($dbh));
5151
}
5252
}
53-
tester();
53+
tester($dbh);
5454

55-
pg_close(dbh);
55+
pg_close($dbh);
5656

5757
?>
5858
--EXPECTF--
59-
resource(%d) of type (pgsql result)
59+
object(PgSqlResult)#%d (0) {
60+
}
6061
array(1) {
6162
[0]=>
6263
string(1) "f"

ext/pgsql/tests/bug46408.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Bug #46408 (Locale number format settings can cause pg_query_params to break wit
33
--SKIPIF--
44
<?php
55
require_once('skipif.inc');
6-
if (false === setlocale(LC_ALL, 'de_DE.utf-8', 'de_DE')) {
7-
echo "skip Locale de_DE.utf-8 not present";
6+
if (false === setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8")) {
7+
echo "skip Locale de-DE not present";
88
}
99
?>
1010
--FILE--
@@ -13,7 +13,7 @@ if (false === setlocale(LC_ALL, 'de_DE.utf-8', 'de_DE')) {
1313
require_once('config.inc');
1414

1515
$dbh = pg_connect($conn_str);
16-
setlocale(LC_ALL, 'de_DE.utf-8', 'de_DE');
16+
setlocale(LC_ALL, "de", "de_DE", "de_DE.ISO8859-1", "de_DE.ISO_8859-1", "de_DE.UTF-8");
1717
echo 3.5 , "\n";
1818
pg_query_params("SELECT $1::numeric", array(3.5));
1919
pg_close($dbh);
@@ -22,5 +22,5 @@ echo "Done".PHP_EOL;
2222

2323
?>
2424
--EXPECT--
25-
3,5
25+
3.5
2626
Done

ext/pgsql/tests/connect_after_close.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include('config.inc');
1010
$db1 = pg_connect($conn_str);
1111
unset($db1);
1212
var_dump(pg_close());
13-
exit;
13+
1414
$db2 = pg_connect($conn_str);
1515
unset($db2);
1616
var_dump(pg_close());

0 commit comments

Comments
 (0)