mboeren         Tue Oct 29 09:08:40 2002 EDT

  Modified files:              
    /php4/ext/dbx       dbx.c dbx.h dbx_fbsql.c dbx_fbsql.h dbx_mssql.c 
                        dbx_mssql.h dbx_mysql.c dbx_mysql.h dbx_oci8.c 
                        dbx_oci8.h dbx_odbc.c dbx_odbc.h dbx_pgsql.c 
                        dbx_pgsql.h dbx_sybasect.c dbx_sybasect.h php_dbx.h 
  Log:
  Added dbx_escape_string function
  # tested on odbc, oci8 and mysql
  @Added dbx_escape_string function to dbx module. (Marc)
  
  
Index: php4/ext/dbx/dbx.c
diff -u php4/ext/dbx/dbx.c:1.40 php4/ext/dbx/dbx.c:1.41
--- php4/ext/dbx/dbx.c:1.40     Mon Oct 28 04:41:15 2002
+++ php4/ext/dbx/dbx.c  Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx.c,v 1.40 2002/10/28 09:41:15 mboeren Exp $ */
+/* $Id: dbx.c,v 1.41 2002/10/29 14:08:39 mboeren Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -30,7 +30,6 @@
 #include "php_ini.h"
 #include "php_dbx.h"
 #include "ext/standard/info.h"
-#include "ext/standard/php_string.h"
 
 /* defines for supported databases */
 #define DBX_UNKNOWN 0
@@ -137,6 +136,8 @@
        /* returns array[0..columncount-1] as strings on success or 0 as long on 
failure */
 int switch_dbx_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS, zval 
**dbx_module);
        /* returns string */
+int switch_dbx_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module);
+       /* returns escaped string */
 
 /* Every user visible function must have an entry in dbx_functions[].
 */
@@ -145,6 +146,7 @@
        ZEND_FE(dbx_close,              NULL)
        ZEND_FE(dbx_query,              NULL)
        ZEND_FE(dbx_error,              NULL)
+       ZEND_FE(dbx_escape_string,      NULL)
 
        ZEND_FE(dbx_sort,               NULL)
        ZEND_FE(dbx_compare,    NULL)
@@ -168,15 +170,15 @@
 #ifdef COMPILE_DL_DBX
 ZEND_GET_MODULE(dbx)
 #endif
