]> granicus.if.org Git - php/commitdiff
Add SQLite support to DBX (Marc).
authorMarc Boeren <mboeren@php.net>
Wed, 9 Jul 2003 16:31:40 +0000 (16:31 +0000)
committerMarc Boeren <mboeren@php.net>
Wed, 9 Jul 2003 16:31:40 +0000 (16:31 +0000)
@Add SQLite support to DBX (Marc).

ext/dbx/config.m4
ext/dbx/dbx.c
ext/dbx/dbx.dsp
ext/dbx/dbx_sqlite.c [new file with mode: 0644]
ext/dbx/dbx_sqlite.h [new file with mode: 0644]
ext/dbx/tests/002.phpt
ext/dbx/tests/003.phpt
ext/dbx/tests/004.phpt
ext/dbx/tests/006.phpt
ext/dbx/tests/dbx_test.p

index 8c5dc11ba8d9a0da9cacefefd8d9b1eb5996b110..de6e857249d2b118c4b420bd034c888640d398ac 100644 (file)
@@ -6,5 +6,5 @@ PHP_ARG_ENABLE(dbx,whether to enable dbx support,
 [  --enable-dbx            Enable dbx])
 
 if test "$PHP_DBX" != "no"; then
-  PHP_NEW_EXTENSION(dbx, dbx.c dbx_mysql.c dbx_odbc.c dbx_pgsql.c dbx_mssql.c dbx_fbsql.c dbx_oci8.c dbx_sybasect.c, $ext_shared)
+  PHP_NEW_EXTENSION(dbx, dbx.c dbx_mysql.c dbx_odbc.c dbx_pgsql.c dbx_mssql.c dbx_fbsql.c dbx_oci8.c dbx_sybasect.c dbx_sqlite.c, $ext_shared)
 fi
index 0b0d4d83d9d4a30afa1676e9293c334b6553ac15..d15bbe045b1aca25655d2f979e8181f66ba02dbf 100644 (file)
@@ -40,6 +40,7 @@
 #define DBX_FBSQL 5
 #define DBX_OCI8 6
 #define DBX_SYBASECT 7
+#define DBX_SQLITE 8
 /* includes for supported databases */
 #include "dbx.h"
 #include "dbx_mysql.h"
@@ -49,6 +50,7 @@
 #include "dbx_fbsql.h"
 #include "dbx_oci8.h"
 #include "dbx_sybasect.h"
+#include "dbx_sqlite.h"
 
 /* support routines */
 int module_exists(char *module_name)
@@ -69,6 +71,7 @@ int module_identifier_exists(long module_identifier)
                case DBX_FBSQL: return module_exists("fbsql");
                case DBX_OCI8: return module_exists("oci8");
                case DBX_SYBASECT: return module_exists("sybase_ct");
+               case DBX_SQLITE: return module_exists("sqlite");
        }
        return 0;
 }
@@ -82,6 +85,7 @@ int get_module_identifier(char *module_name)
        if (!strcmp("fbsql", module_name)) return DBX_FBSQL;
        if (!strcmp("oci8", module_name)) return DBX_OCI8;
        if (!strcmp("sybase_ct", module_name)) return DBX_SYBASECT;
+       if (!strcmp("sqlite", module_name)) return DBX_SQLITE;
        return DBX_UNKNOWN;
 }
 
