@@ -4236,7 +4236,7 @@ PHP_FUNCTION(pg_flush)
4236
4236
* table_name must not be empty
4237
4237
* TODO: Add meta_data cache for better performance
4238
4238
*/
4239
- PHP_PGSQL_API zend_result php_pgsql_meta_data (PGconn * pg_link , const char * table_name , zval * meta , bool extended )
4239
+ PHP_PGSQL_API zend_result php_pgsql_meta_data (PGconn * pg_link , const zend_string * table_name , zval * meta , bool extended )
4240
4240
{
4241
4241
PGresult * pg_result ;
4242
4242
char * src , * tmp_name , * tmp_name2 = NULL ;
@@ -4246,9 +4246,9 @@ PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const char *table
4246
4246
int i , num_rows ;
4247
4247
zval elem ;
4248
4248
4249
- ZEND_ASSERT (* table_name );
4249
+ ZEND_ASSERT (ZSTR_LEN ( table_name ) != 0 );
4250
4250
4251
- src = estrdup (table_name );
4251
+ src = estrdup (ZSTR_VAL ( table_name ) );
4252
4252
tmp_name = php_strtok_r (src , "." , & tmp_name2 );
4253
4253
if (!tmp_name ) {
4254
4254
// TODO ValueError (empty table name)?
@@ -4302,7 +4302,7 @@ PHP_PGSQL_API zend_result php_pgsql_meta_data(PGconn *pg_link, const char *table
4302
4302
4303
4303
pg_result = PQexec (pg_link , ZSTR_VAL (querystr .s ));
4304
4304
if (PQresultStatus (pg_result ) != PGRES_TUPLES_OK || (num_rows = PQntuples (pg_result )) == 0 ) {
4305
- php_error_docref (NULL , E_WARNING , "Table '%s' doesn't exists" , table_name );
4305
+ php_error_docref (NULL , E_WARNING , "Table '%s' doesn't exists" , ZSTR_VAL ( table_name ) );
4306
4306
smart_str_free (& querystr );
4307
4307
PQclear (pg_result );
4308
4308
return FAILURE ;
@@ -4369,7 +4369,7 @@ PHP_FUNCTION(pg_meta_data)
4369
4369
}
4370
4370
4371
4371
array_init (return_value );
4372
- if (php_pgsql_meta_data (pgsql , ZSTR_VAL ( table_name ) , return_value , extended ) == FAILURE ) {
4372
+ if (php_pgsql_meta_data (pgsql , table_name , return_value , extended ) == FAILURE ) {
4373
4373
zend_array_destroy (Z_ARR_P (return_value )); /* destroy array */
4374
4374
RETURN_FALSE ;
4375
4375
}
@@ -4560,7 +4560,7 @@ static int php_pgsql_add_quotes(zval *src, bool should_free)
4560
4560
/* {{{ php_pgsql_convert
4561
4561
* check and convert array values (fieldname=>value pair) for sql
4562
4562
*/
4563
- PHP_PGSQL_API zend_result php_pgsql_convert (PGconn * pg_link , const char * table_name , const zval * values , zval * result , zend_ulong opt )
4563
+ PHP_PGSQL_API zend_result php_pgsql_convert (PGconn * pg_link , const zend_string * table_name , const zval * values , zval * result , zend_ulong opt )
4564
4564
{
4565
4565
zend_string * field = NULL ;
4566
4566
zval meta , * def , * type , * not_null , * has_default , * is_enum , * val , new_val ;
@@ -4573,10 +4573,10 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const char *table_n
4573
4573
ZEND_ASSERT (!(opt & ~PGSQL_CONV_OPTS ));
4574
4574
ZEND_ASSERT (table_name );
4575
4575
/* Table name cannot be empty for php_pgsql_meta_data() */
4576
- ZEND_ASSERT (* table_name );
4576
+ ZEND_ASSERT (ZSTR_LEN ( table_name ) != 0 );
4577
4577
4578
4578
array_init (& meta );
4579
- /* table_name is escaped by php_pgsql_meta_data */
4579
+ /* table_name is escaped by php_pgsql_meta_data */
4580
4580
if (php_pgsql_meta_data (pg_link , table_name , & meta , 0 ) == FAILURE ) {
4581
4581
zval_ptr_dtor (& meta );
4582
4582
return FAILURE ;
@@ -5246,7 +5246,7 @@ PHP_FUNCTION(pg_convert)
5246
5246
php_error_docref (NULL , E_NOTICE , "Detected unhandled result(s) in connection" );
5247
5247
}
5248
5248
array_init (return_value );
5249
- if (php_pgsql_convert (pg_link , ZSTR_VAL ( table_name ) , values , return_value , option ) == FAILURE ) {
5249
+ if (php_pgsql_convert (pg_link , table_name , values , return_value , option ) == FAILURE ) {
5250
5250
zend_array_destroy (Z_ARR_P (return_value ));
5251
5251
RETURN_FALSE ;
5252
5252
}
@@ -5276,23 +5276,22 @@ static bool do_exec(smart_str *querystr, ExecStatusType expect, PGconn *pg_link,
5276
5276
}
5277
5277
/* }}} */
5278
5278
5279
- static inline void build_tablename (smart_str * querystr , PGconn * pg_link , const char * table ) /* {{{ */
5279
+ static inline void build_tablename (smart_str * querystr , PGconn * pg_link , const zend_string * table ) /* {{{ */
5280
5280
{
5281
- size_t table_len = strlen (table );
5282
-
5283
5281
/* schema.table should be "schema"."table" */
5284
- const char * dot = memchr (table , '.' , table_len );
5285
- size_t len = dot ? dot - table : table_len ;
5286
- if (_php_pgsql_identifier_is_escaped (table , len )) {
5287
- smart_str_appendl (querystr , table , len );
5282
+ const char * dot = memchr (ZSTR_VAL (table ), '.' , ZSTR_LEN (table ));
5283
+ size_t len = dot ? dot - ZSTR_VAL (table ) : ZSTR_LEN (table );
5284
+
5285
+ if (_php_pgsql_identifier_is_escaped (ZSTR_VAL (table ), len )) {
5286
+ smart_str_appendl (querystr , ZSTR_VAL (table ), len );
5288
5287
} else {
5289
- char * escaped = PQescapeIdentifier (pg_link , table , len );
5288
+ char * escaped = PQescapeIdentifier (pg_link , ZSTR_VAL ( table ) , len );
5290
5289
smart_str_appends (querystr , escaped );
5291
5290
PQfreemem (escaped );
5292
5291
}
5293
5292
if (dot ) {
5294
5293
const char * after_dot = dot + 1 ;
5295
- len = table_len - len - 1 ;
5294
+ len = ZSTR_LEN ( table ) - len - 1 ;
5296
5295
/* "schema"."table" format */
5297
5296
if (_php_pgsql_identifier_is_escaped (after_dot , len )) {
5298
5297
smart_str_appendc (querystr , '.' );
@@ -5308,7 +5307,7 @@ static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const c
5308
5307
/* }}} */
5309
5308
5310
5309
/* {{{ php_pgsql_insert */
5311
- PHP_PGSQL_API zend_result php_pgsql_insert (PGconn * pg_link , const char * table , zval * var_array , zend_ulong opt , zend_string * * sql )
5310
+ PHP_PGSQL_API zend_result php_pgsql_insert (PGconn * pg_link , const zend_string * table , zval * var_array , zend_ulong opt , zend_string * * sql )
5312
5311
{
5313
5312
zval * val , converted ;
5314
5313
char buf [256 ];
@@ -5459,7 +5458,7 @@ PHP_FUNCTION(pg_insert)
5459
5458
if (option & PGSQL_DML_EXEC ) {
5460
5459
/* return resource when executed */
5461
5460
option = option & ~PGSQL_DML_EXEC ;
5462
- if (php_pgsql_insert (pg_link , ZSTR_VAL ( table ) , values , option |PGSQL_DML_STRING , & sql ) == FAILURE ) {
5461
+ if (php_pgsql_insert (pg_link , table , values , option |PGSQL_DML_STRING , & sql ) == FAILURE ) {
5463
5462
RETURN_FALSE ;
5464
5463
}
5465
5464
pg_result = PQexec (pg_link , ZSTR_VAL (sql ));
@@ -5499,7 +5498,7 @@ PHP_FUNCTION(pg_insert)
5499
5498
}
5500
5499
break ;
5501
5500
}
5502
- } else if (php_pgsql_insert (pg_link , ZSTR_VAL ( table ) , values , option , & sql ) == FAILURE ) {
5501
+ } else if (php_pgsql_insert (pg_link , table , values , option , & sql ) == FAILURE ) {
5503
5502
RETURN_FALSE ;
5504
5503
}
5505
5504
if (return_sql ) {
@@ -5573,7 +5572,7 @@ static inline int build_assignment_string(PGconn *pg_link, smart_str *querystr,
5573
5572
/* }}} */
5574
5573
5575
5574
/* {{{ php_pgsql_update */
5576
- 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 )
5575
+ 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 )
5577
5576
{
5578
5577
zval var_converted , ids_converted ;
5579
5578
smart_str querystr = {0 };
@@ -5671,7 +5670,7 @@ PHP_FUNCTION(pg_update)
5671
5670
if (php_pgsql_flush_query (pg_link )) {
5672
5671
php_error_docref (NULL , E_NOTICE , "Detected unhandled result(s) in connection" );
5673
5672
}
5674
- if (php_pgsql_update (pg_link , ZSTR_VAL ( table ) , values , ids , option , & sql ) == FAILURE ) {
5673
+ if (php_pgsql_update (pg_link , table , values , ids , option , & sql ) == FAILURE ) {
5675
5674
RETURN_FALSE ;
5676
5675
}
5677
5676
if (option & PGSQL_DML_STRING ) {
@@ -5682,7 +5681,7 @@ PHP_FUNCTION(pg_update)
5682
5681
/* }}} */
5683
5682
5684
5683
/* {{{ php_pgsql_delete */
5685
- PHP_PGSQL_API zend_result php_pgsql_delete (PGconn * pg_link , const char * table , zval * ids_array , zend_ulong opt , zend_string * * sql )
5684
+ PHP_PGSQL_API zend_result php_pgsql_delete (PGconn * pg_link , const zend_string * table , zval * ids_array , zend_ulong opt , zend_string * * sql )
5686
5685
{
5687
5686
zval ids_converted ;
5688
5687
smart_str querystr = {0 };
@@ -5766,7 +5765,7 @@ PHP_FUNCTION(pg_delete)
5766
5765
if (php_pgsql_flush_query (pg_link )) {
5767
5766
php_error_docref (NULL , E_NOTICE , "Detected unhandled result(s) in connection" );
5768
5767
}
5769
- if (php_pgsql_delete (pg_link , ZSTR_VAL ( table ) , ids , option , & sql ) == FAILURE ) {
5768
+ if (php_pgsql_delete (pg_link , table , ids , option , & sql ) == FAILURE ) {
5770
5769
RETURN_FALSE ;
5771
5770
}
5772
5771
if (option & PGSQL_DML_STRING ) {
@@ -5818,7 +5817,7 @@ PHP_PGSQL_API void php_pgsql_result2array(PGresult *pg_result, zval *ret_array,
5818
5817
/* }}} */
5819
5818
5820
5819
/* {{{ php_pgsql_select */
5821
- 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 )
5820
+ 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 )
5822
5821
{
5823
5822
zval ids_converted ;
5824
5823
smart_str querystr = {0 };
@@ -5914,7 +5913,7 @@ PHP_FUNCTION(pg_select)
5914
5913
php_error_docref (NULL , E_NOTICE , "Detected unhandled result(s) in connection" );
5915
5914
}
5916
5915
array_init (return_value );
5917
- if (php_pgsql_select (pg_link , ZSTR_VAL ( table ) , ids , return_value , option , result_type , & sql ) == FAILURE ) {
5916
+ if (php_pgsql_select (pg_link , table , ids , return_value , option , result_type , & sql ) == FAILURE ) {
5918
5917
zval_ptr_dtor (return_value );
5919
5918
RETURN_FALSE ;
5920
5919
}
0 commit comments