-
-ZEND_INI_BEGIN()
-    ZEND_INI_ENTRY("dbx.colnames_case", "unchanged", ZEND_INI_SYSTEM, NULL)
-ZEND_INI_END()
+
+ZEND_INI_BEGIN()
+    ZEND_INI_ENTRY("dbx.colnames_case", "unchanged", ZEND_INI_SYSTEM, NULL)
+ZEND_INI_END()
 
 ZEND_MINIT_FUNCTION(dbx)
 {
-    REGISTER_INI_ENTRIES();
-
+    REGISTER_INI_ENTRIES();
+
        REGISTER_LONG_CONSTANT("DBX_MYSQL", DBX_MYSQL, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DBX_ODBC", DBX_ODBC, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DBX_PGSQL", DBX_PGSQL, CONST_CS | CONST_PERSISTENT);
@@ -190,10 +192,10 @@
        REGISTER_LONG_CONSTANT("DBX_RESULT_INFO", DBX_RESULT_INFO, CONST_CS | 
CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DBX_RESULT_INDEX", DBX_RESULT_INDEX, CONST_CS | 
CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DBX_RESULT_ASSOC", DBX_RESULT_ASSOC, CONST_CS | 
CONST_PERSISTENT);
-
-       REGISTER_LONG_CONSTANT("DBX_COLNAMES_UNCHANGED", DBX_COLNAMES_UNCHANGED, 
CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("DBX_COLNAMES_UPPERCASE", DBX_COLNAMES_UPPERCASE, 
CONST_CS | CONST_PERSISTENT);
-       REGISTER_LONG_CONSTANT("DBX_COLNAMES_LOWERCASE", DBX_COLNAMES_LOWERCASE, 
CONST_CS | CONST_PERSISTENT);
+
+       REGISTER_LONG_CONSTANT("DBX_COLNAMES_UNCHANGED", DBX_COLNAMES_UNCHANGED, 
+CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("DBX_COLNAMES_UPPERCASE", DBX_COLNAMES_UPPERCASE, 
+CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("DBX_COLNAMES_LOWERCASE", DBX_COLNAMES_LOWERCASE, 
+CONST_CS | CONST_PERSISTENT);
 
        REGISTER_LONG_CONSTANT("DBX_CMP_NATIVE", DBX_CMP_NATIVE, CONST_CS | 
CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DBX_CMP_TEXT", DBX_CMP_TEXT, CONST_CS | 
CONST_PERSISTENT);
@@ -206,7 +208,7 @@
 
 ZEND_MSHUTDOWN_FUNCTION(dbx)
 {
-    UNREGISTER_INI_ENTRIES();
+    UNREGISTER_INI_ENTRIES();
        return SUCCESS;
 }
 
@@ -227,7 +229,7 @@
        php_info_print_table_row(2, "dbx version", "1.0.0");
        php_info_print_table_row(2, "supported databases", 
"MySQL\nODBC\nPostgreSQL\nMicrosoft SQL Server\nFrontBase\nOracle 8 
(oci8)\nSybase-CT");
        php_info_print_table_end();
-    DISPLAY_INI_ENTRIES();
+    DISPLAY_INI_ENTRIES();
 }
 
 /*
@@ -366,20 +368,20 @@
        long col_index;
        long row_count;
        zval *info;
-       long query_flags;
-       long result_flags;
+       long query_flags;
+       long result_flags;
        zval *data;
        zval **row_ptr;
-       zval **inforow_ptr;
-       /* default values for colname-case */
-       char * colnames_case = INI_STR("dbx.colnames_case");
-       long colcase = DBX_COLNAMES_UNCHANGED;
-       if (!strcmp(colnames_case, "uppercase")) {
-               colcase = DBX_COLNAMES_UPPERCASE;
-       }
-       if (!strcmp(colnames_case, "lowercase")) {
-               colcase = DBX_COLNAMES_LOWERCASE;
-       }
+       zval **inforow_ptr;
+       /* default values for colname-case */
+       char * colnames_case = INI_STR("dbx.colnames_case");
+       long colcase = DBX_COLNAMES_UNCHANGED;
+       if (!strcmp(colnames_case, "uppercase")) {
+               colcase = DBX_COLNAMES_UPPERCASE;
+       }
+       if (!strcmp(colnames_case, "lowercase")) {
+               colcase = DBX_COLNAMES_LOWERCASE;
+       }
 
        if (ZEND_NUM_ARGS()<min_number_of_arguments || 
ZEND_NUM_ARGS()>number_of_arguments || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), 
arguments) == FAILURE) {
                WRONG_PARAM_COUNT;
@@ -394,22 +396,22 @@
        if (ZEND_NUM_ARGS()>2) {
                convert_to_long_ex(arguments[2]);
                query_flags = Z_LVAL_PP(arguments[2]);
-               /* fieldnames are needed for association! */
-               result_flags = (query_flags & DBX_RESULT_INFO) | (query_flags & 
DBX_RESULT_INDEX) | (query_flags & DBX_RESULT_ASSOC);
+               /* fieldnames are needed for association! */
+               result_flags = (query_flags & DBX_RESULT_INFO) | (query_flags & 
+DBX_RESULT_INDEX) | (query_flags & DBX_RESULT_ASSOC);
                if (result_flags & DBX_RESULT_ASSOC) {
                        result_flags |= DBX_RESULT_INFO;
-               }
-               if (!result_flags) result_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | 
DBX_RESULT_ASSOC;
+               }
+               if (!result_flags) result_flags = DBX_RESULT_INFO | DBX_RESULT_INDEX | 
+DBX_RESULT_ASSOC;
                /* override ini-setting for colcase */
-               if (query_flags & DBX_COLNAMES_UNCHANGED) {
-                       colcase = DBX_COLNAMES_UNCHANGED;
-               }
-               if (query_flags & DBX_COLNAMES_UPPERCASE) {
-                       colcase = DBX_COLNAMES_UPPERCASE;
-               }
-               if (query_flags & DBX_COLNAMES_LOWERCASE) {
-                       colcase = DBX_COLNAMES_LOWERCASE;
-               }
+               if (query_flags & DBX_COLNAMES_UNCHANGED) {
+                       colcase = DBX_COLNAMES_UNCHANGED;
+               }
+               if (query_flags & DBX_COLNAMES_UPPERCASE) {
+                       colcase = DBX_COLNAMES_UPPERCASE;
+               }
+               if (query_flags & DBX_COLNAMES_LOWERCASE) {
+                       colcase = DBX_COLNAMES_LOWERCASE;
+               }
        }
        MAKE_STD_ZVAL(rv_result_handle); 
        ZVAL_LONG(rv_result_handle, 0);
@@ -484,14 +486,14 @@
                        /* get name */
                        MAKE_STD_ZVAL(rv_column_name);
                        ZVAL_LONG(rv_column_name, 0);
-                       result = switch_dbx_getcolumnname(&rv_column_name, 
&rv_result_handle, col_index, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
-                       /* modify case if requested */
+                       result = switch_dbx_getcolumnname(&rv_column_name, 
+&rv_result_handle, col_index, INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
+                       /* modify case if requested */
                        if (colcase==DBX_COLNAMES_UPPERCASE) {
-                               php_strtoupper(Z_STRVAL_P(rv_column_name), 
Z_STRLEN_P(rv_column_name));
-                               }
-                       if (colcase==DBX_COLNAMES_LOWERCASE) {
-                               php_strtolower(Z_STRVAL_P(rv_column_name), 
Z_STRLEN_P(rv_column_name));
-                               }
+                               php_strtoupper(Z_STRVAL_P(rv_column_name), 
+Z_STRLEN_P(rv_column_name));
+                               }
+                       if (colcase==DBX_COLNAMES_LOWERCASE) {
+                               php_strtolower(Z_STRVAL_P(rv_column_name), 
+Z_STRLEN_P(rv_column_name));
+                               }
                        if (result) { 
                                zend_hash_index_update(Z_ARRVAL_P(info_row_name), 
col_index, (void *)&(rv_column_name), sizeof(zval *), NULL);
                        } else {
@@ -574,6 +576,40 @@
 }
 /* }}} */
 
+/* {{{ proto string dbx_esc(dbx_link_object dbx_link, string sz)
+   Returns escaped string or NULL on error
+*/
+ZEND_FUNCTION(dbx_escape_string)
+{
+       int number_of_arguments=2;
+       zval **arguments[2];
+
+       int result;
+       zval **dbx_handle;
+       zval **dbx_module;
+       zval **dbx_database;
+       zval *rv;
+
+       if (ZEND_NUM_ARGS() !=number_of_arguments || 
+zend_get_parameters_array_ex(number_of_arguments, arguments) == FAILURE) {
+               WRONG_PARAM_COUNT;
+       }
+       if (!split_dbx_handle_object(arguments[0], &dbx_handle, &dbx_module, 
+&dbx_database)) {
+               zend_error(E_WARNING, "dbx_esc: not a valid dbx_handle-object...");
+               RETURN_NULL();
+       }
+       convert_to_string_ex(arguments[1]);
+
+       MAKE_STD_ZVAL(rv); 
+       ZVAL_LONG(rv, 0);
+       result = switch_dbx_esc(&rv, dbx_handle, arguments[1], 
+INTERNAL_FUNCTION_PARAM_PASSTHRU, dbx_module);
+       if (!result) { /* this will probably never happen */
+               FREE_ZVAL(rv);
+               RETURN_NULL();
+       }
+       MOVE_RETURNED_TO_RV(&return_value, rv);
+}
+/* }}} */
+
 /*
  *      dbx functions that are database independent... like sorting result_objects!
  */
@@ -847,6 +883,22 @@
                case DBX_SYBASECT: return dbx_sybasect_error(rv, dbx_handle, 
INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        zend_error(E_WARNING, "dbx_error: not supported in this module");
+       return 0;
+}
+
+int switch_dbx_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS, zval **dbx_module)
+{
+       /* returns escaped string */
+       switch (Z_LVAL_PP(dbx_module)) {
+               case DBX_MYSQL: return dbx_mysql_esc(rv, dbx_handle, string, 
+INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_ODBC:  return dbx_odbc_esc(rv, dbx_handle, string, 
+INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_PGSQL: return dbx_pgsql_esc(rv, dbx_handle, string, 
+INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_MSSQL: return dbx_mssql_esc(rv, dbx_handle, string, 
+INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_FBSQL: return dbx_fbsql_esc(rv, dbx_handle, string, 
+INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_OCI8:  return dbx_oci8_esc(rv, dbx_handle, string, 
+INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SYBASECT: return dbx_sybasect_esc(rv, dbx_handle, string, 
+INTERNAL_FUNCTION_PARAM_PASSTHRU);
+       }
+       zend_error(E_WARNING, "dbx_esc: not supported in this module");
        return 0;
 }
 
Index: php4/ext/dbx/dbx.h
diff -u php4/ext/dbx/dbx.h:1.10 php4/ext/dbx/dbx.h:1.11
--- php4/ext/dbx/dbx.h:1.10     Mon Oct 28 04:41:15 2002
+++ php4/ext/dbx/dbx.h  Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx.h,v 1.10 2002/10/28 09:41:15 mboeren Exp $ */
+/* $Id: dbx.h,v 1.11 2002/10/29 14:08:39 mboeren Exp $ */
 
 #ifndef ZEND_DBX_H
 #define ZEND_DBX_H
@@ -30,15 +30,16 @@
 #endif
 
 #include "php.h"
+#include "ext/standard/php_string.h"
 
 #define DBX_PERSISTENT         (1<<0)
 
 #define DBX_RESULT_INFO        (1<<0)
 #define DBX_RESULT_INDEX       (1<<1)
 #define DBX_RESULT_ASSOC       (1<<2)
-#define DBX_COLNAMES_UNCHANGED (1<<3)
-#define DBX_COLNAMES_UPPERCASE (1<<4)
-#define DBX_COLNAMES_LOWERCASE (1<<5)
+#define DBX_COLNAMES_UNCHANGED (1<<3)
+#define DBX_COLNAMES_UPPERCASE (1<<4)
+#define DBX_COLNAMES_LOWERCASE (1<<5)
 
 #define DBX_CMP_NATIVE         (1<<0)
 #define DBX_CMP_TEXT           (1<<1)
Index: php4/ext/dbx/dbx_fbsql.c
diff -u php4/ext/dbx/dbx_fbsql.c:1.6 php4/ext/dbx/dbx_fbsql.c:1.7
--- php4/ext/dbx/dbx_fbsql.c:1.6        Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/dbx_fbsql.c    Tue Oct 29 09:08:39 2002
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_fbsql.c,v 1.6 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: dbx_fbsql.c,v 1.7 2002/10/29 14:08:39 mboeren Exp $ */
 
 #include "dbx.h"
 #include "dbx_fbsql.h"
@@ -246,6 +246,28 @@
                return 0;
        }
        MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_fbsql_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);
+
+       ZVAL_STRINGL(*rv, str, len, 0);
+
        return 1;
 }
 
Index: php4/ext/dbx/dbx_fbsql.h
diff -u php4/ext/dbx/dbx_fbsql.h:1.5 php4/ext/dbx/dbx_fbsql.h:1.6
--- php4/ext/dbx/dbx_fbsql.h:1.5        Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/dbx_fbsql.h    Tue Oct 29 09:08:39 2002
@@ -21,7 +21,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_fbsql.h,v 1.5 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: dbx_fbsql.h,v 1.6 2002/10/29 14:08:39 mboeren Exp $ */
 
 #ifndef ZEND_DBX_FBSQL_H
 #define ZEND_DBX_FBSQL_H
@@ -50,6 +50,8 @@
        /* returns array[0..columncount-1] as strings on success or 0 as long on 
failure */
 int dbx_fbsql_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
        /* returns string */
+int dbx_fbsql_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS);
+       /* returns escaped string */
 
 #endif /* ZEND_DBX_FBSQL_H */
 
Index: php4/ext/dbx/dbx_mssql.c
diff -u php4/ext/dbx/dbx_mssql.c:1.9 php4/ext/dbx/dbx_mssql.c:1.10
--- php4/ext/dbx/dbx_mssql.c:1.9        Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/dbx_mssql.c    Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_mssql.c,v 1.9 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: dbx_mssql.c,v 1.10 2002/10/29 14:08:39 mboeren Exp $ */
 
 #include "dbx.h"
 #include "dbx_mssql.h"
@@ -246,6 +246,27 @@
                return 0;
        }
        MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_mssql_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns escaped string */
+       /* replace ' 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);
+
+       ZVAL_STRINGL(*rv, str, len, 0);
+
        return 1;
 }
 
Index: php4/ext/dbx/dbx_mssql.h
diff -u php4/ext/dbx/dbx_mssql.h:1.7 php4/ext/dbx/dbx_mssql.h:1.8
--- php4/ext/dbx/dbx_mssql.h:1.7        Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/dbx_mssql.h    Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_mssql.h,v 1.7 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: dbx_mssql.h,v 1.8 2002/10/29 14:08:39 mboeren Exp $ */
 
 #ifndef ZEND_DBX_MSSQL_H
 #define ZEND_DBX_MSSQL_H
@@ -49,6 +49,8 @@
        /* returns array[0..columncount-1] as strings on success or 0 as long on 
failure */
 int dbx_mssql_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
        /* returns string */
+int dbx_mssql_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS);
+       /* returns escaped string */
 
 #endif /* ZEND_DBX_MSSQL_H */
 
Index: php4/ext/dbx/dbx_mysql.c
diff -u php4/ext/dbx/dbx_mysql.c:1.14 php4/ext/dbx/dbx_mysql.c:1.15
--- php4/ext/dbx/dbx_mysql.c:1.14       Wed Jan 16 11:28:50 2002
+++ php4/ext/dbx/dbx_mysql.c    Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_mysql.c,v 1.14 2002/01/16 16:28:50 mboeren Exp $ */
+/* $Id: dbx_mysql.c,v 1.15 2002/10/29 14:08:39 mboeren Exp $ */
 
 #include "dbx.h"
 #include "dbx_mysql.h"
@@ -250,6 +250,43 @@
        if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_STRING) {
                if (returned_zval) zval_ptr_dtor(&returned_zval);
                return 0;
+       }
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_mysql_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns escaped string */
+       int number_of_arguments=2;
+       zval **arguments[2];
+       zval *returned_zval=NULL;
+       char * str;
+       int len;
+       char * tmpstr;
+       int tmplen;
+
+       arguments[0]=string;
+       arguments[1]=dbx_handle;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, 
+"mysql_real_escape_string", &returned_zval, number_of_arguments, arguments);
+       if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_STRING) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               /* mysql_real_escape_string failed, just do my own escaping then */
+               /* replace \ with \\ */
+               /*         ' with '' */
+
+               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;
        }
        MOVE_RETURNED_TO_RV(rv, returned_zval);
        return 1;
