@@ -1468,8 +1468,8 @@ PHP_FUNCTION(pg_last_notice)
1468
1468
RETURN_TRUE ;
1469
1469
break ;
1470
1470
default :
1471
- php_error_docref ( NULL , E_WARNING ,
1472
- "Invalid option specified (" ZEND_LONG_FMT ")" , option );
1471
+ zend_argument_value_error ( 2 , "must be one of PGSQL_NOTICE_LAST, PGSQL_NOTICE_ALL, or PGSQL_NOTICE_CLEAR" );
1472
+ RETURN_THROWS ( );
1473
1473
}
1474
1474
RETURN_FALSE ;
1475
1475
}
@@ -1555,7 +1555,12 @@ PHP_FUNCTION(pg_field_table)
1555
1555
RETURN_THROWS ();
1556
1556
}
1557
1557
1558
- if (fnum < 0 || fnum >= PQnfields (pg_result -> result )) {
1558
+ if (fnum < 0 ) {
1559
+ zend_argument_value_error (2 , "must be greater than or equal to 0" );
1560
+ RETURN_THROWS ();
1561
+ }
1562
+
1563
+ if (fnum >= PQnfields (pg_result -> result )) {
1559
1564
php_error_docref (NULL , E_WARNING , "Bad field offset specified" );
1560
1565
RETURN_FALSE ;
1561
1566
}
@@ -1638,10 +1643,14 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ
1638
1643
RETURN_THROWS ();
1639
1644
}
1640
1645
1646
+ if (field < 0 ) {
1647
+ zend_argument_value_error (2 , "must be greater than or equal to 0" );
1648
+ RETURN_THROWS ();
1649
+ }
1641
1650
1642
1651
pgsql_result = pg_result -> result ;
1643
1652
1644
- if (field < 0 || field >= PQnfields (pgsql_result )) {
1653
+ if (field >= PQnfields (pgsql_result )) {
1645
1654
php_error_docref (NULL , E_WARNING , "Bad field offset specified" );
1646
1655
RETURN_FALSE ;
1647
1656
}
@@ -1758,7 +1767,11 @@ PHP_FUNCTION(pg_fetch_result)
1758
1767
}
1759
1768
pg_result -> row ++ ;
1760
1769
} else {
1761
- if (row < 0 || row >= PQntuples (pgsql_result )) {
1770
+ if (row < 0 ) {
1771
+ zend_argument_value_error (2 , "must be greater than or equal to 0" );
1772
+ RETURN_THROWS ();
1773
+ }
1774
+ if (row >= PQntuples (pgsql_result )) {
1762
1775
php_error_docref (NULL , E_WARNING , "Unable to jump to row " ZEND_LONG_FMT " on PostgreSQL result index " ZEND_LONG_FMT ,
1763
1776
row , Z_LVAL_P (result ));
1764
1777
RETURN_FALSE ;
@@ -1767,12 +1780,17 @@ PHP_FUNCTION(pg_fetch_result)
1767
1780
}
1768
1781
if (field_name ) {
1769
1782
field_offset = PQfnumber (pgsql_result , ZSTR_VAL (field_name ));
1783
+ // TODO Split into 2 and ValueError for negative index?
1770
1784
if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
1771
1785
php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
1772
1786
RETURN_FALSE ;
1773
1787
}
1774
1788
} else {
1775
- if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
1789
+ if (field_offset < 0 ) {
1790
+ zend_argument_value_error (argc , "must be greater than or equal to 0" );
1791
+ RETURN_THROWS ();
1792
+ }
1793
+ if (field_offset >= PQnfields (pgsql_result )) {
1776
1794
php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
1777
1795
RETURN_FALSE ;
1778
1796
}
@@ -1815,13 +1833,13 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
1815
1833
}
1816
1834
1817
1835
if (!row_is_null && row < 0 ) {
1818
- php_error_docref ( NULL , E_WARNING , "The row parameter must be greater or equal to zero " );
1819
- RETURN_FALSE ;
1836
+ zend_argument_value_error ( 2 , " must be greater than or equal to 0 " );
1837
+ RETURN_THROWS () ;
1820
1838
}
1821
1839
1822
1840
if (!(result_type & PGSQL_BOTH )) {
1823
- php_error_docref ( NULL , E_WARNING , "Invalid result type " );
1824
- RETURN_FALSE ;
1841
+ zend_argument_value_error ( 3 , "must be one of PGSQL_ASSOC, PGSQL_NUM, or PGSQL_BOTH " );
1842
+ RETURN_THROWS () ;
1825
1843
}
1826
1844
1827
1845
if ((pg_result = (pgsql_result_handle * )zend_fetch_resource (Z_RES_P (result ), "PostgreSQL result" , le_result )) == NULL ) {
@@ -1831,7 +1849,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
1831
1849
pgsql_result = pg_result -> result ;
1832
1850
1833
1851
if (!row_is_null ) {
1834
- if (row < 0 || row >= PQntuples (pgsql_result )) {
1852
+ if (row >= PQntuples (pgsql_result )) {
1835
1853
php_error_docref (NULL , E_WARNING , "Unable to jump to row " ZEND_LONG_FMT " on PostgreSQL result index " ZEND_LONG_FMT ,
1836
1854
row , Z_LVAL_P (result ));
1837
1855
RETURN_FALSE ;
@@ -1977,8 +1995,8 @@ PHP_FUNCTION(pg_fetch_all)
1977
1995
}
1978
1996
1979
1997
if (!(result_type & PGSQL_BOTH )) {
1980
- php_error_docref ( NULL , E_WARNING , "Invalid result type " );
1981
- RETURN_FALSE ;
1998
+ zend_argument_value_error ( 4 , "must be one of PGSQL_ASSOC, PGSQL_NUM, or PGSQL_BOTH " );
1999
+ RETURN_THROWS () ;
1982
2000
}
1983
2001
1984
2002
if ((pg_result = (pgsql_result_handle * )zend_fetch_resource (Z_RES_P (result ), "PostgreSQL result" , le_result )) == NULL ) {
@@ -2012,10 +2030,15 @@ PHP_FUNCTION(pg_fetch_all_columns)
2012
2030
RETURN_THROWS ();
2013
2031
}
2014
2032
2033
+ if (colno < 0 ) {
2034
+ zend_argument_value_error (2 , "must be greater than or equal to 0" );
2035
+ RETURN_THROWS ();
2036
+ }
2037
+
2015
2038
pgsql_result = pg_result -> result ;
2016
2039
2017
2040
num_fields = PQnfields (pgsql_result );
2018
- if (colno >= (zend_long )num_fields || colno < 0 ) {
2041
+ if (colno >= (zend_long )num_fields ) {
2019
2042
php_error_docref (NULL , E_WARNING , "Invalid column number '" ZEND_LONG_FMT "'" , colno );
2020
2043
RETURN_FALSE ;
2021
2044
}
@@ -2097,11 +2120,16 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
2097
2120
pg_result -> row = 0 ;
2098
2121
}
2099
2122
pgsql_row = pg_result -> row ;
2123
+ // TODO Split into 2 and ValueError for negative index?
2100
2124
if (pgsql_row < 0 || pgsql_row >= PQntuples (pgsql_result )) {
2101
2125
RETURN_FALSE ;
2102
2126
}
2103
2127
} else {
2104
- if (row < 0 || row >= PQntuples (pgsql_result )) {
2128
+ if (row < 0 ) {
2129
+ zend_argument_value_error (2 , "must be greater than or equal to 0" );
2130
+ RETURN_THROWS ();
2131
+ }
2132
+ if (row >= PQntuples (pgsql_result )) {
2105
2133
php_error_docref (NULL , E_WARNING , "Unable to jump to row " ZEND_LONG_FMT " on PostgreSQL result index " ZEND_LONG_FMT ,
2106
2134
row , Z_LVAL_P (result ));
2107
2135
RETURN_FALSE ;
@@ -2111,12 +2139,16 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
2111
2139
2112
2140
if (field_name ) {
2113
2141
field_offset = PQfnumber (pgsql_result , ZSTR_VAL (field_name ));
2142
+ // TODO Split into 2 and ValueError for negative index?
2114
2143
if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
2115
2144
php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
2116
2145
RETURN_FALSE ;
2117
2146
}
2118
2147
} else {
2119
- if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
2148
+ if (field_offset < 0 ) {
2149
+ zend_argument_value_error (argc , "must be greater than or equal to 0" );
2150
+ }
2151
+ if (field_offset >= PQnfields (pgsql_result )) {
2120
2152
php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
2121
2153
RETURN_FALSE ;
2122
2154
}
@@ -2603,14 +2635,15 @@ PHP_FUNCTION(pg_lo_write)
2603
2635
}
2604
2636
2605
2637
if (argc > 2 ) {
2638
+ if (z_len < 0 ) {
2639
+ zend_argument_value_error (3 , "must be greater than or equal to 0" );
2640
+ RETURN_THROWS ();
2641
+ }
2606
2642
if (z_len > (zend_long )str_len ) {
2643
+ /* TODO Promote to ValueError? */
2607
2644
php_error_docref (NULL , E_WARNING , "Cannot write more than buffer size %zu. Tried to write " ZEND_LONG_FMT , str_len , z_len );
2608
2645
RETURN_FALSE ;
2609
2646
}
2610
- if (z_len < 0 ) {
2611
- php_error_docref (NULL , E_WARNING , "Buffer size must be larger than 0, but " ZEND_LONG_FMT " was specified" , z_len );
2612
- RETURN_FALSE ;
2613
- }
2614
2647
len = z_len ;
2615
2648
}
2616
2649
else {
@@ -2816,9 +2849,10 @@ PHP_FUNCTION(pg_lo_seek)
2816
2849
if (zend_parse_parameters (argc , "rl|l" , & pgsql_id , & offset , & whence ) == FAILURE ) {
2817
2850
RETURN_THROWS ();
2818
2851
}
2852
+ /* TODO Error for < 0 offset? */
2819
2853
if (whence != SEEK_SET && whence != SEEK_CUR && whence != SEEK_END ) {
2820
- php_error_docref ( NULL , E_WARNING , "Invalid whence parameter " );
2821
- return ;
2854
+ zend_argument_value_error ( 3 , "must be one of PGSQL_SEEK_SET, PGSQL_SEEK_CUR, or PGSQL_SEEK_END " );
2855
+ RETURN_THROWS () ;
2822
2856
}
2823
2857
2824
2858
if ((pgsql = (pgLofp * )zend_fetch_resource (Z_RES_P (pgsql_id ), "PostgreSQL large object" , le_lofp )) == NULL ) {
@@ -3352,6 +3386,7 @@ PHP_FUNCTION(pg_unescape_bytea)
3352
3386
to = estrndup (tmp , to_len );
3353
3387
PQfreemem (tmp );
3354
3388
if (!to ) {
3389
+ /* TODO Promote to Error? */
3355
3390
php_error_docref (NULL , E_WARNING ,"Invalid parameter" );
3356
3391
RETURN_FALSE ;
3357
3392
}
@@ -4020,10 +4055,9 @@ PHP_FUNCTION(pg_result_status)
4020
4055
}
4021
4056
else if (result_type == PGSQL_STATUS_STRING ) {
4022
4057
RETURN_STRING (PQcmdStatus (pgsql_result ));
4023
- }
4024
- else {
4025
- php_error_docref (NULL , E_WARNING , "Optional 2nd parameter should be PGSQL_STATUS_LONG or PGSQL_STATUS_STRING" );
4026
- RETURN_FALSE ;
4058
+ } else {
4059
+ zend_argument_value_error (2 , "must be either PGSQL_STATUS_LONG or PGSQL_STATUS_STRING" );
4060
+ RETURN_THROWS ();
4027
4061
}
4028
4062
}
4029
4063
/* }}} */
@@ -4045,8 +4079,8 @@ PHP_FUNCTION(pg_get_notify)
4045
4079
}
4046
4080
4047
4081
if (!(result_type & PGSQL_BOTH )) {
4048
- php_error_docref ( NULL , E_WARNING , "Invalid result type " );
4049
- RETURN_FALSE ;
4082
+ zend_argument_value_error ( 2 , "must be one of PGSQL_ASSOC, PGSQL_NUM, or PGSQL_BOTH " );
4083
+ RETURN_THROWS () ;
4050
4084
}
4051
4085
4052
4086
PQconsumeInput (pgsql );
@@ -4246,6 +4280,7 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
4246
4280
zval elem ;
4247
4281
4248
4282
if (!* table_name ) {
4283
+ // CHeck if can be TODO
4249
4284
php_error_docref (NULL , E_WARNING , "The table name must be specified" );
4250
4285
return FAILURE ;
4251
4286
}
@@ -4364,6 +4399,12 @@ PHP_FUNCTION(pg_meta_data)
4364
4399
RETURN_THROWS ();
4365
4400
}
4366
4401
4402
+ /* php_pgsql_meta_data() warns on empty table_name */
4403
+ if (table_name_len == 0 ) {
4404
+ zend_argument_value_error (2 , "cannot be empty" );
4405
+ RETURN_THROWS ();
4406
+ }
4407
+
4367
4408
array_init (return_value );
4368
4409
if (php_pgsql_meta_data (pgsql , table_name , return_value , extended ) == FAILURE ) {
4369
4410
zend_array_destroy (Z_ARR_P (return_value )); /* destroy array */
@@ -4564,14 +4605,11 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4564
4605
int err = 0 , skip_field ;
4565
4606
php_pgsql_data_type data_type ;
4566
4607
4567
- assert (pg_link != NULL );
4568
- assert (Z_TYPE_P (values ) == IS_ARRAY );
4569
- assert (Z_TYPE_P (result ) == IS_ARRAY );
4570
- assert (!(opt & ~PGSQL_CONV_OPTS ));
4571
-
4572
- if (!table_name ) {
4573
- return FAILURE ;
4574
- }
4608
+ ZEND_ASSERT (pg_link != NULL );
4609
+ ZEND_ASSERT (Z_TYPE_P (values ) == IS_ARRAY );
4610
+ ZEND_ASSERT (Z_TYPE_P (result ) == IS_ARRAY );
4611
+ ZEND_ASSERT (!(opt & ~PGSQL_CONV_OPTS ));
4612
+ ZEND_ASSERT (table_name );
4575
4613
4576
4614
array_init (& meta );
4577
4615
/* table_name is escaped by php_pgsql_meta_data */
@@ -5222,13 +5260,16 @@ PHP_FUNCTION(pg_convert)
5222
5260
"rsa|l" , & pgsql_link , & table_name , & table_name_len , & values , & option ) == FAILURE ) {
5223
5261
RETURN_THROWS ();
5224
5262
}
5225
- if (option & ~PGSQL_CONV_OPTS ) {
5226
- php_error_docref (NULL , E_WARNING , "Invalid option is specified" );
5227
- RETURN_FALSE ;
5263
+
5264
+ if (table_name_len == 0 ) {
5265
+ zend_argument_value_error (2 , "cannot be empty" );
5266
+ RETURN_THROWS ();
5228
5267
}
5229
- if (!table_name_len ) {
5230
- php_error_docref (NULL , E_NOTICE , "Table name is invalid" );
5231
- RETURN_FALSE ;
5268
+
5269
+ if (option & ~PGSQL_CONV_OPTS ) {
5270
+ zend_argument_value_error (4 , "must be a valid bit mask of PGSQL_CONV_IGNORE_DEFAULT, "
5271
+ "PGSQL_CONV_FORCE_NULL, or PGSQL_CONV_IGNORE_NOT_NULL" );
5272
+ RETURN_THROWS ();
5232
5273
}
5233
5274
5234
5275
if ((pg_link = (PGconn * )zend_fetch_resource2 (Z_RES_P (pgsql_link ), "PostgreSQL link" , le_link , le_plink )) == NULL ) {
@@ -5433,9 +5474,16 @@ PHP_FUNCTION(pg_insert)
5433
5474
& pgsql_link , & table , & table_len , & values , & option ) == FAILURE ) {
5434
5475
RETURN_THROWS ();
5435
5476
}
5477
+
5478
+ if (table_len == 0 ) {
5479
+ zend_argument_value_error (2 , "cannot be empty" );
5480
+ RETURN_THROWS ();
5481
+ }
5482
+
5436
5483
if (option & ~(PGSQL_CONV_OPTS |PGSQL_DML_NO_CONV |PGSQL_DML_EXEC |PGSQL_DML_ASYNC |PGSQL_DML_STRING |PGSQL_DML_ESCAPE )) {
5437
- php_error_docref (NULL , E_WARNING , "Invalid option is specified" );
5438
- RETURN_FALSE ;
5484
+ zend_argument_value_error (4 , "must be a valid bit mask of PGSQL_CONV_FORCE_NULL, PGSQL_DML_NO_CONV, "
5485
+ "PGSQL_DML_ESCAPE, PGSQL_DML_EXEC, PGSQL_DML_ASYNC or PGSQL_DML_STRING" );
5486
+ RETURN_THROWS ();
5439
5487
}
5440
5488
5441
5489
if ((pg_link = (PGconn * )zend_fetch_resource2 (Z_RES_P (pgsql_link ), "PostgreSQL link" , le_link , le_plink )) == NULL ) {
@@ -5643,9 +5691,16 @@ PHP_FUNCTION(pg_update)
5643
5691
& pgsql_link , & table , & table_len , & values , & ids , & option ) == FAILURE ) {
5644
5692
RETURN_THROWS ();
5645
5693
}
5694
+
5695
+ if (table_len == 0 ) {
5696
+ zend_argument_value_error (2 , "cannot be empty" );
5697
+ RETURN_THROWS ();
5698
+ }
5699
+
5646
5700
if (option & ~(PGSQL_CONV_OPTS |PGSQL_DML_NO_CONV |PGSQL_DML_EXEC |PGSQL_DML_STRING |PGSQL_DML_ESCAPE )) {
5647
- php_error_docref (NULL , E_WARNING , "Invalid option is specified" );
5648
- RETURN_FALSE ;
5701
+ zend_argument_value_error (5 , "must be a valid bit mask of PGSQL_CONV_FORCE_NULL, PGSQL_DML_NO_CONV, "
5702
+ "PGSQL_DML_ESCAPE, PGSQL_DML_EXEC, PGSQL_DML_ASYNC or PGSQL_DML_STRING" );
5703
+ RETURN_THROWS ();
5649
5704
}
5650
5705
5651
5706
if ((pg_link = (PGconn * )zend_fetch_resource2 (Z_RES_P (pgsql_link ), "PostgreSQL link" , le_link , le_plink )) == NULL ) {
@@ -5733,9 +5788,16 @@ PHP_FUNCTION(pg_delete)
5733
5788
& pgsql_link , & table , & table_len , & ids , & option ) == FAILURE ) {
5734
5789
RETURN_THROWS ();
5735
5790
}
5791
+
5792
+ if (table_len == 0 ) {
5793
+ zend_argument_value_error (2 , "cannot be empty" );
5794
+ RETURN_THROWS ();
5795
+ }
5796
+
5736
5797
if (option & ~(PGSQL_CONV_FORCE_NULL |PGSQL_DML_NO_CONV |PGSQL_DML_EXEC |PGSQL_DML_STRING |PGSQL_DML_ESCAPE )) {
5737
- php_error_docref (NULL , E_WARNING , "Invalid option is specified" );
5738
- RETURN_FALSE ;
5798
+ zend_argument_value_error (4 , "must be a valid bit mask of PGSQL_CONV_FORCE_NULL, PGSQL_DML_NO_CONV, "
5799
+ "PGSQL_DML_ESCAPE, PGSQL_DML_EXEC, PGSQL_DML_ASYNC or PGSQL_DML_STRING" );
5800
+ RETURN_THROWS ();
5739
5801
}
5740
5802
5741
5803
if ((pg_link = (PGconn * )zend_fetch_resource2 (Z_RES_P (pgsql_link ), "PostgreSQL link" , le_link , le_plink )) == NULL ) {
@@ -5865,20 +5927,26 @@ PHP_FUNCTION(pg_select)
5865
5927
long result_type = PGSQL_ASSOC ;
5866
5928
PGconn * pg_link ;
5867
5929
zend_string * sql = NULL ;
5868
- int argc = ZEND_NUM_ARGS ();
5869
5930
5870
- // TODO: result_type is unused by zpp!
5871
- if (zend_parse_parameters (argc , "rsa|l " ,
5931
+ /* TODO Document result_type param on php.net (apparently it was added in PHP 7.1) */
5932
+ if (zend_parse_parameters (ZEND_NUM_ARGS () , "rsa|ll " ,
5872
5933
& pgsql_link , & table , & table_len , & ids , & option , & result_type ) == FAILURE ) {
5873
5934
RETURN_THROWS ();
5874
5935
}
5936
+
5937
+ if (table_len == 0 ) {
5938
+ zend_argument_value_error (2 , "cannot be empty" );
5939
+ RETURN_THROWS ();
5940
+ }
5941
+
5875
5942
if (option & ~(PGSQL_CONV_FORCE_NULL |PGSQL_DML_NO_CONV |PGSQL_DML_EXEC |PGSQL_DML_ASYNC |PGSQL_DML_STRING |PGSQL_DML_ESCAPE )) {
5876
- php_error_docref (NULL , E_WARNING , "Invalid option is specified" );
5877
- RETURN_FALSE ;
5943
+ zend_argument_value_error (4 , "must be a valid bit mask of PGSQL_CONV_FORCE_NULL, PGSQL_DML_NO_CONV, "
5944
+ "PGSQL_DML_ESCAPE, PGSQL_DML_EXEC, PGSQL_DML_ASYNC or PGSQL_DML_STRING" );
5945
+ RETURN_THROWS ();
5878
5946
}
5879
5947
if (!(result_type & PGSQL_BOTH )) {
5880
- php_error_docref ( NULL , E_WARNING , "Invalid result type " );
5881
- RETURN_FALSE ;
5948
+ zend_argument_value_error ( 5 , "must be one of PGSQL_ASSOC, PGSQL_NUM, or PGSQL_BOTH " );
5949
+ RETURN_THROWS () ;
5882
5950
}
5883
5951
5884
5952
if ((pg_link = (PGconn * )zend_fetch_resource2 (Z_RES_P (pgsql_link ), "PostgreSQL link" , le_link , le_plink )) == NULL ) {
0 commit comments