mboeren         Wed Jul  9 12:31:40 2003 EDT

  Added files:                 
    /php-src/ext/dbx    dbx_sqlite.c dbx_sqlite.h 

  Modified files:              
    /php-src/ext/dbx    config.m4 dbx.c dbx.dsp 
    /php-src/ext/dbx/tests      002.phpt 003.phpt 004.phpt 006.phpt 
                                dbx_test.p 
  Log:
  Add SQLite support to DBX (Marc).
  @Add SQLite support to DBX (Marc).
  
  
Index: php-src/ext/dbx/config.m4
diff -u php-src/ext/dbx/config.m4:1.3 php-src/ext/dbx/config.m4:1.4
--- php-src/ext/dbx/config.m4:1.3       Tue Mar 12 11:14:37 2002
+++ php-src/ext/dbx/config.m4   Wed Jul  9 12:31:40 2003
@@ -1,10 +1,10 @@
 dnl
-dnl $Id: config.m4,v 1.3 2002/03/12 16:14:37 sas Exp $
+dnl $Id: config.m4,v 1.4 2003/07/09 16:31:40 mboeren Exp $
 dnl
 
 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: php-src/ext/dbx/dbx.c
diff -u php-src/ext/dbx/dbx.c:1.50 php-src/ext/dbx/dbx.c:1.51
--- php-src/ext/dbx/dbx.c:1.50  Sun Jun 15 11:29:46 2003
+++ php-src/ext/dbx/dbx.c       Wed Jul  9 12:31:40 2003
@@ -20,7 +20,7 @@
    +----------------------------------------------------------------------+
 */
 
-/* $Id: dbx.c,v 1.50 2003/06/15 15:29:46 andrey Exp $ */
+/* $Id: dbx.c,v 1.51 2003/07/09 16:31:40 mboeren Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -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 @@
                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 @@
        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 @@
        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 @@
 {
        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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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 @@
                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: php-src/ext/dbx/dbx.dsp
diff -u php-src/ext/dbx/dbx.dsp:1.8 php-src/ext/dbx/dbx.dsp:1.9
--- php-src/ext/dbx/dbx.dsp:1.8 Mon Feb 18 04:21:51 2002
+++ php-src/ext/dbx/dbx.dsp     Wed Jul  9 12:31:40 2003
@@ -122,6 +122,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\dbx_sqlite.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\dbx_sybasect.c
 # End Source File
 # End Group
@@ -155,6 +159,10 @@
 # Begin Source File
 
 SOURCE=.\dbx_pgsql.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\dbx_sqlite.h
 # End Source File
 # Begin Source File
 
Index: php-src/ext/dbx/tests/002.phpt
diff -u php-src/ext/dbx/tests/002.phpt:1.7 php-src/ext/dbx/tests/002.phpt:1.8
--- php-src/ext/dbx/tests/002.phpt:1.7  Mon Oct 28 04:41:15 2002
+++ php-src/ext/dbx/tests/002.phpt      Wed Jul  9 12:31:40 2003
@@ -11,6 +11,7 @@
 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: php-src/ext/dbx/tests/003.phpt
diff -u php-src/ext/dbx/tests/003.phpt:1.5 php-src/ext/dbx/tests/003.phpt:1.6
--- php-src/ext/dbx/tests/003.phpt:1.5  Thu Oct 24 15:34:18 2002
+++ php-src/ext/dbx/tests/003.phpt      Wed Jul  9 12:31:40 2003
@@ -20,39 +20,62 @@
        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");
-       }
-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);
-    }
+// 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 {
+    $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");
+    }
+else {
+    $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");
-       }
-else {
-    print_r($dlo);
-       dbx_close($dlo);
+// 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 {
+    $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 @@
     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 @@
        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: php-src/ext/dbx/tests/004.phpt
diff -u php-src/ext/dbx/tests/004.phpt:1.4 php-src/ext/dbx/tests/004.phpt:1.5
--- php-src/ext/dbx/tests/004.phpt:1.4  Thu Oct 24 15:34:18 2002
+++ php-src/ext/dbx/tests/004.phpt      Wed Jul  9 12:31:40 2003
@@ -8,7 +8,7 @@
 <?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: php-src/ext/dbx/tests/006.phpt
diff -u php-src/ext/dbx/tests/006.phpt:1.6 php-src/ext/dbx/tests/006.phpt:1.7
--- php-src/ext/dbx/tests/006.phpt:1.6  Thu Oct 24 15:34:18 2002
+++ php-src/ext/dbx/tests/006.phpt      Wed Jul  9 12:31:40 2003
@@ -34,6 +34,7 @@
     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 ([EMAIL PROTECTED](0)) {
         print('wrong dbx_link_object: dbx_error failure works ok'."\n");
         }
Index: php-src/ext/dbx/tests/dbx_test.p
diff -u php-src/ext/dbx/tests/dbx_test.p:1.9 php-src/ext/dbx/tests/dbx_test.p:1.10
--- php-src/ext/dbx/tests/dbx_test.p:1.9        Thu Oct 24 10:16:28 2002
+++ php-src/ext/dbx/tests/dbx_test.p    Wed Jul  9 12:31:40 2003
@@ -60,6 +60,14 @@
         $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;
     }
 
 ?>

Index: php-src/ext/dbx/dbx_sqlite.c
+++ php-src/ext/dbx/dbx_sqlite.c
/*
   +----------------------------------------------------------------------+
   | 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          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author : Marc Boeren         <[EMAIL PROTECTED]>                      |
   +----------------------------------------------------------------------+
*/

/* $Id: dbx_sqlite.c,v 1.1 2003/07/09 16:31:40 mboeren Exp $ */

#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:
 */

Index: php-src/ext/dbx/dbx_sqlite.h
+++ php-src/ext/dbx/dbx_sqlite.h
/*
   +----------------------------------------------------------------------+
   | 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          |
   | [EMAIL PROTECTED] so we can mail you a copy immediately.               |
   +----------------------------------------------------------------------+
   | Author : Marc Boeren         <[EMAIL PROTECTED]>                      |
   +----------------------------------------------------------------------+
*/

/* $Id: dbx_sqlite.h,v 1.1 2003/07/09 16:31:40 mboeren Exp $ */

#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:
 */

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

Reply via email to