Index: php4/ext/dbx/dbx_mysql.h
diff -u php4/ext/dbx/dbx_mysql.h:1.11 php4/ext/dbx/dbx_mysql.h:1.12
--- php4/ext/dbx/dbx_mysql.h:1.11       Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/dbx_mysql.h    Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_mysql.h,v 1.11 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: dbx_mysql.h,v 1.12 2002/10/29 14:08:39 mboeren Exp $ */
 
 #ifndef ZEND_DBX_MYSQL_H
 #define ZEND_DBX_MYSQL_H
@@ -49,6 +49,8 @@
        /* returns array[0..columncount-1] as strings on success or 0 as long on 
failure */
 int dbx_mysql_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
        /* returns string */
+int dbx_mysql_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS);
+       /* returns escaped string */
 
 #endif /* ZEND_DBX_MYSQL_H */
 
Index: php4/ext/dbx/dbx_oci8.c
diff -u php4/ext/dbx/dbx_oci8.c:1.9 php4/ext/dbx/dbx_oci8.c:1.10
--- php4/ext/dbx/dbx_oci8.c:1.9 Mon Oct 28 04:41:15 2002
+++ php4/ext/dbx/dbx_oci8.c     Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_oci8.c,v 1.9 2002/10/28 09:41:15 mboeren Exp $ */
+/* $Id: dbx_oci8.c,v 1.10 2002/10/29 14:08:39 mboeren Exp $ */
 
 #include "dbx.h"
 #include "dbx_oci8.h"
