@@ -2300,6 +2300,7 @@ PHP_FUNCTION(pg_lo_create)
2300
2300
RETURN_THROWS ();
2301
2301
}
2302
2302
2303
+ /* Overloaded method use default link if arg 1 is not a ressource, 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 zend_is_numeric_string/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
2330
/* wrong integer format */
2329
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2330
- RETURN_FALSE ;
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 zend_is_numeric_string/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: Use zend_is_numeric_string/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 zend_is_numeric_string/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 zend_is_numeric_string/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 ();
@@ -2525,6 +2531,7 @@ PHP_FUNCTION(pg_lo_open)
2525
2531
if ((pgsql_lofd = lo_open (pgsql , oid , pgsql_mode )) == -1 ) {
2526
2532
if (lo_unlink (pgsql , oid ) == -1 ) {
2527
2533
efree (pgsql_lofp );
2534
+ /* TODO: Throw error? */
2528
2535
php_error_docref (NULL , E_WARNING , "Something is really messed up! Your database is badly corrupted in a way NOT related to PHP" );
2529
2536
RETURN_FALSE ;
2530
2537
}
@@ -2717,25 +2724,26 @@ PHP_FUNCTION(pg_lo_import)
2717
2724
switch (Z_TYPE_P (oid )) {
2718
2725
case IS_STRING :
2719
2726
{
2727
+ /* TODO: Use zend_is_numeric_string/subroutine? */
2720
2728
char * end_ptr ;
2721
2729
wanted_oid = (Oid )strtoul (Z_STRVAL_P (oid ), & end_ptr , 10 );
2722
2730
if ((Z_STRVAL_P (oid )+ Z_STRLEN_P (oid )) != end_ptr ) {
2723
2731
/* wrong integer format */
2724
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2725
- RETURN_FALSE ;
2732
+ zend_value_error ( "Invalid OID value passed" );
2733
+ RETURN_THROWS () ;
2726
2734
}
2727
2735
}
2728
2736
break ;
2729
2737
case IS_LONG :
2730
2738
if (Z_LVAL_P (oid ) < (zend_long )InvalidOid ) {
2731
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2732
- RETURN_FALSE ;
2739
+ zend_value_error ( "Invalid OID value passed" );
2740
+ RETURN_THROWS () ;
2733
2741
}
2734
2742
wanted_oid = (Oid )Z_LVAL_P (oid );
2735
2743
break ;
2736
2744
default :
2737
- php_error_docref ( NULL , E_NOTICE , "Invalid OID value passed" );
2738
- RETURN_FALSE ;
2745
+ zend_type_error ( " OID value must be of type string|int, %s given" , zend_zval_type_name ( oid ) );
2746
+ RETURN_THROWS () ;
2739
2747
}
2740
2748
2741
2749
returned_oid = lo_import_with_oid (pgsql , file_in , wanted_oid );
@@ -2773,39 +2781,41 @@ PHP_FUNCTION(pg_lo_export)
2773
2781
if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2774
2782
"rlp" , & pgsql_link , & oid_long , & file_out , & name_len ) == SUCCESS ) {
2775
2783
if (oid_long <= (zend_long )InvalidOid ) {
2776
- php_error_docref ( NULL , E_NOTICE , "Invalid OID specified " );
2777
- RETURN_FALSE ;
2784
+ zend_value_error ( "Invalid OID value passed " );
2785
+ RETURN_THROWS () ;
2778
2786
}
2779
2787
oid = (Oid )oid_long ;
2780
2788
link = Z_RES_P (pgsql_link );
2781
2789
}
2782
2790
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2783
2791
"rsp" , & pgsql_link , & oid_string , & oid_strlen , & file_out , & name_len ) == SUCCESS ) {
2792
+ /* TODO: Use zend_is_numeric_string/subroutine? */
2784
2793
oid = (Oid )strtoul (oid_string , & end_ptr , 10 );
2785
2794
if ((oid_string + oid_strlen ) != end_ptr ) {
2786
2795
/* wrong integer format */
2787
- php_error_docref ( NULL , E_NOTICE , "Wrong OID value passed" );
2788
- RETURN_FALSE ;
2796
+ zend_value_error ( "Invalid OID value passed" );
2797
+ RETURN_THROWS () ;
2789
2798
}
2790
2799
link = Z_RES_P (pgsql_link );
2791
2800
}
2792
2801
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2793
2802
"lp" , & oid_long , & file_out , & name_len ) == SUCCESS ) {
2794
2803
if (oid_long <= (zend_long )InvalidOid ) {
2795
- php_error_docref ( NULL , E_NOTICE , "Invalid OID specified " );
2796
- RETURN_FALSE ;
2804
+ zend_value_error ( "Invalid OID value passed " );
2805
+ RETURN_THROWS () ;
2797
2806
}
2798
2807
oid = (Oid )oid_long ;
2799
2808
link = FETCH_DEFAULT_LINK ();
2800
2809
CHECK_DEFAULT_LINK (link );
2801
2810
}
2802
2811
else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , argc ,
2803
2812
"sp" , & oid_string , & oid_strlen , & file_out , & name_len ) == SUCCESS ) {
2813
+ /* TODO: Use zend_is_numeric_string/subroutine? */
2804
2814
oid = (Oid )strtoul (oid_string , & end_ptr , 10 );
2805
2815
if ((oid_string + oid_strlen ) != end_ptr ) {
2806
2816
/* wrong integer format */
2807
- php_error_docref ( NULL , E_NOTICE , "Wrong OID value passed" );
2808
- RETURN_FALSE ;
2817
+ zend_value_error ( "Invalid OID value passed" );
2818
+ RETURN_THROWS () ;
2809
2819
}
2810
2820
link = FETCH_DEFAULT_LINK ();
2811
2821
CHECK_DEFAULT_LINK (link );
@@ -4264,6 +4274,7 @@ PHP_PGSQL_API int php_pgsql_meta_data(PGconn *pg_link, const char *table_name, z
4264
4274
src = estrdup (table_name );
4265
4275
tmp_name = php_strtok_r (src , "." , & tmp_name2 );
4266
4276
if (!tmp_name ) {
4277
+ // TODO ValueError (empty table name)?
4267
4278
efree (src );
4268
4279
php_error_docref (NULL , E_WARNING , "The table name must be specified" );
4269
4280
return FAILURE ;
@@ -4557,6 +4568,7 @@ static int php_pgsql_add_quotes(zval *src, zend_bool should_free)
4557
4568
}
4558
4569
/* }}} */
4559
4570
4571
+ /* Raise E_NOTICE to E_WARNING or Error? */
4560
4572
#define PGSQL_CONV_CHECK_IGNORE () \
4561
4573
if (!err && Z_TYPE(new_val) == IS_STRING && !strcmp(Z_STRVAL(new_val), "NULL")) { \
4562
4574
/* if new_value is string "NULL" and field has default value, remove element to use default value */ \
@@ -4600,8 +4612,10 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4600
4612
skip_field = 0 ;
4601
4613
ZVAL_NULL (& new_val );
4602
4614
4615
+ /* TODO: Check when meta data can be broken and see if can use assertions instead */
4616
+
4603
4617
if (!err && field == NULL ) {
4604
- php_error_docref ( NULL , E_WARNING , "Accepts only string key for values " );
4618
+ zend_value_error ( "Array of values must be an associated array with string keys " );
4605
4619
err = 1 ;
4606
4620
}
4607
4621
@@ -4626,7 +4640,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4626
4640
err = 1 ;
4627
4641
}
4628
4642
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" );
4643
+ zend_type_error ( "Values must be of type string|int|float|bool|null, %s given" , zend_zval_type_name ( val ) );
4630
4644
err = 1 ;
4631
4645
}
4632
4646
if (err ) {
@@ -4641,6 +4655,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
4641
4655
data_type = php_pgsql_get_data_type (Z_STRVAL_P (type ), Z_STRLEN_P (type ));
4642
4656
}
4643
4657
4658
+ /* TODO: Should E_NOTICE be converted to type error if PHP type cannot be converted to field type? */
4644
4659
switch (data_type )
4645
4660
{
4646
4661
case PG_BOOL :
@@ -5358,7 +5373,7 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var
5358
5373
5359
5374
ZEND_HASH_FOREACH_STR_KEY (Z_ARRVAL_P (var_array ), fld ) {
5360
5375
if (fld == NULL ) {
5361
- php_error_docref ( NULL , E_NOTICE , "Expects associative array for values to be inserted " );
5376
+ zend_value_error ( "Array of values must be an associated array of string keys " );
5362
5377
goto cleanup ;
5363
5378
}
5364
5379
if (opt & PGSQL_DML_ESCAPE ) {
@@ -5401,9 +5416,8 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *var
5401
5416
smart_str_appendl (& querystr , "NULL" , sizeof ("NULL" )- 1 );
5402
5417
break ;
5403
5418
default :
5404
- php_error_docref ( NULL , E_WARNING , "Expects scaler values. type = %d " , Z_TYPE_P (val ));
5419
+ zend_type_error ( "Value must be of type string|int|float|null, %s given " , zend_zval_type_name (val ));
5405
5420
goto cleanup ;
5406
- break ;
5407
5421
}
5408
5422
smart_str_appendc (& querystr , ',' );
5409
5423
} ZEND_HASH_FOREACH_END ();
@@ -5532,7 +5546,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,
5532
5546
5533
5547
ZEND_HASH_FOREACH_STR_KEY_VAL (ht , fld , val ) {
5534
5548
if (fld == NULL ) {
5535
- php_error_docref ( NULL , E_NOTICE , "Expects associative array for values to be inserted " );
5549
+ zend_value_error ( "Array of values must be an associated array of string keys " );
5536
5550
return -1 ;
5537
5551
}
5538
5552
if (opt & PGSQL_DML_ESCAPE ) {
@@ -5573,7 +5587,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,
5573
5587
smart_str_appendl (querystr , "NULL" , sizeof ("NULL" )- 1 );
5574
5588
break ;
5575
5589
default :
5576
- php_error_docref ( NULL , E_WARNING , "Expects scaler values. type=%d " , Z_TYPE_P (val ));
5590
+ zend_type_error ( "Value must be of type string|int|float|null, %s given " , zend_zval_type_name (val ));
5577
5591
return -1 ;
5578
5592
}
5579
5593
smart_str_appendl (querystr , pad , pad_len );
0 commit comments