@@ -4511,24 +4511,9 @@ static int php_pgsql_convert_match(const zend_string *str, const char *regex , s
4511
4511
/* {{{ php_pgsql_add_quote
4512
4512
* add quotes around string.
4513
4513
*/
4514
- static int php_pgsql_add_quotes (zval * src , bool should_free )
4514
+ static zend_string * php_pgsql_add_quotes (zend_string * src )
4515
4515
{
4516
- smart_str str = {0 };
4517
-
4518
- ZEND_ASSERT (Z_TYPE_P (src ) == IS_STRING );
4519
-
4520
- smart_str_appendc (& str , 'E' );
4521
- smart_str_appendc (& str , '\'' );
4522
- smart_str_appendl (& str , Z_STRVAL_P (src ), Z_STRLEN_P (src ));
4523
- smart_str_appendc (& str , '\'' );
4524
- smart_str_0 (& str );
4525
-
4526
- if (should_free ) {
4527
- zval_ptr_dtor (src );
4528
- }
4529
- ZVAL_NEW_STR (src , str .s );
4530
-
4531
- return SUCCESS ;
4516
+ return zend_string_concat3 ("E'" , strlen ("E'" ), ZSTR_VAL (src ), ZSTR_LEN (src ), "'" , strlen ("'" ));
4532
4517
}
4533
4518
/* }}} */
4534
4519
@@ -4741,8 +4726,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4741
4726
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX1 , sizeof (REGEX1 )- 1 , 1 ) == FAILURE ) {
4742
4727
err = 1 ;
4743
4728
} else {
4744
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4745
- php_pgsql_add_quotes (& new_val , 1 );
4729
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4746
4730
}
4747
4731
}
4748
4732
else {
@@ -4809,8 +4793,8 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4809
4793
/* better to use PGSQLescapeLiteral since PGescapeStringConn does not handle special \ */
4810
4794
ZSTR_LEN (str ) = PQescapeStringConn (pg_link , ZSTR_VAL (str ), Z_STRVAL_P (val ), Z_STRLEN_P (val ), NULL );
4811
4795
str = zend_string_truncate (str , ZSTR_LEN (str ), 0 );
4812
- ZVAL_NEW_STR (& new_val , str );
4813
- php_pgsql_add_quotes ( & new_val , 1 );
4796
+ ZVAL_STR (& new_val , php_pgsql_add_quotes ( str ) );
4797
+ zend_string_release_ex ( str , false );
4814
4798
}
4815
4799
break ;
4816
4800
@@ -4896,8 +4880,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4896
4880
err = 1 ;
4897
4881
}
4898
4882
else {
4899
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
4900
- php_pgsql_add_quotes (& new_val , 1 );
4883
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4901
4884
}
4902
4885
#undef REGEX0
4903
4886
#undef REGEX1
@@ -4932,8 +4915,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4932
4915
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX0 , sizeof (REGEX0 )- 1 , 1 ) == FAILURE ) {
4933
4916
err = 1 ;
4934
4917
} else {
4935
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4936
- php_pgsql_add_quotes (& new_val , 1 );
4918
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4937
4919
}
4938
4920
#undef REGEX0
4939
4921
}
@@ -4965,8 +4947,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4965
4947
err = 1 ;
4966
4948
}
4967
4949
else {
4968
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
4969
- php_pgsql_add_quotes (& new_val , 1 );
4950
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4970
4951
}
4971
4952
#undef REGEX0
4972
4953
}
@@ -4998,8 +4979,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4998
4979
err = 1 ;
4999
4980
}
5000
4981
else {
5001
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
5002
- php_pgsql_add_quotes (& new_val , 1 );
4982
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5003
4983
}
5004
4984
#undef REGEX0
5005
4985
}
@@ -5077,8 +5057,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5077
5057
err = 1 ;
5078
5058
}
5079
5059
else {
5080
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
5081
- php_pgsql_add_quotes (& new_val , 1 );
5060
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5082
5061
}
5083
5062
#undef REGEX0
5084
5063
}
@@ -5105,15 +5084,14 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5105
5084
else {
5106
5085
unsigned char * tmp ;
5107
5086
size_t to_len ;
5108
- smart_str s = {0 };
5087
+ zend_string * tmp_zstr ;
5088
+
5109
5089
tmp = PQescapeByteaConn (pg_link , (unsigned char * )Z_STRVAL_P (val ), Z_STRLEN_P (val ), & to_len );
5110
- ZVAL_STRINGL ( & new_val , ( char * )tmp , to_len - 1 ); /* PQescapeBytea's to_len includes additional '\0' */
5090
+ tmp_zstr = zend_string_init (( char * )tmp , to_len - 1 , false ); /* PQescapeBytea's to_len includes additional '\0' */
5111
5091
PQfreemem (tmp );
5112
- php_pgsql_add_quotes (& new_val , 1 );
5113
- smart_str_appendl (& s , Z_STRVAL (new_val ), Z_STRLEN (new_val ));
5114
- smart_str_0 (& s );
5115
- zval_ptr_dtor (& new_val );
5116
- ZVAL_NEW_STR (& new_val , s .s );
5092
+
5093
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (tmp_zstr ));
5094
+ zend_string_release_ex (tmp_zstr , false);
5117
5095
}
5118
5096
break ;
5119
5097
@@ -5151,8 +5129,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5151
5129
err = 1 ;
5152
5130
}
5153
5131
else {
5154
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
5155
- php_pgsql_add_quotes (& new_val , 1 );
5132
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5156
5133
}
5157
5134
#undef REGEX0
5158
5135
}
0 commit comments