@@ -264,6 +264,27 @@
        }
        MOVE_RETURNED_TO_RV(rv, returned_message_zval);
        zval_ptr_dtor(&returned_zval);
+       return 1;
+}
+
+int dbx_oci8_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns escaped string */
+       /* replace ' 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);
+
+       ZVAL_STRINGL(*rv, str, len, 0);
+
        return 1;
 }
 
Index: php4/ext/dbx/dbx_oci8.h
diff -u php4/ext/dbx/dbx_oci8.h:1.4 php4/ext/dbx/dbx_oci8.h:1.5
--- php4/ext/dbx/dbx_oci8.h:1.4 Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/dbx_oci8.h     Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_oci8.h,v 1.4 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: dbx_oci8.h,v 1.5 2002/10/29 14:08:39 mboeren Exp $ */
 
 #ifndef ZEND_DBX_OCI8_H
 #define ZEND_DBX_OCI8_H
@@ -49,6 +49,8 @@
        /* returns array[0..columncount-1] as strings on success or 0 as long on 
failure */
 int dbx_oci8_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
        /* returns string */
+int dbx_oci8_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS);
+       /* returns escaped string */
 
 #endif /* ZEND_DBX_OCI8_H */
 
Index: php4/ext/dbx/dbx_odbc.c
diff -u php4/ext/dbx/dbx_odbc.c:1.16 php4/ext/dbx/dbx_odbc.c:1.17
--- php4/ext/dbx/dbx_odbc.c:1.16        Thu Oct 24 15:07:08 2002
+++ php4/ext/dbx/dbx_odbc.c     Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_odbc.c,v 1.16 2002/10/24 19:07:08 helly Exp $ */
+/* $Id: dbx_odbc.c,v 1.17 2002/10/29 14:08:39 mboeren Exp $ */
 
 #include "dbx.h"
 #include "dbx_odbc.h"
