@@ -4225,7 +4225,7 @@ PHP_FUNCTION(pg_flush)
4225
4225
* table_name must not be empty
4226
4226
* TODO: Add meta_data cache for better performance
4227
4227
*/
4228
- PHP_PGSQL_API zend_result php_pgsql_meta_data (PGconn * pg_link , const char * table_name , zval * meta , bool extended )
4228
+ PHP_PGSQL_API zend_result php_pgsql_meta_data (PGconn * pg_link , const zend_string * table_name , zval * meta , bool extended )
4229
4229
{
4230
4230
PGresult * pg_result ;
4231
4231
char * src , * tmp_name , * tmp_name2 = NULL ;
@@ -4235,9 +4235,9 @@ PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const char *table
4235
4235
int i , num_rows ;
4236
4236
zval elem ;
4237
4237
4238
- ZEND_ASSERT (* table_name );
4238
+ ZEND_ASSERT (ZSTR_LEN ( table_name ) != 0 );
4239
4239
4240
- src = estrdup (table_name );
4240
+ src = estrdup (ZSTR_VAL ( table_name ) );
4241
4241
tmp_name = php_strtok_r (src , "." , & tmp_name2 );
4242
4242
if (!tmp_name ) {
4243
4243
// TODO ValueError (empty table name)?
@@ -4291,7 +4291,7 @@ PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const char *table
4291
4291
4292
4292
pg_result = PQexec (pg_link , ZSTR_VAL (querystr .s ));
4293
4293
if (PQresultStatus (pg_result ) != PGRES_TUPLES_OK || (num_rows = PQntuples (pg_result )) == 0 ) {
4294
- php_error_docref (NULL , E_WARNING , "Table '%s' doesn't exists" , table_name );
4294
+ php_error_docref (NULL , E_WARNING , "Table '%s' doesn't exists" , ZSTR_VAL ( table_name ) );
4295
4295
smart_str_free (& querystr );
4296
4296
PQclear (pg_result );
4297
4297
return FAILURE ;
@@ -4358,7 +4358,7 @@ PHP_FUNCTION(pg_meta_data)
4358
4358
}
4359
4359
4360
4360
array_init (return_value );
4361
- if (php_pgsql_meta_data (pgsql , ZSTR_VAL ( table_name ) , return_value , extended ) == FAILURE ) {
4361
+ if (php_pgsql_meta_data (pgsql , table_name , return_value , extended ) == FAILURE ) {
4362
4362
zend_array_destroy (Z_ARR_P (return_value )); /* destroy array */
4363
4363
RETURN_FALSE ;
4364
4364
}
@@ -4550,7 +4550,7 @@ static int php_pgsql_add_quotes(zval *src, bool should_free)
4550
4550
/* {{{ php_pgsql_convert
4551
4551
* check and convert array values (fieldname=>value pair) for sql
4552
4552
*/
4553
- PHP_PGSQL_API zend_result php_pgsql_convert (PGconn * pg_link , const char * table_name , const zval * values , zval * result , zend_ulong opt )
4553
+ PHP_PGSQL_API zend_result php_pgsql_convert (PGconn * pg_link , const zend_string * table_name , const zval * values , zval * result , zend_ulong opt )
4554
4554
{
4555
4555
zend_string * field = NULL ;
4556
4556
zval meta , * def , * type , * not_null , * has_default , * is_enum , * val , new_val ;
@@ -4563,10 +4563,10 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const char *table_n
4563
4563
ZEND_ASSERT (!(opt & ~PGSQL_CONV_OPTS ));
4564
4564
ZEND_ASSERT (table_name );
4565
4565
/* Table name cannot be empty for php_pgsql_meta_data() */
4566
- ZEND_ASSERT (* table_name );
4566
+ ZEND_ASSERT (ZSTR_LEN ( table_name ) != 0 );
4567
4567
4568
4568
array_init (& meta );
4569
- /* table_name is escaped by php_pgsql_meta_data */
4569
+ /* table_name is escaped by php_pgsql_meta_data */
4570
4570
if (php_pgsql_meta_data (pg_link , table_name , & meta , 0 ) == FAILURE ) {
4571
4571
zval_ptr_dtor (& meta );
4572
4572
return FAILURE ;
@@ -5236,7 +5236,7 @@ PHP_FUNCTION(pg_convert)
5236
5236
php_error_docref (NULL , E_NOTICE , "Detected unhandled result(s) in connection" );
5237
5237
}
5238
5238
array_init (return_value );
5239
- if (php_pgsql_convert (pg_link , ZSTR_VAL ( table_name ) , values , return_value , option ) == FAILURE ) {
5239
+ if (php_pgsql_convert (pg_link , table_name , values , return_value , option ) == FAILURE ) {
5240
5240
zend_array_destroy (Z_ARR_P (return_value ));
5241
5241
RETURN_FALSE ;
5242
5242
}
@@ -5267,23 +5267,22 @@ static int do_exec(smart_str *querystr, ExecStatusType expect, PGconn *pg_link,
5267
5267
}
5268
5268
/* }}} */
5269
5269
5270
- static inline void build_tablename (smart_str * querystr , PGconn * pg_link , const char * table ) /* {{{ */
5270
+ static inline void build_tablename (smart_str * querystr , PGconn * pg_link , const zend_string * table ) /* {{{ */
5271
5271
{
5272
- size_t table_len = strlen (table );
5273
-
5274
5272
/* schema.table should be "schema"."table" */
5275
- const char * dot = memchr (table , '.' , table_len );
5276
- size_t len = dot ? dot - table : table_len ;
5277
- if (_php_pgsql_identifier_is_escaped (table , len )) {
5278
- smart_str_appendl (querystr , table , len );
5273
+ const char * dot = memchr (ZSTR_VAL (table ), '.' , ZSTR_LEN (table ));
5274
+ size_t len = dot ? dot - ZSTR_VAL (table ) : ZSTR_LEN (table );
5275
+
5276
+ if (_php_pgsql_identifier_is_escaped (ZSTR_VAL (table ), len )) {
5277
+ smart_str_appendl (querystr , ZSTR_VAL (table ), len );
5279
5278
} else {
5280
- char * escaped = PQescapeIdentifier (pg_link , table , len );
5279
+ char * escaped = PQescapeIdentifier (pg_link , ZSTR_VAL ( table ) , len );
5281
5280
smart_str_appends (querystr , escaped );
5282
5281
PQfreemem (escaped );
5283
5282
}
5284
5283
if (dot ) {
5285
5284
const char * after_dot = dot + 1 ;
5286
- len = table_len - len - 1 ;
5285
+ len = ZSTR_LEN ( table ) - len - 1 ;
5287
5286
/* "schema"."table" format */
5288
5287
if (_php_pgsql_identifier_is_escaped (after_dot , len )) {
5289
5288
smart_str_appendc (querystr , '.' );
@@ -5299,7 +5298,7 @@ static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const c
5299
5298
/* }}} */
5300
5299
5301
5300
/* {{{ php_pgsql_insert */
5302
- PHP_PGSQL_API zend_result php_pgsql_insert (PGconn * pg_link , const char * table , zval * var_array , zend_ulong opt , zend_string * * sql )
5301
+ PHP_PGSQL_API zend_result php_pgsql_insert (PGconn * pg_link , const zend_string * table , zval * var_array , zend_ulong opt , zend_string * * sql )
5303
5302
{
5304
5303
zval * val , converted ;
5305
5304
char buf [256 ];
@@ -5450,7 +5449,7 @@ PHP_FUNCTION(pg_insert)
5450
5449
if (option & PGSQL_DML_EXEC ) {
5451
5450
/* return resource when executed */
5452
5451
option = option & ~PGSQL_DML_EXEC ;
5453
- if (php_pgsql_insert (pg_link , ZSTR_VAL ( table ) , values , option |PGSQL_DML_STRING , & sql ) == FAILURE ) {
5452
+ if (php_pgsql_insert (pg_link , table , values , option |PGSQL_DML_STRING , & sql ) == FAILURE ) {
5454
5453
RETURN_FALSE ;
5455
5454
}
5456
5455
pg_result = PQexec (pg_link , ZSTR_VAL (sql ));
@@ -5490,7 +5489,7 @@ PHP_FUNCTION(pg_insert)
5490
5489
}
5491
5490
break ;
5492
5491
}
5493
- } else if (php_pgsql_insert (pg_link , ZSTR_VAL ( table ) , values , option , & sql ) == FAILURE ) {
5492
+ } else if (php_pgsql_insert (pg_link , table , values , option , & sql ) == FAILURE ) {
5494
5493
RETURN_FALSE ;
5495
5494
}
5496
5495
if (return_sql ) {
@@ -5564,7 +5563,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,
5564
5563
/* }}} */
5565
5564
5566
5565
/* {{{ php_pgsql_update */
5567
- PHP_PGSQL_API zend_result php_pgsql_update (PGconn * pg_link , const char * table , zval * var_array , zval * ids_array , zend_ulong opt , zend_string * * sql )
5566
+ PHP_PGSQL_API zend_result php_pgsql_update (PGconn * pg_link , const zend_string * table , zval * var_array , zval * ids_array , zend_ulong opt , zend_string * * sql )
5568
5567
{
5569
5568
zval var_converted , ids_converted ;
5570
5569
smart_str querystr = {0 };
@@ -5662,7 +5661,7 @@ PHP_FUNCTION(pg_update)
5662
5661
if (php_pgsql_flush_query (pg_link )) {
5663
5662
php_error_docref (NULL , E_NOTICE , "Detected unhandled result(s) in connection" );
5664
5663
}
5665
- if (php_pgsql_update (pg_link , ZSTR_VAL ( table ) , values , ids , option , & sql ) == FAILURE ) {
5664
+ if (php_pgsql_update (pg_link , table , values , ids , option , & sql ) == FAILURE ) {
5666
5665
RETURN_FALSE ;
5667
5666
}
5668
5667
if (option & PGSQL_DML_STRING ) {
@@ -5673,7 +5672,7 @@ PHP_FUNCTION(pg_update)
5673
5672
/* }}} */
5674
5673
5675
5674
/* {{{ php_pgsql_delete */
5676
- PHP_PGSQL_API zend_result php_pgsql_delete (PGconn * pg_link , const char * table , zval * ids_array , zend_ulong opt , zend_string * * sql )
5675
+ PHP_PGSQL_API zend_result php_pgsql_delete (PGconn * pg_link , const zend_string * table , zval * ids_array , zend_ulong opt , zend_string * * sql )
5677
5676
{
5678
5677
zval ids_converted ;
5679
5678
smart_str querystr = {0 };
@@ -5757,7 +5756,7 @@ PHP_FUNCTION(pg_delete)
5757
5756
if (php_pgsql_flush_query (pg_link )) {
5758
5757
php_error_docref (NULL , E_NOTICE , "Detected unhandled result(s) in connection" );
5759
5758
}
5760
- if (php_pgsql_delete (pg_link , ZSTR_VAL ( table ) , ids , option , & sql ) == FAILURE ) {
5759
+ if (php_pgsql_delete (pg_link , table , ids , option , & sql ) == FAILURE ) {
5761
5760
RETURN_FALSE ;
5762
5761
}
5763
5762
if (option & PGSQL_DML_STRING ) {
@@ -5808,7 +5807,7 @@ PHP_PGSQL_API void php_pgsql_result2array(PGresult *pg_result, zval *ret_array,
5808
5807
/* }}} */
5809
5808
5810
5809
/* {{{ php_pgsql_select */
5811
- PHP_PGSQL_API zend_result php_pgsql_select (PGconn * pg_link , const char * table , zval * ids_array , zval * ret_array , zend_ulong opt , long result_type , zend_string * * sql )
5810
+ PHP_PGSQL_API zend_result php_pgsql_select (PGconn * pg_link , const zend_string * table , zval * ids_array , zval * ret_array , zend_ulong opt , long result_type , zend_string * * sql )
5812
5811
{
5813
5812
zval ids_converted ;
5814
5813
smart_str querystr = {0 };
@@ -5904,7 +5903,7 @@ PHP_FUNCTION(pg_select)
5904
5903
php_error_docref (NULL , E_NOTICE , "Detected unhandled result(s) in connection" );
5905
5904
}
5906
5905
array_init (return_value );
5907
- if (php_pgsql_select (pg_link , ZSTR_VAL ( table ) , ids , return_value , option , result_type , & sql ) == FAILURE ) {
5906
+ if (php_pgsql_select (pg_link , table , ids , return_value , option , result_type , & sql ) == FAILURE ) {
5908
5907
zval_ptr_dtor (return_value );
5909
5908
RETURN_FALSE ;
5910
5909
}
0 commit comments