@@ -2300,6 +2300,7 @@ PHP_FUNCTION(pg_lo_create)
2300
2300
RETURN_THROWS ();
2301
2301
}
2302
2302
2303
+ /* Overloaded method uses default link if arg 1 is not a resource, set oid pointer */
2303
2304
if ((argc == 1 ) && (Z_TYPE_P (pgsql_link ) != IS_RESOURCE )) {
2304
2305
oid = pgsql_link ;
2305
2306
pgsql_link = NULL ;
@@ -2322,25 +2323,26 @@ PHP_FUNCTION(pg_lo_create)
2322
2323
switch (Z_TYPE_P (oid )) {
2323
2324
case IS_STRING :
2324
2325
{
2326
+ /* TODO: Use subroutine? */
2325
2327
char * end_ptr ;
2326
2328
wanted_oid = (Oid )strtoul (Z_STRVAL_P (oid ), & end_ptr , 10 );
2327
2329
if ((Z_STRVAL_P (oid )+ Z_STRLEN_P (oid )) != end_ptr ) {
2328
- /* wrong integer format */
2329
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2330
- RETURN_FALSE ;
2330
+ /* wrong integer format */
2331
+ zend_value_error ( "Invalid OID value passed" );
2332
+ RETURN_THROWS () ;
2331
2333
}
2332
2334
}
2333
2335
break ;
2334
2336
case IS_LONG :
2335
2337
if (Z_LVAL_P (oid ) < (zend_long )InvalidOid ) {
2336
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2337
- RETURN_FALSE ;
2338
+ zend_value_error ( "Invalid OID value passed" );
2339
+ RETURN_THROWS () ;
2338
2340
}
2339
2341
wanted_oid = (Oid )Z_LVAL_P (oid );
2340
2342
break ;
2341
2343
default :
2342
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2343
- RETURN_FALSE ;
2344
+ zend_type_error ( " OID value must be of type string|int, %s given" , zend_zval_type_name ( oid ) );
2345
+ RETURN_THROWS () ;
2344
2346
}
2345
2347
if ((pgsql_oid = lo_create (pgsql , wanted_oid )) == InvalidOid ) {
2346
2348
php_error_docref (NULL , E_WARNING , "Unable to create PostgreSQL large object" );
@@ -2374,39 +2376,41 @@ PHP_FUNCTION(pg_lo_unlink)
2374
2376
/* accept string type since Oid type is unsigned int */
2375
2377
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2376
2378
"rs" , & pgsql_link , & oid_string , & oid_strlen ) == SUCCESS ) {
2379
+ /* TODO: Use subroutine? */
2377
2380
oid = (Oid )strtoul (oid_string , & end_ptr , 10 );
2378
2381
if ((oid_string + oid_strlen ) != end_ptr ) {
2379
2382
/* wrong integer format */
2380
- php_error_docref ( NULL , E_NOTICE , "Wrong OID value passed" );
2381
- RETURN_FALSE ;
2383
+ zend_value_error ( "Invalid OID value passed" );
2384
+ RETURN_THROWS () ;
2382
2385
}
2383
2386
link = Z_RES_P (pgsql_link );
2384
2387
}
2385
2388
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2386
2389
"rl" , & pgsql_link , & oid_long ) == SUCCESS ) {
2387
2390
if (oid_long <= (zend_long )InvalidOid ) {
2388
- php_error_docref ( NULL , E_NOTICE , "Invalid OID specified " );
2389
- RETURN_FALSE ;
2391
+ zend_value_error ( "Invalid OID value passed " );
2392
+ RETURN_THROWS () ;
2390
2393
}
2391
2394
oid = (Oid )oid_long ;
2392
2395
link = Z_RES_P (pgsql_link );
2393
2396
}
2394
2397
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2395
2398
"s" , & oid_string , & oid_strlen ) == SUCCESS ) {
2399
+ /* TODO: subroutine? */
2396
2400
oid = (Oid )strtoul (oid_string , & end_ptr , 10 );
2397
2401
if ((oid_string + oid_strlen ) != end_ptr ) {
2398
2402
/* wrong integer format */
2399
- php_error_docref ( NULL , E_NOTICE , "Wrong OID value passed" );
2400
- RETURN_FALSE ;
2403
+ zend_value_error ( "Invalid OID value passed" );
2404
+ RETURN_THROWS () ;
2401
2405
}
2402
2406
link = FETCH_DEFAULT_LINK ();
2403
2407
CHECK_DEFAULT_LINK (link );
2404
2408
}
2405
2409
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2406
2410
"l" , & oid_long ) == SUCCESS ) {
2407
2411
if (oid_long <= (zend_long )InvalidOid ) {
2408
- php_error_docref ( NULL , E_NOTICE , "Invalid OID is specified " );
2409
- RETURN_FALSE ;
2412
+ zend_value_error ( "Invalid OID value passed " );
2413
+ RETURN_THROWS () ;
2410
2414
}
2411
2415
oid = (Oid )oid_long ;
2412
2416
link = FETCH_DEFAULT_LINK ();
@@ -2447,39 +2451,41 @@ PHP_FUNCTION(pg_lo_open)
2447
2451
/* accept string type since Oid is unsigned int */
2448
2452
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2449
2453
"rss" , & pgsql_link , & oid_string , & oid_strlen , & mode_string , & mode_strlen ) == SUCCESS ) {
2454
+ /* TODO: Use subroutine? */
2450
2455
oid = (Oid )strtoul (oid_string , & end_ptr , 10 );
2451
2456
if ((oid_string + oid_strlen ) != end_ptr ) {
2452
2457
/* wrong integer format */
2453
- php_error_docref ( NULL , E_NOTICE , "Wrong OID value passed" );
2454
- RETURN_FALSE ;
2458
+ zend_value_error ( "Invalid OID value passed" );
2459
+ RETURN_THROWS () ;
2455
2460
}
2456
2461
link = Z_RES_P (pgsql_link );
2457
2462
}
2458
2463
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2459
2464
"rls" , & pgsql_link , & oid_long , & mode_string , & mode_strlen ) == SUCCESS ) {
2460
2465
if (oid_long <= (zend_long )InvalidOid ) {
2461
- php_error_docref ( NULL , E_NOTICE , "Invalid OID specified " );
2462
- RETURN_FALSE ;
2466
+ zend_value_error ( "Invalid OID value passed " );
2467
+ RETURN_THROWS () ;
2463
2468
}
2464
2469
oid = (Oid )oid_long ;
2465
2470
link = Z_RES_P (pgsql_link );
2466
2471
}
2467
2472
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2468
2473
"ss" , & oid_string , & oid_strlen , & mode_string , & mode_strlen ) == SUCCESS ) {
2474
+ /* TODO: Use subroutine? */
2469
2475
oid = (Oid )strtoul (oid_string , & end_ptr , 10 );
2470
2476
if ((oid_string + oid_strlen ) != end_ptr ) {
2471
2477
/* wrong integer format */
2472
- php_error_docref ( NULL , E_NOTICE , "Wrong OID value passed" );
2473
- RETURN_FALSE ;
2478
+ zend_value_error ( "Invalid OID value passed" );
2479
+ RETURN_THROWS () ;
2474
2480
}
2475
2481
link = FETCH_DEFAULT_LINK ();
2476
2482
CHECK_DEFAULT_LINK (link );
2477
2483
}
2478
2484
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2479
2485
"ls" , & oid_long , & mode_string , & mode_strlen ) == SUCCESS ) {
2480
2486
if (oid_long <= (zend_long )InvalidOid ) {
2481
- php_error_docref ( NULL , E_NOTICE , "Invalid OID specified " );
2482
- RETURN_FALSE ;
2487
+ zend_value_error ( "Invalid OID value passed " );
2488
+ RETURN_THROWS () ;
2483
2489
}
2484
2490
oid = (Oid )oid_long ;
2485
2491
link = FETCH_DEFAULT_LINK ();
@@ -2717,25 +2723,26 @@ PHP_FUNCTION(pg_lo_import)
2717
2723
switch (Z_TYPE_P (oid )) {
2718
2724
case IS_STRING :
2719
2725
{
2726
+ /* TODO: Use subroutine? */
2720
2727
char * end_ptr ;
2721
2728
wanted_oid = (Oid )strtoul (Z_STRVAL_P (oid ), & end_ptr , 10 );
2722
2729
if ((Z_STRVAL_P (oid )+ Z_STRLEN_P (oid )) != end_ptr ) {
2723
- /* wrong integer format */
2724
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2725
- RETURN_FALSE ;
2730
+ /* wrong integer format */
2731
+ zend_value_error ( "Invalid OID value passed" );
2732
+ RETURN_THROWS () ;
2726
2733
}
2727
2734
}
2728
2735
break ;
2729
2736
case IS_LONG :
2730
2737
if (Z_LVAL_P (oid ) < (zend_long )InvalidOid ) {
2731
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2732
- RETURN_FALSE ;
2738
+ zend_value_error ( "Invalid OID value passed" );
2739
+ RETURN_THROWS () ;
2733
2740
}
2734
2741
wanted_oid = (Oid )Z_LVAL_P (oid );
2735
2742
break ;
2736
2743
default :
2737
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2738
- RETURN_FALSE ;
2744
+ zend_type_error ( " OID value must be of type string|int, %s given" , zend_zval_type_name ( oid ) );
2745
+ RETURN_THROWS () ;
2739
2746
}
2740
2747
2741
2748
returned_oid = lo_import_with_oid (pgsql , file_in , wanted_oid );
@@ -2773,39 +2780,41 @@ PHP_FUNCTION(pg_lo_export)
2773
2780
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2774
2781
"rlp" , & pgsql_link , & oid_long , & file_out , & name_len ) == SUCCESS ) {
2775
2782
if (oid_long <= (zend_long )InvalidOid ) {
2776
- php_error_docref ( NULL , E_NOTICE , "Invalid OID specified " );
2777
- RETURN_FALSE ;
2783
+ zend_value_error ( "Invalid OID value passed " );
2784
+ RETURN_THROWS () ;
2778
2785
}
2779
2786
oid = (Oid )oid_long ;
2780
2787
link = Z_RES_P (pgsql_link );
2781
2788
}
2782
2789
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2783
2790
"rsp" , & pgsql_link , & oid_string , & oid_strlen , & file_out , & name_len ) == SUCCESS ) {
2791
+ /* TODO: Use subroutine? */
2784
2792
oid = (Oid )strtoul (oid_string , & end_ptr , 10 );
2785
2793
if ((oid_string + oid_strlen ) != end_ptr ) {
2786
2794
/* wrong integer format */
2787
- php_error_docref ( NULL , E_NOTICE , "Wrong OID value passed" );
2788
- RETURN_FALSE ;
2795
+ zend_value_error ( "Invalid OID value passed" );
2796
+ RETURN_THROWS () ;
2789
2797
}
2790
2798
link = Z_RES_P (pgsql_link );
2791
2799
}
2792
2800
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2793
2801
"lp" , & oid_long , & file_out , & name_len ) == SUCCESS ) {
2794
2802
if (oid_long <= (zend_long )InvalidOid ) {
2795
- php_error_docref ( NULL , E_NOTICE , "Invalid OID specified " );
2796
- RETURN_FALSE ;
2803
+ zend_value_error ( "Invalid OID value passed " );
2804
+ RETURN_THROWS () ;
2797
2805
}
2798
2806
oid = (Oid )oid_long ;
2799
2807
link = FETCH_DEFAULT_LINK ();
2800
2808
CHECK_DEFAULT_LINK (link );
2801
2809
}
2802
2810
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2803
2811
"sp" , & oid_string , & oid_strlen , & file_out , & name_len ) == SUCCESS ) {
2812
+ /* TODO: Use subroutine? */
2804
2813
oid = (Oid )strtoul (oid_string , & end_ptr , 10 );
2805
2814
if ((oid_string + oid_strlen ) != end_ptr ) {
2806
2815
/* wrong integer format */
2807
- php_error_docref ( NULL , E_NOTICE , "Wrong OID value passed" );
2808
- RETURN_FALSE ;
2816
+ zend_value_error ( "Invalid OID value passed" );
2817
+ RETURN_THROWS () ;
2809
2818
}
2810
2819
link = FETCH_DEFAULT_LINK ();
2811
2820
CHECK_DEFAULT_LINK (link );
@@ -4264,6 +4273,7 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
4264
4273
src = estrdup (table_name );
4265
4274
tmp_name = php_strtok_r (src , "." , & tmp_name2 );
4266
4275
if (!tmp_name ) {
4276
+ // TODO ValueError (empty table name)?
4267
4277
efree (src );
4268
4278
php_error_docref (NULL , E_WARNING , "The table name must be specified" );
4269
4279
return FAILURE ;
@@ -4557,6 +4567,7 @@ static int php_pgsql_add_quotes(zval *src, zend_bool should_free)
4557
4567
}
4558
4568
/* }}} */
4559
4569
4570
+ /* Raise E_NOTICE to E_WARNING or Error? */
4560
4571
#define PGSQL_CONV_CHECK_IGNORE () \
4561
4572
if (!err && Z_TYPE(new_val) == IS_STRING && !strcmp(Z_STRVAL(new_val), "NULL")) { \
4562
4573
/* if new_value is string "NULL" and field has default value, remove element to use default value */ \
@@ -4600,8 +4611,10 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4600
4611
skip_field = 0 ;
4601
4612
ZVAL_NULL (& new_val );
4602
4613
4614
+ /* TODO: Check when meta data can be broken and see if can use assertions instead */
4615
+
4603
4616
if (!err && field == NULL ) {
4604
- php_error_docref ( NULL , E_WARNING , "Accepts only string key for values " );
4617
+ zend_value_error ( "Array of values must be an associative array with string keys " );
4605
4618
err = 1 ;
4606
4619
}
4607
4620
@@ -4625,8 +4638,8 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4625
4638
php_error_docref (NULL , E_NOTICE , "Detected broken meta data. Missing 'is enum'" );
4626
4639
err = 1 ;
4627
4640
}
4628
- if (!err && (Z_TYPE_P (val ) == IS_ARRAY || Z_TYPE_P (val ) == IS_OBJECT )) {
4629
- php_error_docref ( NULL , E_NOTICE , "Expects scalar values as field values" );
4641
+ if (!err && (Z_TYPE_P (val ) == IS_ARRAY || Z_TYPE_P (val ) == IS_OBJECT || Z_TYPE_P ( val ) == IS_RESOURCE )) {
4642
+ zend_type_error ( "Values must be of type string|int|float|bool|null, %s given" , zend_zval_type_name ( val ) );
4630
4643
err = 1 ;
4631
4644
}
4632
4645
if (err ) {
@@ -4641,6 +4654,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4641
4654
data_type = php_pgsql_get_data_type (Z_STRVAL_P (type ), Z_STRLEN_P (type ));
4642
4655
}
4643
4656
4657
+ /* TODO: Should E_NOTICE be converted to type error if PHP type cannot be converted to field type? */
4644
4658
switch (data_type )
4645
4659
{
4646
4660
case PG_BOOL :
@@ -5358,7 +5372,7 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var
5358
5372
5359
5373
ZEND_HASH_FOREACH_STR_KEY (Z_ARRVAL_P (var_array ), fld ) {
5360
5374
if (fld == NULL ) {
5361
- php_error_docref ( NULL , E_NOTICE , "Expects associative array for values to be inserted " );
5375
+ zend_value_error ( "Array of values must be an associative array with string keys " );
5362
5376
goto cleanup ;
5363
5377
}
5364
5378
if (opt & PGSQL_DML_ESCAPE ) {
@@ -5401,9 +5415,8 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var
5401
5415
smart_str_appendl (& querystr , "NULL" , sizeof ("NULL" )- 1 );
5402
5416
break ;
5403
5417
default :
5404
- php_error_docref ( NULL , E_WARNING , "Expects scaler values. type = %d " , Z_TYPE_P (val ));
5418
+ zend_type_error ( "Value must be of type string|int|float|null, %s given " , zend_zval_type_name (val ));
5405
5419
goto cleanup ;
5406
- break ;
5407
5420
}
5408
5421
smart_str_appendc (& querystr , ',' );
5409
5422
} ZEND_HASH_FOREACH_END ();
@@ -5532,7 +5545,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,
5532
5545
5533
5546
ZEND_HASH_FOREACH_STR_KEY_VAL (ht , fld , val ) {
5534
5547
if (fld == NULL ) {
5535
- php_error_docref ( NULL , E_NOTICE , "Expects associative array for values to be inserted " );
5548
+ zend_value_error ( "Array of values must be an associative array with string keys " );
5536
5549
return -1 ;
5537
5550
}
5538
5551
if (opt & PGSQL_DML_ESCAPE ) {
@@ -5573,7 +5586,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,
5573
5586
smart_str_appendl (querystr , "NULL" , sizeof ("NULL" )- 1 );
5574
5587
break ;
5575
5588
default :
5576
- php_error_docref ( NULL , E_WARNING , "Expects scaler values. type=%d " , Z_TYPE_P (val ));
5589
+ zend_type_error ( "Value must be of type string|int|float|null, %s given " , zend_zval_type_name (val ));
5577
5590
return -1 ;
5578
5591
}
5579
5592
smart_str_appendl (querystr , pad , pad_len );
0 commit comments