@@ -269,6 +269,27 @@
                return 0;
        }
        MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_odbc_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns escaped string */
+       /* replace ' 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);
+
+       ZVAL_STRINGL(*rv, str, len, 0);
+
        return 1;
 }
 
Index: php4/ext/dbx/dbx_odbc.h
diff -u php4/ext/dbx/dbx_odbc.h:1.11 php4/ext/dbx/dbx_odbc.h:1.12
--- php4/ext/dbx/dbx_odbc.h:1.11        Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/dbx_odbc.h     Tue Oct 29 09:08:39 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_odbc.h,v 1.11 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: dbx_odbc.h,v 1.12 2002/10/29 14:08:39 mboeren Exp $ */
 
 #ifndef ZEND_DBX_ODBC_H
 #define ZEND_DBX_ODBC_H
@@ -49,6 +49,8 @@
        /* returns array[0..columncount-1] as strings on success or 0 as long on 
failure */
 int dbx_odbc_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
        /* returns string */
+int dbx_odbc_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS);
+       /* returns escaped string */
 
 #endif /* ZEND_DBX_ODBC_H */
 
Index: php4/ext/dbx/dbx_pgsql.c
diff -u php4/ext/dbx/dbx_pgsql.c:1.17 php4/ext/dbx/dbx_pgsql.c:1.18
--- php4/ext/dbx/dbx_pgsql.c:1.17       Wed Feb 13 08:11:36 2002
+++ php4/ext/dbx/dbx_pgsql.c    Tue Oct 29 09:08:40 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dbx_pgsql.c,v 1.17 2002/02/13 13:11:36 yohgaki Exp $ */
+/* $Id: dbx_pgsql.c,v 1.18 2002/10/29 14:08:40 mboeren Exp $ */
 
 #include "dbx.h"
 #include "php_dbx.h"
