Skip to content

Commit 46c239e

Browse files
committed
Tests + nits
1 parent ba179fe commit 46c239e

6 files changed

+179
-4
lines changed

ext/pgsql/pgsql.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ PHP_FUNCTION(pg_lo_create)
23002300
RETURN_THROWS();
23012301
}
23022302

2303-
/* Overloaded method use default link if arg 1 is not a ressource, set oid pointer */
2303+
/* Overloaded method uses default link if arg 1 is not a resource, set oid pointer */
23042304
if ((argc == 1) && (Z_TYPE_P(pgsql_link) != IS_RESOURCE)) {
23052305
oid = pgsql_link;
23062306
pgsql_link = NULL;
@@ -4615,7 +4615,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
46154615
/* TODO: Check when meta data can be broken and see if can use assertions instead */
46164616

46174617
if (!err && field == NULL) {
4618-
zend_value_error("Array of values must be an associated array with string keys");
4618+
zend_value_error("Array of values must be an associative array with string keys");
46194619
err = 1;
46204620
}
46214621

@@ -4639,7 +4639,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
46394639
php_error_docref(NULL, E_NOTICE, "Detected broken meta data. Missing 'is enum'");
46404640
err = 1;
46414641
}
4642-
if (!err && (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT)) {
4642+
if (!err && (Z_TYPE_P(val) == IS_ARRAY || Z_TYPE_P(val) == IS_OBJECT || Z_TYPE_P(val) == IS_RESOURCE)) {
46434643
zend_type_error("Values must be of type string|int|float|bool|null, %s given", zend_zval_type_name(val));
46444644
err = 1;
46454645
}
@@ -5373,7 +5373,7 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var
53735373

53745374
ZEND_HASH_FOREACH_STR_KEY(Z_ARRVAL_P(var_array), fld) {
53755375
if (fld == NULL) {
5376-
zend_value_error("Array of values must be an associated array of string keys");
5376+
zend_value_error("Array of values must be an associative array of string keys");
53775377
goto cleanup;
53785378
}
53795379
if (opt & PGSQL_DML_ESCAPE) {

ext/pgsql/tests/05large_object.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ if (!file_exists($path . 'php.gif.exported')) {
6868
@unlink($path . 'php.gif.exported');
6969
pg_query($db, 'commit');
7070

71+
/* invalid OID values */
72+
try {
73+
pg_lo_create(-15);
74+
} catch (\ValueError $e) {
75+
echo $e->getMessage(), \PHP_EOL;
76+
}
77+
try {
78+
pg_lo_create($db, -15);
79+
} catch (\ValueError $e) {
80+
echo $e->getMessage(), \PHP_EOL;
81+
}
82+
try {
83+
pg_lo_create('giberrish');
84+
} catch (\ValueError $e) {
85+
echo $e->getMessage(), \PHP_EOL;
86+
}
87+
try {
88+
pg_lo_create($db, 'giberrish');
89+
} catch (\ValueError $e) {
90+
echo $e->getMessage(), \PHP_EOL;
91+
}
92+
7193
echo "OK";
7294
?>
7395
--EXPECT--
@@ -79,4 +101,8 @@ unlink LO
79101
Test without connection
80102
Test with string oid value
81103
import/export LO
104+
Invalid OID value passed
105+
Invalid OID value passed
106+
Invalid OID value passed
107+
Invalid OID value passed
82108
OK

ext/pgsql/tests/10pg_convert_9.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,34 @@ $fields = array('num'=>'1234', 'str'=>'AAA', 'bin'=>'BBB');
1818
$converted = pg_convert($db, $table_name, $fields);
1919

2020
var_dump($converted);
21+
22+
/* Invalid values */
23+
try {
24+
$converted = pg_convert($db, $table_name, [5 => 'AAA']);
25+
} catch (\ValueError $e) {
26+
echo $e->getMessage(), \PHP_EOL;
27+
}
28+
try {
29+
$converted = pg_convert($db, $table_name, ['AAA']);
30+
} catch (\ValueError $e) {
31+
echo $e->getMessage(), \PHP_EOL;
32+
}
33+
try {
34+
$converted = pg_convert($db, $table_name, ['num' => []]);
35+
} catch (\TypeError $e) {
36+
echo $e->getMessage(), \PHP_EOL;
37+
}
38+
try {
39+
$converted = pg_convert($db, $table_name, ['num' => new stdClass()]);
40+
} catch (\TypeError $e) {
41+
echo $e->getMessage(), \PHP_EOL;
42+
}
43+
try {
44+
$converted = pg_convert($db, $table_name, ['num' => $db]);
45+
var_dump($converted);
46+
} catch (\TypeError $e) {
47+
echo $e->getMessage(), \PHP_EOL;
48+
}
2149
?>
2250
--EXPECT--
2351
array(3) {
@@ -28,3 +56,8 @@ array(3) {
2856
[""bin""]=>
2957
string(12) "E'\\x424242'"
3058
}
59+
Array of values must be an associative array with string keys
60+
Array of values must be an associative array with string keys
61+
Values must be of type string|int|float|bool|null, array given
62+
Values must be of type string|int|float|bool|null, stdClass given
63+
Values must be of type string|int|float|bool|null, resource given

ext/pgsql/tests/12pg_insert_9.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,43 @@ echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING)."\n";
2121
echo pg_insert($db, $table_name, $fields, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";
2222
var_dump( pg_insert($db, $table_name, $fields, PGSQL_DML_EXEC) ); // Return resource
2323

24+
/* Invalid values */
25+
try {
26+
$converted = pg_insert($db, $table_name, [5 => 'AAA']);
27+
} catch (\ValueError $e) {
28+
echo $e->getMessage(), \PHP_EOL;
29+
}
30+
try {
31+
$converted = pg_insert($db, $table_name, ['AAA']);
32+
} catch (\ValueError $e) {
33+
echo $e->getMessage(), \PHP_EOL;
34+
}
35+
try {
36+
$converted = pg_insert($db, $table_name, ['num' => []]);
37+
} catch (\TypeError $e) {
38+
echo $e->getMessage(), \PHP_EOL;
39+
}
40+
try {
41+
$converted = pg_insert($db, $table_name, ['num' => new stdClass()]);
42+
} catch (\TypeError $e) {
43+
echo $e->getMessage(), \PHP_EOL;
44+
}
45+
try {
46+
$converted = pg_insert($db, $table_name, ['num' => $db]);
47+
var_dump($converted);
48+
} catch (\TypeError $e) {
49+
echo $e->getMessage(), \PHP_EOL;
50+
}
51+
2452
echo "Ok\n";
2553
?>
2654
--EXPECTF--
2755
INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES (1234,E'AAA',E'\\x424242');
2856
INSERT INTO "php_pgsql_test" ("num","str","bin") VALUES ('1234','AAA','BBB');
2957
resource(%d) of type (pgsql result)
58+
Array of values must be an associative array with string keys
59+
Array of values must be an associative array with string keys
60+
Values must be of type string|int|float|bool|null, array given
61+
Values must be of type string|int|float|bool|null, stdClass given
62+
Values must be of type string|int|float|bool|null, resource given
3063
Ok

ext/pgsql/tests/13pg_select_9.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,35 @@ $res = pg_select($db, $table_name, $ids) or print "Error\n";
2121
var_dump($res);
2222
echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING)."\n";
2323
echo pg_select($db, $table_name, $ids, PGSQL_DML_STRING|PGSQL_DML_ESCAPE)."\n";
24+
25+
/* Invalid values */
26+
try {
27+
$converted = pg_select($db, $table_name, [5 => 'AAA']);
28+
} catch (\ValueError $e) {
29+
echo $e->getMessage(), \PHP_EOL;
30+
}
31+
try {
32+
$converted = pg_select($db, $table_name, ['AAA']);
33+
} catch (\ValueError $e) {
34+
echo $e->getMessage(), \PHP_EOL;
35+
}
36+
try {
37+
$converted = pg_select($db, $table_name, ['num' => []]);
38+
} catch (\TypeError $e) {
39+
echo $e->getMessage(), \PHP_EOL;
40+
}
41+
try {
42+
$converted = pg_select($db, $table_name, ['num' => new stdClass()]);
43+
} catch (\TypeError $e) {
44+
echo $e->getMessage(), \PHP_EOL;
45+
}
46+
try {
47+
$converted = pg_select($db, $table_name, ['num' => $db]);
48+
var_dump($converted);
49+
} catch (\TypeError $e) {
50+
echo $e->getMessage(), \PHP_EOL;
51+
}
52+
2453
echo "Ok\n";
2554

2655
?>
@@ -47,4 +76,9 @@ array(2) {
4776
}
4877
SELECT * FROM "php_pgsql_test" WHERE "num"=1234;
4978
SELECT * FROM "php_pgsql_test" WHERE "num"='1234';
79+
Array of values must be an associative array with string keys
80+
Array of values must be an associative array with string keys
81+
Values must be of type string|int|float|bool|null, array given
82+
Values must be of type string|int|float|bool|null, stdClass given
83+
Values must be of type string|int|float|bool|null, resource given
5084
Ok

ext/pgsql/tests/28large_object_import_oid.phpt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,60 @@ if ($oid != 21005) echo ("pg_lo_import() wrong id\n");
3838
pg_lo_unlink ($oid);
3939
pg_exec('commit');
4040

41+
/* Invalide OID */
42+
try {
43+
pg_lo_import(__FILE__, -15);
44+
} catch (\ValueError $e) {
45+
echo $e->getMessage(), \PHP_EOL;
46+
}
47+
try {
48+
pg_lo_import($db, __FILE__, -15);
49+
} catch (\ValueError $e) {
50+
echo $e->getMessage(), \PHP_EOL;
51+
}
52+
try {
53+
pg_lo_import(__FILE__, 'giberrish');
54+
} catch (\ValueError $e) {
55+
echo $e->getMessage(), \PHP_EOL;
56+
}
57+
try {
58+
pg_lo_import($db, __FILE__, 'giberrish');
59+
} catch (\ValueError $e) {
60+
echo $e->getMessage(), \PHP_EOL;
61+
}
62+
try {
63+
pg_lo_import(__FILE__, true);
64+
} catch (\TypeError $e) {
65+
echo $e->getMessage(), \PHP_EOL;
66+
}
67+
try {
68+
pg_lo_import($db, __FILE__, []);
69+
} catch (\TypeError $e) {
70+
echo $e->getMessage(), \PHP_EOL;
71+
}
72+
try {
73+
pg_lo_import($db, __FILE__, new stdClass());
74+
} catch (\TypeError $e) {
75+
echo $e->getMessage(), \PHP_EOL;
76+
}
77+
try {
78+
pg_lo_import($db, __FILE__, $db);
79+
} catch (\TypeError $e) {
80+
echo $e->getMessage(), \PHP_EOL;
81+
}
4182

4283
echo "OK";
4384
?>
4485
--EXPECT--
4586
import LO from int
4687
import LO from string
4788
import LO using default connection
89+
Invalid OID value passed
90+
Invalid OID value passed
91+
Invalid OID value passed
92+
Invalid OID value passed
93+
OID value must be of type string|int, bool given
94+
OID value must be of type string|int, array given
95+
OID value must be of type string|int, stdClass given
96+
OID value must be of type string|int, resource given
4897
OK

0 commit comments

Comments
 (0)