diff options
Diffstat (limited to 'ext/dbx/dbx_pgsql.c')
| -rw-r--r-- | ext/dbx/dbx_pgsql.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/ext/dbx/dbx_pgsql.c b/ext/dbx/dbx_pgsql.c index 88e28816ee..c8cac1908c 100644 --- a/ext/dbx/dbx_pgsql.c +++ b/ext/dbx/dbx_pgsql.c @@ -275,6 +275,30 @@ int dbx_pgsql_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS) return 1; } +int dbx_pgsql_esc(zval **rv, zval **dbx_handle, zval **string, INTERNAL_FUNCTION_PARAMETERS) +{ + /* returns escaped string */ + /* replace \ with \\ */ + /* ' with '' */ + char * str; + int len; + char * tmpstr; + int tmplen; + + tmpstr = estrdup(Z_STRVAL_PP(string)); + tmplen = Z_STRLEN_PP(string); + /* php_str_to_str uses a smart_str that allocates memory */ + /* this memory must be freed or passed on to rv */ + str = php_str_to_str(tmpstr, tmplen, "\\", 1, "\\\\", 2, &len); + efree(tmpstr); + tmpstr=str; tmplen=len; + str = php_str_to_str(tmpstr, tmplen, "'", 1, "''", 2, &len); + efree(tmpstr); + + ZVAL_STRINGL(*rv, str, len, 0); + return 1; +} + /* * Local variables: * tab-width: 4 |