@@ -272,6 +272,30 @@
                return 0;
        }
        MOVE_RETURNED_TO_RV(rv, returned_zval);
+       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;
 }
 
Index: php4/ext/dbx/dbx_pgsql.h
diff -u php4/ext/dbx/dbx_pgsql.h:1.10 php4/ext/dbx/dbx_pgsql.h:1.11
--- php4/ext/dbx/dbx_pgsql.h:1.10       Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/dbx_pgsql.h    Tue Oct 29 09:08:40 2002
@@ -16,7 +16,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: dbx_pgsql.h,v 1.10 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: dbx_pgsql.h,v 1.11 2002/10/29 14:08:40 mboeren Exp $ */
 
 #ifndef ZEND_DBX_PGSQL_H
 #define ZEND_DBX_PGSQL_H
@@ -45,6 +45,8 @@
        /* returns array[0..columncount-1] as strings on success or 0 as long on 
failure */
 int dbx_pgsql_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
        /* returns string */
+int dbx_pgsql_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS);
+       /* returns escaped string */
 
 #endif /* ZEND_DBX_PGSQL_H */
 
Index: php4/ext/dbx/dbx_sybasect.c
diff -u php4/ext/dbx/dbx_sybasect.c:1.3 php4/ext/dbx/dbx_sybasect.c:1.4
--- php4/ext/dbx/dbx_sybasect.c:1.3     Tue Jun 18 03:48:41 2002
+++ php4/ext/dbx/dbx_sybasect.c Tue Oct 29 09:08:40 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_sybasect.c,v 1.3 2002/06/18 07:48:41 mfischer Exp $ */
+/* $Id: dbx_sybasect.c,v 1.4 2002/10/29 14:08:40 mboeren Exp $ */
 
 #include "dbx.h"
 #include "dbx_sybasect.h"