@@ -186,6 +190,7 @@ ZEND_MINIT_FUNCTION(dbx)
        REGISTER_LONG_CONSTANT("DBX_FBSQL", DBX_FBSQL, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DBX_OCI8", DBX_OCI8, CONST_CS | CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("DBX_SYBASECT", DBX_SYBASECT, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("DBX_SQLITE", DBX_SQLITE, CONST_CS | CONST_PERSISTENT);
 
        REGISTER_LONG_CONSTANT("DBX_PERSISTENT", DBX_PERSISTENT, CONST_CS | CONST_PERSISTENT);
 
@@ -226,8 +231,8 @@ ZEND_MINFO_FUNCTION(dbx)
 {
        php_info_print_table_start();
        php_info_print_table_row(2, "dbx support", "enabled");
-       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_row(2, "dbx version", "1.0.1");
+       php_info_print_table_row(2, "supported databases", "MySQL\nODBC\nPostgreSQL\nMicrosoft SQL Server\nFrontBase\nOracle 8 (oci8)\nSybase-CT\nSQLite");
        php_info_print_table_end();
     DISPLAY_INI_ENTRIES();
 }
@@ -725,6 +730,7 @@ int switch_dbx_connect(zval **rv, zval **host, zval **db, zval **username, zval
                case DBX_FBSQL: return dbx_fbsql_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_OCI8:  return dbx_oci8_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_SYBASECT: return dbx_sybasect_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_connect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -741,6 +747,7 @@ int switch_dbx_pconnect(zval **rv, zval **host, zval **db, zval **username, zval
                case DBX_FBSQL: return dbx_fbsql_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_OCI8:  return dbx_oci8_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_SYBASECT: return dbx_sybasect_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_pconnect(rv, host, db, username, password, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -757,6 +764,7 @@ int switch_dbx_close(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS,
                case DBX_FBSQL: return dbx_fbsql_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_OCI8:  return dbx_oci8_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_SYBASECT: return dbx_sybasect_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_close(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -773,6 +781,7 @@ int switch_dbx_query(zval **rv, zval **dbx_handle, zval **db_name, zval **sql_st
                case DBX_FBSQL: return dbx_fbsql_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_OCI8:  return dbx_oci8_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_SYBASECT: return dbx_sybasect_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_query(rv, dbx_handle, db_name, sql_statement, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -789,6 +798,7 @@ int switch_dbx_getcolumncount(zval **rv, zval **result_handle, INTERNAL_FUNCTION
                case DBX_FBSQL: return dbx_fbsql_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_OCI8:  return dbx_oci8_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_SYBASECT: return dbx_sybasect_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_getcolumncount(rv, result_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -805,6 +815,7 @@ int switch_dbx_getcolumnname(zval **rv, zval **result_handle, long column_index,
                case DBX_FBSQL: return dbx_fbsql_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_OCI8:  return dbx_oci8_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_SYBASECT: return dbx_sybasect_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_getcolumnname(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -821,6 +832,7 @@ int switch_dbx_getcolumntype(zval **rv, zval **result_handle, long column_index,
                case DBX_FBSQL: return dbx_fbsql_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_OCI8:  return dbx_oci8_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_SYBASECT: return dbx_sybasect_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_getcolumntype(rv, result_handle, column_index, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -837,6 +849,7 @@ int switch_dbx_getrow(zval **rv, zval **result_handle, long row_number, INTERNAL
                case DBX_FBSQL: return dbx_fbsql_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_OCI8:  return dbx_oci8_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                case DBX_SYBASECT: return dbx_sybasect_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_getrow(rv, result_handle, row_number, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -853,6 +866,7 @@ int switch_dbx_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS,
                case DBX_FBSQL: return dbx_fbsql_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
                /* case DBX_OCI8:  return dbx_oci8_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU); */
                case DBX_SYBASECT: return dbx_sybasect_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
+               case DBX_SQLITE: return dbx_sqlite_error(rv, dbx_handle, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
@@ -869,6 +883,7 @@ int switch_dbx_esc(zval **rv, zval **dbx_handle, zval **string, INTERNAL_FUNCTIO
                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);
+               case DBX_SQLITE: return dbx_sqlite_esc(rv, dbx_handle, string, INTERNAL_FUNCTION_PARAM_PASSTHRU);
        }
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "not supported in this module");
        return 0;
index d4f59514900ec285b80ef7a82dae5034d9da3fc9..8d86a656338dc9fa876a3bdbec2b80b31c8c849b 100644 (file)
@@ -122,6 +122,10 @@ SOURCE=.\dbx_pgsql.c
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\dbx_sqlite.c\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\dbx_sybasect.c\r
 # End Source File\r
 # End Group\r
@@ -158,6 +162,10 @@ SOURCE=.\dbx_pgsql.h
 # End Source File\r
 # Begin Source File\r
 \r
+SOURCE=.\dbx_sqlite.h\r
+# End Source File\r
+# Begin Source File\r
+\r
 SOURCE=.\dbx_sybasect.h\r
 # End Source File\r
 # Begin Source File\r
diff --git a/ext/dbx/dbx_sqlite.c b/ext/dbx/dbx_sqlite.c
new file mode 100644 (file)
index 0000000..c90bc63
--- /dev/null
@@ -0,0 +1,273 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 4                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2003 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | dbx module version 1.0                                               |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 2001 Guidance Rotterdam BV                             |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.0 of the PHP license,       |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_0.txt.                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Author : Marc Boeren         <marc@guidance.nl>                      |
+   +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#include "dbx.h"
+#include "dbx_sqlite.h"
+
+#define SQLITE_ASSOC 1
+#define SQLITE_NUM   2
+#define SQLITE_BOTH  3
+
+int dbx_sqlite_connect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns connection handle as resource on success or 0 as long on failure */
+       int number_of_arguments=1;
+       zval **arguments[1];
+       zval *returned_zval=NULL;
+
+       arguments[0]=db;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_open", &returned_zval, number_of_arguments, arguments);
+       if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_RESOURCE) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               return 0;
+       }
+
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sqlite_pconnect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns persistent connection handle as resource on success or 0 as long on failure */
+       int number_of_arguments=1;
+       zval **arguments[1];
+       zval *returned_zval=NULL;
+
+       arguments[0]=db;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_popen", &returned_zval, number_of_arguments, arguments);
+       if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_RESOURCE) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               return 0;
+       }
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sqlite_close(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns 1 as long on success or 0 as long on failure */
+       int number_of_arguments=1;
+       zval **arguments[1];
+       zval *returned_zval=NULL;
+
+       arguments[0]=dbx_handle;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_close", &returned_zval, number_of_arguments, arguments);
+       if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_BOOL) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               return 0;
+       }
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sqlite_query(zval **rv, zval **dbx_handle, zval **db_name, zval **sql_statement, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns 1 as long or a result identifier as resource on success  or 0 as long on failure */
+       int number_of_arguments=2;
+       zval **arguments[2];
+       zval *returned_zval=NULL;
+
+       number_of_arguments=2;
+       arguments[0]=dbx_handle;
+       arguments[1]=sql_statement;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_query", &returned_zval, number_of_arguments, arguments);
+       /* sqlite_query returns a bool for success or failure, or a result_identifier for select statements */
+       if (!returned_zval || (Z_TYPE_P(returned_zval)!=IS_BOOL && Z_TYPE_P(returned_zval)!=IS_RESOURCE)) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               return 0;
+       }
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sqlite_getcolumncount(zval **rv, zval **result_handle, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns column-count as long on success or 0 as long on failure */
+       int number_of_arguments=1;
+       zval **arguments[1];
+       zval *returned_zval=NULL;
+
+       arguments[0]=result_handle;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_num_fields", &returned_zval, number_of_arguments, arguments);
+       if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_LONG) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               return 0;
+       }
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sqlite_getcolumnname(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns column-name as string on success or 0 as long on failure */
+       int number_of_arguments=2;
+       zval **arguments[2];
+       zval *zval_column_index;
+       zval *returned_zval=NULL;
+
+       MAKE_STD_ZVAL(zval_column_index);
+       ZVAL_LONG(zval_column_index, column_index);
+       arguments[0]=result_handle;
+       arguments[1]=&zval_column_index;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_field_name", &returned_zval, number_of_arguments, arguments);
+       /* sqlite_field_name returns a string */
+       if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_STRING) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               FREE_ZVAL(zval_column_index);
+               return 0;
+       }
+       FREE_ZVAL(zval_column_index);
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sqlite_getcolumntype(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns column-type as string on success or 0 as long on failure */
+       /*int number_of_arguments=2;
+       zval **arguments[2];
+       zval *zval_column_index;
+       */
+       zval *returned_zval=NULL;
+
+       /*
+       MAKE_STD_ZVAL(zval_column_index);
+       ZVAL_LONG(zval_column_index, column_index);
+       arguments[0]=result_handle;
+       arguments[1]=&zval_column_index;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_field_type", &returned_zval, number_of_arguments, arguments);
+       */
+       /* sqlite_field_type returns a string */
+       /*
+       if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_STRING) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               FREE_ZVAL(zval_column_index);
+               return 0;
+       }
+       FREE_ZVAL(zval_column_index);
+       */
+       MAKE_STD_ZVAL(returned_zval);
+       ZVAL_STRING(returned_zval, "string", 1); /* fake field type */
+
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sqlite_getrow(zval **rv, zval **result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns array[0..columncount-1] as strings on success or 0 as long on failure */
+       int number_of_arguments=2;
+       zval **arguments[2];
+       zval *zval_resulttype=NULL;
+       zval *returned_zval=NULL;
+
+       MAKE_STD_ZVAL(zval_resulttype);
+       ZVAL_LONG(zval_resulttype, SQLITE_NUM);
+       arguments[0]=result_handle;
+       arguments[1]=&zval_resulttype;
+       /* optional boolean third parameter 'decode_binary' skipped */
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_fetch_array", &returned_zval, number_of_arguments, arguments);
+       if (!returned_zval || Z_TYPE_P(returned_zval)!=IS_ARRAY) {
+               if (returned_zval) zval_ptr_dtor(&returned_zval);
+               FREE_ZVAL(zval_resulttype);
+               return 0;
+       }
+       FREE_ZVAL(zval_resulttype);
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+int dbx_sqlite_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns string */
+       int number_of_arguments=1;
+       zval **arguments[1];
+       zval *returned_zval_errcode=NULL;
+       zval *returned_zval=NULL;
+
+       arguments[0]=dbx_handle;
+       if (!dbx_handle) number_of_arguments=0;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_last_error", &returned_zval_errcode, number_of_arguments, arguments);
+       if (!returned_zval_errcode || Z_TYPE_P(returned_zval_errcode)!=IS_LONG) {
+               if (returned_zval_errcode) zval_ptr_dtor(&returned_zval_errcode);
+               return 0;
+       }
+       if (Z_LVAL_P(returned_zval_errcode) == 0) {
+               zval_ptr_dtor(&returned_zval_errcode);
+               ZVAL_EMPTY_STRING(*rv);
+               return 1;
+       }
+       arguments[0]=&returned_zval_errcode;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_error_string", &returned_zval, number_of_arguments, arguments);
+       zval_ptr_dtor(&returned_zval_errcode);
+       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_sqlite_esc(zval **rv, zval **dbx_handle, zval **string, INTERNAL_FUNCTION_PARAMETERS)
+{
+       /* returns escaped string */
+       int number_of_arguments=1;
+       zval **arguments[1];
+       zval *returned_zval=NULL;
+       char * str;
+       int len;
+       char * tmpstr;
+       int tmplen;
+
+       if (Z_STRLEN_PP(string) == 0) {
+               ZVAL_EMPTY_STRING(*rv);
+               return 1;
+       }
+       arguments[0]=string;
+       dbx_call_any_function(INTERNAL_FUNCTION_PARAM_PASSTHRU, "sqlite_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);
+               /* sqlite_escape_string failed, just do my own escaping then */
+               /* replace ' 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);
+
+               ZVAL_STRINGL(*rv, str, len, 0);
+               return 1;
+       }
+       MOVE_RETURNED_TO_RV(rv, returned_zval);
+       return 1;
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
diff --git a/ext/dbx/dbx_sqlite.h b/ext/dbx/dbx_sqlite.h
new file mode 100644 (file)
index 0000000..a5aa31e
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+   +----------------------------------------------------------------------+
+   | PHP Version 4                                                        |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 1997-2003 The PHP Group                                |
+   +----------------------------------------------------------------------+
+   | dbx module version 1.0                                               |
+   +----------------------------------------------------------------------+
+   | Copyright (c) 2001 Guidance Rotterdam BV                             |
+   +----------------------------------------------------------------------+
+   | This source file is subject to version 3.0 of the PHP license,       |
+   | that is bundled with this package in the file LICENSE, and is        |
+   | available through the world-wide-web at the following url:           |
+   | http://www.php.net/license/3_0.txt.                                  |
+   | If you did not receive a copy of the PHP license and are unable to   |
+   | obtain it through the world-wide-web, please send a note to          |
+   | license@php.net so we can mail you a copy immediately.               |
+   +----------------------------------------------------------------------+
+   | Author : Marc Boeren         <marc@guidance.nl>                      |
+   +----------------------------------------------------------------------+
+*/
+
+/* $Id$ */
+
+#ifndef ZEND_DBX_SQLITE_H
+#define ZEND_DBX_SQLITE_H
+
+#ifndef INIT_FUNC_ARGS
+#include "zend_modules.h"
+#endif
+
+#include "php.h"
+
+int dbx_sqlite_connect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns connection handle as resource on success or 0 as long on failure */
+int dbx_sqlite_pconnect(zval **rv, zval **host, zval **db, zval **username, zval **password, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns persistent connection handle as resource on success or 0 as long on failure */
+int dbx_sqlite_close(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns 1 as long on success or 0 as long on failure */
+int dbx_sqlite_query(zval **rv, zval **dbx_handle, zval **db_name, zval **sql_statement, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns 1 as long or a result identifier as resource on success  or 0 as long on failure */
+int dbx_sqlite_getcolumncount(zval **rv, zval **result_handle, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns column-count as long on success or 0 as long on failure */
+int dbx_sqlite_getcolumnname(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns column-name as string on success or 0 as long on failure */
+int dbx_sqlite_getcolumntype(zval **rv, zval **result_handle, long column_index, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns column-type as string on success or 0 as long on failure */
+int dbx_sqlite_getrow(zval **rv, zval **result_handle, long row_number, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns array[0..columncount-1] as strings on success or 0 as long on failure */
+int dbx_sqlite_error(zval **rv, zval **dbx_handle, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns string */
+int dbx_sqlite_esc(zval **rv, zval **dbx_handle, zval **string, INTERNAL_FUNCTION_PARAMETERS);
+       /* returns escaped string */
+
+#endif /* ZEND_DBX_SQLITE_H */
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ */
index cf51901cb91f5c61d77ca1052d36a2772876fe9b..f3ec8eeef3d7c66d9e6031ea5d01c9505da741c6 100644 (file)
@@ -11,6 +11,7 @@ if (DBX_MSSQL=="DBX_MSSQL")               print('!DBX_MSSQL');
 if (DBX_FBSQL=="DBX_FBSQL")               print('!DBX_FBSQL');
 if (DBX_OCI8=="DBX_OCI8")                 print('!DBX_OCI8');
 if (DBX_SYBASECT=="DBX_SYBASECT")         print('!DBX_SYBASECT');
+if (DBX_SQLITE=="DBX_SQLITE")             print('!DBX_SQLITE');
 if (DBX_PERSISTENT=="DBX_PERSISTENT")     print('!DBX_PERSISTENT');
 if (DBX_RESULT_INFO=="DBX_RESULT_INFO")   print('!DBX_RESULT_INFO');
 if (DBX_RESULT_INDEX=="DBX_RESULT_INDEX") print('!DBX_RESULT_INDEX');
index 76fda4caf27aea2518b1171c08a01e192802b4bc..01c05f6e8cd4b7c7b5b69b37769093ab0a942606 100644 (file)
@@ -20,39 +20,62 @@ if ($dlo!=0) {
        print('connect using constant ok'."\n");
        dbx_close($dlo);
        }
-$dlo = @dbx_connect($module, $host, $nonexisting_database, $username, $password);
-if ($dlo==0) {
-       print('connect to non-existing database failed, so it\'s ok'."\n");
-       }
+// sqlite is a special case as it will just create a db if it isn't found
+if ($module == DBX_SQLITE) {
+    print('connect to non-existing database failed, so it\'s ok'."\n");
+    }
 else {
-    print_r($dlo);
-       dbx_close($dlo);
+    $dlo = @dbx_connect($module, $host, $nonexisting_database, $username, $password);
+    if ($dlo==0) {
+        print('connect to non-existing database failed, so it\'s ok'."\n");
+        }
+    else {
+        print_r($dlo);
+        dbx_close($dlo);
+        }
+    }
+// sqlite is a special case as it doesn't use user/password restrictions
+if ($module == DBX_SQLITE) {
+    print('connect with false username/password combi failed, so it\'s ok'."\n");
     }
-$dlo = @dbx_connect($module, $host, $database, $nonexisting_username, $nonexisting_password);
-if ($dlo==0) {
-       print('connect with false username/password combi failed, so it\'s ok'."\n");
-       }
 else {
-    print_r($dlo);
-       dbx_close($dlo);
+    $dlo = @dbx_connect($module, $host, $database, $nonexisting_username, $nonexisting_password);
+    if ($dlo==0) {
+        print('connect with false username/password combi failed, so it\'s ok'."\n");
+        }
+    else {
+        print_r($dlo);
+        dbx_close($dlo);
+        }
     }
+
+if ($module != DBX_SQLITE) { // skip persistent tests for sqlite until that bug is solved
+
 $dlo = dbx_connect($module_name, $host, $database, $username, $password, DBX_PERSISTENT);
 if ($dlo!=0) {
        print('persistent connect using string ok'."\n");
+    var_dump($dlo->handle);
        dbx_close($dlo);
        }
 $dlo = dbx_connect($module, $host, $database, $username, $password, DBX_PERSISTENT);
 if ($dlo!=0) {
        print('persistent connect using constant ok'."\n");
+    var_dump($dlo->handle);
        dbx_close($dlo);
        }
-$dlo = @dbx_connect($module, $host, $nonexisting_database, $username, $password, DBX_PERSISTENT);
-if ($dlo==0) {
-       print('persistent connect to non-existing database failed, so it\'s ok'."\n");
-       }
+// sqlite is a special case as it will just create a db if it isn't found
+if ($module == DBX_SQLITE) {
+    print('persistent connect to non-existing database failed, so it\'s ok'."\n");
+    }
 else {
-    print_r($dlo);
-       dbx_close($dlo);
+    $dlo = @dbx_connect($module, $host, $nonexisting_database, $username, $password, DBX_PERSISTENT);
+    if ($dlo==0) {
+        print('persistent connect to non-existing database failed, so it\'s ok'."\n");
+        }
+    else {
+        print_r($dlo);
+        dbx_close($dlo);
+        }
     }
 $dlo = @dbx_connect($module, $host, $database, $nonexisting_username, $nonexisting_password, DBX_PERSISTENT);
 if ($dlo==0) {
@@ -62,6 +85,15 @@ else {
     print_r($dlo);
        dbx_close($dlo);
     }
+
+}  // skip persistent tests for sqlite until that bug is solved
+else {
+       print('persistent connect using string ok'."\n");
+       print('persistent connect using constant ok'."\n");
+    print('persistent connect to non-existing database failed, so it\'s ok'."\n");
+       print('persistent connect with false username/password combi failed, so it\'s ok'."\n");
+}
+
 $dlo = @dbx_connect($module, $host, $database, $username, $password, DBX_PERSISTENT, "12many");
 if ($dlo==0) {
        print('too many parameters: connect failure works ok'."\n");
@@ -85,12 +117,18 @@ if ($dlo1!=0 && $dlo2!=0) {
        dbx_close($dlo1);
        dbx_close($dlo2);
        }
-$dlo1 = dbx_connect($module, $host, $database, $username, $password);
-$dlo2 = @dbx_connect($module, $host, $nonexisting_database, $username, $password);
-if ($dlo1!=0 && $dlo2==0) {
+// sqlite is a special case as it will just create a db if it isn't found
+if ($module == DBX_SQLITE) {
     print('multiple connects (2nd fails on database-name) ok'."\n");
-       dbx_close($dlo1);
-       }
+    }
+else {
+    $dlo1 = dbx_connect($module, $host, $database, $username, $password);
+    $dlo2 = @dbx_connect($module, $host, $nonexisting_database, $username, $password);
+    if ($dlo1!=0 && $dlo2==0) {
+        print('multiple connects (2nd fails on database-name) ok'."\n");
+        dbx_close($dlo1);
+        }
+    }
 ?>
 --EXPECT--
 connect using string ok
index 404e7de3eb45f19903942121622f8befe2af8eee..233bf49be164ddfe1444fc86164bbf40a94f93fe 100644 (file)
@@ -8,7 +8,7 @@ include_once("skipif.inc");
 <?php 
 include_once("dbx_test.p");
 $dlo = dbx_connect($module, $host, $database, $username, $password);
-if ($module===DBX_OCI8) { // close for oci8 always return NULL since it doesn't do anything
+if ($module===DBX_OCI8 || $module===DBX_SQLITE) { // close for oci8 and sqlite always return NULL since it doesn't do anything
     print('close works ok'."\n");
     }
 else {
index 13b8b677f7752750caf5eb37caeb1ceda1a08ea0..e5aa925a97776d3b4f0b9684422fa175c48974ac 100644 (file)
@@ -34,6 +34,7 @@ else {
     if (!strlen(dbx_error($dlo)) || (($module==DBX_MSSQL || $module==DBX_SYBASECT) && dbx_error($dlo)=="Changed database context to '".$database."'.".($module==DBX_SYBASECT?"\n":""))) {
         print('query is valid: dbx_error works ok'."\n");
         }
+    else print(dbx_error($dlo));
     if (!@dbx_error(0)) {
         print('wrong dbx_link_object: dbx_error failure works ok'."\n");
         }
index 67f2546b24ac56e6635f9ad4113280cea9172eee..00fe1f2e37fedb87a77d3c390f3bb048fd8bc4a4 100644 (file)
@@ -60,6 +60,14 @@ switch ($connection) {
         $password="dbx_testpassword";
         $module_name="sybase_ct";
         break;
+    case DBX_SQLITE:
+        $module=DBX_SQLITE;
+        $host="";
+        $database="ext\\dbx\\tests\\dbx_test.sqlite.db";
+        $username="";
+        $password="";
+        $module_name="sqlite";
+        break;
     }
 
 ?>
\ No newline at end of file