@@ -4521,24 +4521,9 @@ static int php_pgsql_convert_match(const zend_string *str, const char *regex , s
4521
4521
/* {{{ php_pgsql_add_quote
4522
4522
* add quotes around string.
4523
4523
*/
4524
- static int php_pgsql_add_quotes (zval * src , bool should_free )
4524
+ static zend_string * php_pgsql_add_quotes (zend_string * src )
4525
4525
{
4526
- smart_str str = {0 };
4527
-
4528
- ZEND_ASSERT (Z_TYPE_P (src ) == IS_STRING );
4529
-
4530
- smart_str_appendc (& str , 'E' );
4531
- smart_str_appendc (& str , '\'' );
4532
- smart_str_appendl (& str , Z_STRVAL_P (src ), Z_STRLEN_P (src ));
4533
- smart_str_appendc (& str , '\'' );
4534
- smart_str_0 (& str );
4535
-
4536
- if (should_free ) {
4537
- zval_ptr_dtor (src );
4538
- }
4539
- ZVAL_NEW_STR (src , str .s );
4540
-
4541
- return SUCCESS ;
4526
+ return zend_string_concat3 ("E'" , strlen ("E'" ), ZSTR_VAL (src ), ZSTR_LEN (src ), "'" , strlen ("'" ));
4542
4527
}
4543
4528
/* }}} */
4544
4529
@@ -4751,8 +4736,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4751
4736
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX1 , sizeof (REGEX1 )- 1 , 1 ) == FAILURE ) {
4752
4737
err = 1 ;
4753
4738
} else {
4754
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4755
- php_pgsql_add_quotes (& new_val , 1 );
4739
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4756
4740
}
4757
4741
}
4758
4742
else {
@@ -4818,9 +4802,8 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4818
4802
str = zend_string_alloc (Z_STRLEN_P (val ) * 2 , 0 );
4819
4803
/* better to use PGSQLescapeLiteral since PGescapeStringConn does not handle special \ */
4820
4804
ZSTR_LEN (str ) = PQescapeStringConn (pg_link , ZSTR_VAL (str ), Z_STRVAL_P (val ), Z_STRLEN_P (val ), NULL );
4821
- str = zend_string_truncate (str , ZSTR_LEN (str ), 0 );
4822
- ZVAL_NEW_STR (& new_val , str );
4823
- php_pgsql_add_quotes (& new_val , 1 );
4805
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (str ));
4806
+ zend_string_release_ex (str , false);
4824
4807
}
4825
4808
break ;
4826
4809
@@ -4906,8 +4889,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4906
4889
err = 1 ;
4907
4890
}
4908
4891
else {
4909
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
4910
- php_pgsql_add_quotes (& new_val , 1 );
4892
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4911
4893
}
4912
4894
#undef REGEX0
4913
4895
#undef REGEX1
@@ -4942,8 +4924,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4942
4924
if (php_pgsql_convert_match (Z_STR_P (val ), REGEX0 , sizeof (REGEX0 )- 1 , 1 ) == FAILURE ) {
4943
4925
err = 1 ;
4944
4926
} else {
4945
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
4946
- php_pgsql_add_quotes (& new_val , 1 );
4927
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4947
4928
}
4948
4929
#undef REGEX0
4949
4930
}
@@ -4975,8 +4956,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
4975
4956
err = 1 ;
4976
4957
}
4977
4958
else {
4978
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
4979
- php_pgsql_add_quotes (& new_val , 1 );
4959
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
4980
4960
}
4981
4961
#undef REGEX0
4982
4962
}
@@ -5008,8 +4988,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5008
4988
err = 1 ;
5009
4989
}
5010
4990
else {
5011
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
5012
- php_pgsql_add_quotes (& new_val , 1 );
4991
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5013
4992
}
5014
4993
#undef REGEX0
5015
4994
}
@@ -5087,8 +5066,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5087
5066
err = 1 ;
5088
5067
}
5089
5068
else {
5090
- ZVAL_STRING (& new_val , Z_STRVAL_P (val ));
5091
- php_pgsql_add_quotes (& new_val , 1 );
5069
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5092
5070
}
5093
5071
#undef REGEX0
5094
5072
}
@@ -5115,15 +5093,14 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5115
5093
else {
5116
5094
unsigned char * tmp ;
5117
5095
size_t to_len ;
5118
- smart_str s = {0 };
5096
+ zend_string * tmp_zstr ;
5097
+
5119
5098
tmp = PQescapeByteaConn (pg_link , (unsigned char * )Z_STRVAL_P (val ), Z_STRLEN_P (val ), & to_len );
5120
- ZVAL_STRINGL ( & new_val , ( char * )tmp , to_len - 1 ); /* PQescapeBytea's to_len includes additional '\0' */
5099
+ tmp_zstr = zend_string_init (( char * )tmp , to_len - 1 , false ); /* PQescapeBytea's to_len includes additional '\0' */
5121
5100
PQfreemem (tmp );
5122
- php_pgsql_add_quotes (& new_val , 1 );
5123
- smart_str_appendl (& s , Z_STRVAL (new_val ), Z_STRLEN (new_val ));
5124
- smart_str_0 (& s );
5125
- zval_ptr_dtor (& new_val );
5126
- ZVAL_NEW_STR (& new_val , s .s );
5101
+
5102
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (tmp_zstr ));
5103
+ zend_string_release_ex (tmp_zstr , false);
5127
5104
}
5128
5105
break ;
5129
5106
@@ -5161,8 +5138,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
5161
5138
err = 1 ;
5162
5139
}
5163
5140
else {
5164
- ZVAL_STRINGL (& new_val , Z_STRVAL_P (val ), Z_STRLEN_P (val ));
5165
- php_pgsql_add_quotes (& new_val , 1 );
5141
+ ZVAL_STR (& new_val , php_pgsql_add_quotes (Z_STR_P (val )));
5166
5142
}
5167
5143
#undef REGEX0
5168
5144
}
0 commit comments