@@ -271,6 +271,27 @@
                return 0;
        }
        MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sybasect_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns escaped string */
+       /* replace ' 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);
+
+       ZVAL_STRINGL(*rv, str, len, 0);
+
        return 1;
 }
 
Index: php4/ext/dbx/dbx_sybasect.h
diff -u php4/ext/dbx/dbx_sybasect.h:1.2 php4/ext/dbx/dbx_sybasect.h:1.3
--- php4/ext/dbx/dbx_sybasect.h:1.2     Mon Feb 18 05:22:09 2002
+++ php4/ext/dbx/dbx_sybasect.h Tue Oct 29 09:08:40 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx_sybasect.h,v 1.2 2002/02/18 10:22:09 mboeren Exp $ */
+/* $Id: dbx_sybasect.h,v 1.3 2002/10/29 14:08:40 mboeren Exp $ */
 
 #ifndef ZEND_DBX_SYBASECT_H
 #define ZEND_DBX_SYBASECT_H
@@ -49,6 +49,8 @@
        /* returns array[0..columncount-1] as strings on success or 0 as long on 
failure */
 int dbx_sybasect_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
        /* returns string */
+int dbx_sybasect_esc(zval **rv, zval **dbx_handle, zval **string, 
+INTERNAL_FUNCTION_PARAMETERS);
+       /* returns escaped string */
 
 #endif /* ZEND_DBX_SYBASECT_H */
 
Index: php4/ext/dbx/php_dbx.h
diff -u php4/ext/dbx/php_dbx.h:1.12 php4/ext/dbx/php_dbx.h:1.13
--- php4/ext/dbx/php_dbx.h:1.12 Tue Dec 11 10:29:05 2001
+++ php4/ext/dbx/php_dbx.h      Tue Oct 29 09:08:40 2002
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: php_dbx.h,v 1.12 2001/12/11 15:29:05 sebastian Exp $ */
+/* $Id: php_dbx.h,v 1.13 2002/10/29 14:08:40 mboeren Exp $ */
 
 #ifndef ZEND_PHP_DBX_H
 #define ZEND_PHP_DBX_H
@@ -49,6 +49,7 @@
 ZEND_FUNCTION(dbx_close);
 ZEND_FUNCTION(dbx_query);
 ZEND_FUNCTION(dbx_error);
+ZEND_FUNCTION(dbx_escape_string);
 
 ZEND_FUNCTION(dbx_sort);
 ZEND_FUNCTION(dbx_compare);

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to