summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2003-06-04 20:54:48 +0000
committerMarcus Boerger <helly@php.net>2003-06-04 20:54:48 +0000
commitb70cf4074252a2e524ead2927c8e29ecb2eaa25e (patch)
treed764afe2e6f8b0b2cfef5e833f8b26edb984e76e
parenta8c7c3bc5e93a0de0639bd25965a15375db0d04b (diff)
downloadphp-git-b70cf4074252a2e524ead2927c8e29ecb2eaa25e.tar.gz
Goodbye namespaces
-rwxr-xr-xext/spl/php_spl.c22
-rwxr-xr-xext/spl/php_spl.h1
-rwxr-xr-xext/spl/spl_engine.c2
-rwxr-xr-xext/spl/spl_functions.c29
-rwxr-xr-xext/spl/spl_functions.h15
-rwxr-xr-xext/spl/tests/array_access_001.phpt4
-rwxr-xr-xext/spl/tests/array_access_002.phpt4
-rwxr-xr-xext/spl/tests/array_access_ex.phpt10
-rwxr-xr-xext/spl/tests/array_read.phpt4
-rwxr-xr-xext/spl/tests/foreach.phpt4
-rwxr-xr-xext/spl/tests/foreach_break.phpt4
-rwxr-xr-xext/spl/tests/forward.phpt10
-rwxr-xr-xext/spl/tests/sequence.phpt16
-rw-r--r--ext/sqlite/php_sqlite.h3
-rw-r--r--ext/sqlite/sqlite.c631
15 files changed, 589 insertions, 170 deletions
diff --git a/ext/spl/php_spl.c b/ext/spl/php_spl.c
index 4467b0aa60..00b1a37f0c 100755
--- a/ext/spl/php_spl.c
+++ b/ext/spl/php_spl.c
@@ -62,7 +62,6 @@ zend_module_entry spl_module_entry = {
};
/* }}} */
-zend_namespace *spl_ns_spl;
zend_class_entry *spl_ce_iterator;
zend_class_entry *spl_ce_forward;
zend_class_entry *spl_ce_assoc;
@@ -123,8 +122,6 @@ PHP_MINIT_FUNCTION(spl)
{
ZEND_INIT_MODULE_GLOBALS(spl, spl_init_globals, NULL);
- REGISTER_SPL_NAMESPACE(spl);
-
REGISTER_SPL_INTERFACE(spl, iterator);
REGISTER_SPL_INTF_FUNC(spl, iterator, new_iterator);
@@ -294,11 +291,28 @@ PHP_FUNCTION(class_implements)
}
/* }}} */
+#define SPL_ADD_CLASS(class_name) \
+ spl_add_classes(&spl_ce_ ## class_name, return_value TSRMLS_CC)
+
/* {{{ spl_classes */
PHP_FUNCTION(spl_classes)
{
array_init(return_value);
- zend_hash_apply_with_argument(&spl_ns_spl->class_table, (apply_func_arg_t)spl_add_classes, return_value TSRMLS_CC);
+
+ SPL_ADD_CLASS(iterator);
+ SPL_ADD_CLASS(forward);
+ SPL_ADD_CLASS(sequence);
+ SPL_ADD_CLASS(assoc);
+ SPL_ADD_CLASS(forward_assoc);
+ SPL_ADD_CLASS(sequence_assoc);
+ SPL_ADD_CLASS(array_read);
+ SPL_ADD_CLASS(array_access);
+ SPL_ADD_CLASS(array_access_ex);
+ SPL_ADD_CLASS(array_writer);
+
+#ifdef SPL_ARRAY_WRITE
+ SPL_ADD_CLASS(array_writer_default);
+#endif
}
/* }}} */
diff --git a/ext/spl/php_spl.h b/ext/spl/php_spl.h
index d06090d52d..e54ef2dbcb 100755
--- a/ext/spl/php_spl.h
+++ b/ext/spl/php_spl.h
@@ -83,7 +83,6 @@ extern int spl_globals_id;
extern zend_spl_globals spl_globals;
#endif
-extern zend_namespace *spl_ns_spl;
extern zend_class_entry *spl_ce_iterator;
extern zend_class_entry *spl_ce_forward;
extern zend_class_entry *spl_ce_sequence;
diff --git a/ext/spl/spl_engine.c b/ext/spl/spl_engine.c
index 1f4bb78f47..30cee2fd57 100755
--- a/ext/spl/spl_engine.c
+++ b/ext/spl/spl_engine.c
@@ -186,7 +186,6 @@ int spl_call_method(zval **object_pp, zend_class_entry *obj_ce, zend_function **
zend_class_entry *current_scope;
zend_class_entry *calling_scope = NULL;
zval *current_this;
- zend_namespace *current_namespace = EG(active_namespace);
zend_execute_data execute_data;
va_list args;
@@ -315,7 +314,6 @@ int spl_call_method(zval **object_pp, zend_class_entry *obj_ce, zend_function **
}
zend_ptr_stack_clear_multiple(TSRMLS_C);
EG(function_state_ptr) = original_function_state_ptr;
- EG(active_namespace) = current_namespace;
if (EG(This)) {
zval_ptr_dtor(&EG(This));
diff --git a/ext/spl/spl_functions.c b/ext/spl/spl_functions.c
index ea51d695e2..eefa130d7f 100755
--- a/ext/spl/spl_functions.c
+++ b/ext/spl/spl_functions.c
@@ -34,25 +34,14 @@ void spl_destroy_class(zend_class_entry ** ppce)
}
/* }}} */
-/* {{{ spl_register_namespace */
-void spl_register_namespace(zend_namespace ** ppns, char * namespace_name TSRMLS_DC)
-{
- zend_namespace ns;
-
- INIT_NAMESPACE(ns, namespace_name);
- ns.name_length = strlen(namespace_name);
- *ppns = zend_register_internal_namespace(&ns TSRMLS_CC);
-}
-/* }}} */
-
/* {{{ spl_register_interface */
-void spl_register_interface(zend_class_entry ** ppce, zend_namespace * namespace_entry, char * class_name TSRMLS_DC)
+void spl_register_interface(zend_class_entry ** ppce, char * class_name TSRMLS_DC)
{
zend_class_entry ce;
INIT_CLASS_ENTRY(ce, class_name, NULL);
ce.name_length = strlen(class_name);
- *ppce = zend_register_internal_ns_class(&ce, NULL, namespace_entry, NULL TSRMLS_CC);
+ *ppce = zend_register_internal_class(&ce TSRMLS_CC);
/* entries changed by initialize */
(*ppce)->ce_flags = ZEND_ACC_ABSTRACT | ZEND_ACC_INTERFACE;
@@ -60,14 +49,14 @@ void spl_register_interface(zend_class_entry ** ppce, zend_namespace * namespace
/* }}} */
/* {{{ spl_register_std_class */
-void spl_register_std_class(zend_class_entry ** ppce, zend_namespace * namespace_entry, char * class_name, void * obj_ctor TSRMLS_DC)
+void spl_register_std_class(zend_class_entry ** ppce, char * class_name, void * obj_ctor TSRMLS_DC)
{
zend_class_entry ce;
memset(&ce, 0, sizeof(zend_class_entry));
INIT_CLASS_ENTRY(ce, class_name, NULL);
ce.name_length = strlen(class_name);
- *ppce = zend_register_internal_ns_class(&ce, NULL, namespace_entry, NULL TSRMLS_CC);
+ *ppce = zend_register_internal_class(&ce TSRMLS_CC);
/* entries changed by initialize */
(*ppce)->create_object = obj_ctor;
@@ -86,7 +75,6 @@ void spl_register_interface_function(zend_class_entry * class_entry, char * fn_n
pfunction->function_name = fn_name;
pfunction->scope = class_entry;
pfunction->fn_flags = ZEND_ACC_ABSTRACT | ZEND_ACC_PUBLIC;
- pfunction->ns = class_entry->ns;
pfunction->prototype = NULL;
zend_hash_add(&class_entry->function_table, fn_name, strlen(fn_name)+1, &function, sizeof(zend_function), (void**)&reg_function);
}
@@ -118,14 +106,7 @@ void spl_register_functions(zend_class_entry * class_entry, function_entry * fun
/* {{ spl_make_fully_qualyfied_name */
char * spl_make_fully_qualyfied_name(zend_class_entry * pce TSRMLS_DC)
{
- if (pce->ns && (pce->ns != &CG(global_namespace))) {
- char *retval;
-
- spprintf(&retval, 0, "%s::%s", pce->ns->name, pce->name);
- return retval;
- } else {
- return estrdup(pce->name);
- }
+ return estrdup(pce->name);
}
/* }}} */
diff --git a/ext/spl/spl_functions.h b/ext/spl/spl_functions.h
index f6a7b57ab4..a68ffacede 100755
--- a/ext/spl/spl_functions.h
+++ b/ext/spl/spl_functions.h
@@ -23,14 +23,11 @@
typedef zend_object_value (*create_object_func_t)(zend_class_entry *class_type TSRMLS_DC);
-#define REGISTER_SPL_NAMESPACE(namespace_name) \
- spl_register_namespace(&spl_ns_ ## namespace_name, # namespace_name TSRMLS_CC);
-
#define REGISTER_SPL_STD_CLASS(namespace_name, class_name, obj_ctor) \
- spl_register_std_class(&spl_ce_ ## class_name, spl_ns_ ## namespace_name, # class_name, obj_ctor TSRMLS_CC);
+ spl_register_std_class(&spl_ce_ ## class_name, "spl_" # class_name, obj_ctor TSRMLS_CC);
#define REGISTER_SPL_INTERFACE(namespace_name, class_name) \
- spl_register_interface(&spl_ce_ ## class_name, spl_ns_ ## namespace_name, # class_name TSRMLS_CC);
+ spl_register_interface(&spl_ce_ ## class_name, "spl_" # class_name TSRMLS_CC);
#define REGISTER_SPL_INTF_FUNC(namespace_name, class_name, function_name) \
spl_register_interface_function(spl_ce_ ## class_name, # function_name TSRMLS_CC);
@@ -46,11 +43,9 @@ typedef zend_object_value (*create_object_func_t)(zend_class_entry *class_type T
void spl_destroy_class(zend_class_entry ** ppce);
-void spl_register_namespace(zend_namespace ** ppns, char * namespace_name TSRMLS_DC);
-
-void spl_register_std_class(zend_class_entry ** ppce, zend_namespace * namespace_entry, char * class_name, create_object_func_t ctor TSRMLS_DC);
+void spl_register_std_class(zend_class_entry ** ppce, char * class_name, create_object_func_t ctor TSRMLS_DC);
-void spl_register_interface(zend_class_entry ** ppce, zend_namespace * namespace_entry, char * class_name TSRMLS_DC);
+void spl_register_interface(zend_class_entry ** ppce, char * class_name TSRMLS_DC);
void spl_register_interface_function(zend_class_entry * class_entry, char * fn_name TSRMLS_DC);
void spl_register_parent_ce(zend_class_entry * class_entry, zend_class_entry * parent_class TSRMLS_DC);
@@ -59,7 +54,7 @@ void spl_register_functions(zend_class_entry * class_entry, function_entry * fun
char * spl_make_fully_qualyfied_name(zend_class_entry * pce TSRMLS_DC);
void spl_add_class_name(zval * list, zend_class_entry * pce TSRMLS_DC);
-void spl_add_interfaces(zval *list, zend_class_entry * pce TSRMLS_DC);
+void spl_add_interfaces(zval * list, zend_class_entry * pce TSRMLS_DC);
int spl_add_classes(zend_class_entry ** ppce, zval *list TSRMLS_DC);
#define SPL_CLASS_FE(class_name, function_name, arg_types) \
diff --git a/ext/spl/tests/array_access_001.phpt b/ext/spl/tests/array_access_001.phpt
index 5748a5c594..12b70e4c31 100755
--- a/ext/spl/tests/array_access_001.phpt
+++ b/ext/spl/tests/array_access_001.phpt
@@ -3,11 +3,11 @@ SPL: array_access
--SKIPIF--
<?php
if (!extension_loaded("spl")) die("skip");
- if (!in_array("spl::array_access",spl_classes())) die("skip spl::array_access not present");
+ if (!in_array("spl_array_access", spl_classes())) die("skip spl_array_access not present");
?>
--FILE--
<?php
-class c implements spl::array_access {
+class c implements spl_array_access {
public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
function exists($index) {
diff --git a/ext/spl/tests/array_access_002.phpt b/ext/spl/tests/array_access_002.phpt
index d415b19248..64dccb3acb 100755
--- a/ext/spl/tests/array_access_002.phpt
+++ b/ext/spl/tests/array_access_002.phpt
@@ -3,11 +3,11 @@ SPL: array_access without return in set()
--SKIPIF--
<?php
if (!extension_loaded("spl")) die("skip");
- if (!in_array("spl::array_access",spl_classes())) die("skip spl::array_access not present");
+ if (!in_array("spl_array_access", spl_classes())) die("skip spl_array_access not present");
?>
--FILE--
<?php
-class c implements spl::array_access {
+class c implements spl_array_access {
public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
function exists($index) {
diff --git a/ext/spl/tests/array_access_ex.phpt b/ext/spl/tests/array_access_ex.phpt
index 2800c0508e..ed7aceab19 100755
--- a/ext/spl/tests/array_access_ex.phpt
+++ b/ext/spl/tests/array_access_ex.phpt
@@ -3,11 +3,11 @@ SPL: array_access
--SKIPIF--
<?php
if (!extension_loaded("spl")) die("skip");
- if (!in_array("spl::array_access",spl_classes())) die("skip spl::array_access not present");
+ if (!in_array("spl_array_access", spl_classes())) die("skip spl_array_access not present");
?>
--FILE--
<?php
-class array_write implements spl::array_writer {
+class array_write implements spl_array_writer {
private $obj;
private $idx;
@@ -22,7 +22,7 @@ class array_write implements spl::array_writer {
}
}
-class c implements spl::array_access_ex {
+class c implements spl_array_access_ex {
public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
@@ -104,11 +104,11 @@ c::get(4th)
int(4)
c::exists(5th)
-Notice: Undefined index: 5th in /usr/src/php5/ext/spl/tests/array_access_ex.php on line 49
+Notice: Undefined index: 5th in %sarray_access_ex.php on line %d
NULL
c::exists(6)
-Notice: Undefined index: 6 in /usr/src/php5/ext/spl/tests/array_access_ex.php on line 50
+Notice: Undefined index: 6 in %sarray_access_ex.php on line %d
NULL
WRITE 1
c::exists(1)
diff --git a/ext/spl/tests/array_read.phpt b/ext/spl/tests/array_read.phpt
index b1e95fd6a1..032373d52d 100755
--- a/ext/spl/tests/array_read.phpt
+++ b/ext/spl/tests/array_read.phpt
@@ -10,7 +10,7 @@ echo "EXTERNAL\n";
$a = array('1st', 1, 2=>'3rd', '4th'=>4);
var_dump($a);
-class external implements spl::array_read {
+class external implements spl_array_read {
function exists($index) {
echo __METHOD__ . "($index)\n";
@@ -46,7 +46,7 @@ $out = $obj['4th']; echo "$out\n";
echo "INTERNAL\n";
-class internal implements spl::array_read {
+class internal implements spl_array_read {
public $a = array('1st', 1, 2=>'3rd', '4th'=>4);
diff --git a/ext/spl/tests/foreach.phpt b/ext/spl/tests/foreach.phpt
index f3c902e74f..de05f4b3f5 100755
--- a/ext/spl/tests/foreach.phpt
+++ b/ext/spl/tests/foreach.phpt
@@ -4,7 +4,7 @@ SPL: foreach and iterator
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
-class c_iter implements spl::forward_assoc {
+class c_iter implements spl_forward_assoc {
private $obj;
private $num = 0;
@@ -36,7 +36,7 @@ class c_iter implements spl::forward_assoc {
}
}
-class c implements spl::iterator {
+class c implements spl_iterator {
public $max = 3;
diff --git a/ext/spl/tests/foreach_break.phpt b/ext/spl/tests/foreach_break.phpt
index 606682d73c..b17831c74c 100755
--- a/ext/spl/tests/foreach_break.phpt
+++ b/ext/spl/tests/foreach_break.phpt
@@ -4,7 +4,7 @@ SPL: foreach and break
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
-class c_iter implements spl::forward_assoc {
+class c_iter implements spl_forward_assoc {
private $obj;
private $num = 0;
@@ -36,7 +36,7 @@ class c_iter implements spl::forward_assoc {
}
}
-class c implements spl::iterator {
+class c implements spl_iterator {
public $max = 3;
diff --git a/ext/spl/tests/forward.phpt b/ext/spl/tests/forward.phpt
index 3421593268..574d87e628 100755
--- a/ext/spl/tests/forward.phpt
+++ b/ext/spl/tests/forward.phpt
@@ -4,7 +4,7 @@ SPL: forward
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
-class c implements spl::forward_assoc {
+class c implements spl_forward_assoc {
public $max = 3;
public $num = 0;
@@ -36,7 +36,7 @@ $i = new c();
$c_info = array(class_name($i) => array('inheits' => class_parents($i), 'implements' => class_implements($i)));
print_r($c_info);
-$methods = get_class_methods("spl::forward_assoc");
+$methods = get_class_methods("spl_forward_assoc");
sort($methods);
print_r($methods);
$methods = get_class_methods($i);
@@ -75,9 +75,9 @@ Array
[implements] => Array
(
- [spl::forward_assoc] => spl::forward_assoc
- [spl::assoc] => spl::assoc
- [spl::forward] => spl::forward
+ [spl_forward_assoc] => spl_forward_assoc
+ [spl_assoc] => spl_assoc
+ [spl_forward] => spl_forward
)
)
diff --git a/ext/spl/tests/sequence.phpt b/ext/spl/tests/sequence.phpt
index 3c6ef2a234..d5408bb75f 100755
--- a/ext/spl/tests/sequence.phpt
+++ b/ext/spl/tests/sequence.phpt
@@ -4,7 +4,7 @@ SPL: sequence
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php
-class c implements spl::iterator {
+class c implements spl_iterator {
public $max = 3;
@@ -14,7 +14,7 @@ class c implements spl::iterator {
}
}
-class c_iter implements spl::sequence_assoc {
+class c_iter implements spl_sequence_assoc {
private $obj;
private $num = 0;
@@ -78,7 +78,7 @@ Array
[implements] => Array
(
- [spl::iterator] => spl::iterator
+ [spl_iterator] => spl_iterator
)
)
@@ -91,11 +91,11 @@ Array
[implements] => Array
(
- [spl::sequence_assoc] => spl::sequence_assoc
- [spl::forward_assoc] => spl::forward_assoc
- [spl::assoc] => spl::assoc
- [spl::forward] => spl::forward
- [spl::sequence] => spl::sequence
+ [spl_sequence_assoc] => spl_sequence_assoc
+ [spl_forward_assoc] => spl_forward_assoc
+ [spl_assoc] => spl_assoc
+ [spl_forward] => spl_forward
+ [spl_sequence] => spl_sequence
)
)
diff --git a/ext/sqlite/php_sqlite.h b/ext/sqlite/php_sqlite.h
index e6aae260c3..dd9cd65406 100644
--- a/ext/sqlite/php_sqlite.h
+++ b/ext/sqlite/php_sqlite.h
@@ -47,6 +47,7 @@ PHP_FUNCTION(sqlite_popen);
PHP_FUNCTION(sqlite_close);
PHP_FUNCTION(sqlite_query);
PHP_FUNCTION(sqlite_unbuffered_query);
+
PHP_FUNCTION(sqlite_fetch_array);
PHP_FUNCTION(sqlite_fetch_string);
PHP_FUNCTION(sqlite_current);
@@ -76,6 +77,8 @@ PHP_FUNCTION(sqlite_error_string);
PHP_FUNCTION(sqlite_create_aggregate);
PHP_FUNCTION(sqlite_create_function);
+PHP_FUNCTION(sqlite_factory);
+
ZEND_BEGIN_MODULE_GLOBALS(sqlite)
int assoc_case;
ZEND_END_MODULE_GLOBALS(sqlite)
diff --git a/ext/sqlite/sqlite.c b/ext/sqlite/sqlite.c
index 5aa2a55b21..150dac5b6d 100644
--- a/ext/sqlite/sqlite.c
+++ b/ext/sqlite/sqlite.c
@@ -38,6 +38,13 @@
#include <sqlite.h>
+#ifdef HAVE_SPL
+#include "ext/spl/php_spl.h"
+#include "ext/spl/spl_functions.h"
+#endif
+
+#include "Zend/zend_default_classes.h"
+
#ifndef safe_emalloc
#define safe_emalloc(a,b,c) emalloc((a)*(b)+(c))
#endif
@@ -70,13 +77,49 @@ static inline void php_sqlite_strtolower(char *s)
/* {{{ PHP_INI
*/
PHP_INI_BEGIN()
-STD_PHP_INI_ENTRY_EX("sqlite.assoc_case", "0", PHP_INI_ALL, OnUpdateInt, assoc_case, zend_sqlite_globals, sqlite_globals, display_link_numbers)
+STD_PHP_INI_ENTRY_EX("sqlite.assoc_case", "0", PHP_INI_ALL, OnUpdateLong, assoc_case, zend_sqlite_globals, sqlite_globals, display_link_numbers)
PHP_INI_END()
/* }}} */
#define DB_FROM_ZVAL(db, zv) ZEND_FETCH_RESOURCE2(db, struct php_sqlite_db *, zv, -1, "sqlite database", le_sqlite_db, le_sqlite_pdb)
+#define DB_FROM_OBJECT(db, object) \
+ { \
+ sqlite_object *obj = (sqlite_object*) zend_object_store_get_object(object TSRMLS_CC); \
+ db = obj->u.db; \
+ if (!db) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The database wasn't opened"); \
+ RETURN_NULL(); \
+ } \
+ }
+
+#define RES_FROM_OBJECT(res, object) \
+ { \
+ sqlite_object *obj = (sqlite_object*) zend_object_store_get_object(object TSRMLS_CC); \
+ res = obj->u.res; \
+ if (!res) { \
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "No result set available"); \
+ RETURN_NULL(); \
+ } \
+ }
+
+#define SQLITE_THROW(message) \
+ PG(suppress_errors) = 0; \
+ EG(exception) = sqlite_instanciate(sqlite_ce_exception, NULL TSRMLS_CC); \
+ { \
+ zval *tmp; \
+ MAKE_STD_ZVAL(tmp); \
+ ZVAL_STRING(tmp, message, 1); \
+ zend_hash_update(Z_OBJPROP_P(EG(exception)), "message", sizeof("message"), (void **) message, sizeof(zval *), NULL); \
+ MAKE_STD_ZVAL(tmp); \
+ ZVAL_STRING(tmp, zend_get_executed_filename(TSRMLS_C), 1); \
+ zend_hash_update(Z_OBJPROP_P(EG(exception)), "file", sizeof("file"), (void **) &tmp, sizeof(zval *), NULL); \
+ MAKE_STD_ZVAL(tmp); \
+ ZVAL_LONG(tmp, zend_get_executed_lineno(TSRMLS_C)); \
+ zend_hash_update(Z_OBJPROP_P(EG(exception)), "line", sizeof("line"), (void **) &tmp, sizeof(zval *), NULL); \
+ }
+
struct php_sqlite_result {
struct php_sqlite_db *db;
sqlite_vm *vm;
@@ -136,9 +179,46 @@ function_entry sqlite_functions[] = {
PHP_FE(sqlite_unbuffered_query, NULL)
PHP_FE(sqlite_create_aggregate, NULL)
PHP_FE(sqlite_create_function, NULL)
+ PHP_FE(sqlite_factory, NULL)
+ {NULL, NULL, NULL}
+};
+
+#define PHP_ME_MAPPING(name, func_name, arg_types) \
+ ZEND_NAMED_FE(name, ZEND_FN(func_name), arg_types)
+
+function_entry sqlite_funcs_db[] = {
+ PHP_ME_MAPPING(sqlite_db, sqlite_open, NULL)
+ PHP_ME_MAPPING(close, sqlite_close, NULL)
+ PHP_ME_MAPPING(query, sqlite_query, NULL)
+ PHP_ME_MAPPING(unbuffered_query, sqlite_unbuffered_query, NULL)
+ PHP_ME_MAPPING(last_insert_rowid, sqlite_last_insert_rowid, NULL)
+ PHP_ME_MAPPING(create_aggregate, sqlite_create_aggregate, NULL)
+ PHP_ME_MAPPING(create_function, sqlite_create_function, NULL)
+ PHP_ME_MAPPING(busy_timeout, sqlite_busy_timeout, NULL)
+ PHP_ME_MAPPING(last_error, sqlite_last_error, NULL)
+/* PHP_ME_MAPPING(error_string, sqlite_error_string, NULL) static */
+/* PHP_ME_MAPPING(escape_string, sqlite_escape_string, NULL) static */
{NULL, NULL, NULL}
};
+function_entry sqlite_funcs_query[] = {
+ PHP_ME_MAPPING(fetch_array, sqlite_fetch_array, NULL)
+ PHP_ME_MAPPING(current, sqlite_current, NULL)
+ PHP_ME_MAPPING(column, sqlite_column, NULL)
+ PHP_ME_MAPPING(changes, sqlite_changes, NULL)
+ PHP_ME_MAPPING(num_rows, sqlite_num_rows, NULL)
+ PHP_ME_MAPPING(num_fields, sqlite_num_fields, NULL)
+ PHP_ME_MAPPING(field_name, sqlite_field_name, NULL)
+ PHP_ME_MAPPING(seek, sqlite_seek, NULL)
+ PHP_ME_MAPPING(rewind, sqlite_rewind, NULL)
+ PHP_ME_MAPPING(next, sqlite_next, NULL)
+ PHP_ME_MAPPING(has_more, sqlite_has_more, NULL)
+ {NULL, NULL, NULL}
+};
+
+function_entry sqlite_funcs_exception[] = {
+ {NULL, NULL, NULL}
+};
zend_module_entry sqlite_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
@@ -148,7 +228,7 @@ zend_module_entry sqlite_module_entry = {
sqlite_functions,
PHP_MINIT(sqlite),
NULL,
- NULL,
+ PHP_RINIT(sqlite),
PHP_RSHUTDOWN(sqlite),
PHP_MINFO(sqlite),
#if ZEND_MODULE_API_NO >= 20010901
@@ -576,6 +656,130 @@ static int php_sqlite_authorizer(void *autharg, int access_type, const char *arg
}
/* }}} */
+/* {{{ OO init/structure stuff */
+#define REGISTER_SQLITE_CLASS(name, parent) \
+ { \
+ zend_class_entry ce; \
+ INIT_CLASS_ENTRY(ce, "sqlite_" # name, sqlite_funcs_ ## name); \
+ ce.create_object = sqlite_object_new_ ## name; \
+ sqlite_ce_ ## name = zend_register_internal_class_ex(&ce, parent, NULL TSRMLS_CC); \
+ memcpy(&sqlite_object_handlers_ ## name, zend_get_std_object_handlers(), sizeof(zend_object_handlers)); \
+ }
+
+zend_class_entry *sqlite_ce_db, *sqlite_ce_query, *sqlite_ce_exception;
+
+static zend_object_handlers sqlite_object_handlers_db;
+static zend_object_handlers sqlite_object_handlers_query;
+static zend_object_handlers sqlite_object_handlers_exception;
+
+typedef enum {
+ is_db,
+ is_result
+} sqlite_obj_type;
+
+typedef struct _sqlite_object {
+ zend_object std;
+ sqlite_obj_type type;
+ union {
+ struct php_sqlite_db *db;
+ struct php_sqlite_result *res;
+ void *ptr;
+ } u;
+} sqlite_object;
+
+static void sqlite_object_clone(void *object, void **object_clone TSRMLS_DC)
+{
+ /* TODO */
+}
+
+static int sqlite_free_persistent(list_entry *le, void *ptr TSRMLS_DC)
+{
+ return le->ptr == ptr;
+}
+
+static void sqlite_object_dtor(void *object, zend_object_handle handle TSRMLS_DC)
+{
+ sqlite_object *intern = (sqlite_object *)object;
+
+ zend_hash_destroy(intern->std.properties);
+ FREE_HASHTABLE(intern->std.properties);
+
+ if (intern->u.ptr) {
+ if (intern->type == is_db) {
+ if (intern->u.db->rsrc_id) {
+ zend_list_delete(intern->u.db->rsrc_id);
+ zend_hash_apply_with_argument(&EG(persistent_list), (apply_func_arg_t) sqlite_free_persistent, &intern->u.ptr TSRMLS_CC);
+ }
+ } else {
+ real_result_dtor(intern->u.res TSRMLS_CC);
+ }
+ }
+
+ efree(object);
+}
+
+static void sqlite_object_new(zend_class_entry *class_type, zend_object_handlers *handlers, zend_object_value *retval TSRMLS_DC)
+{
+ sqlite_object *intern;
+ zval *tmp;
+
+ intern = emalloc(sizeof(sqlite_object));
+ memset(intern, 0, sizeof(sqlite_object));
+ intern->std.ce = class_type;
+
+ ALLOC_HASHTABLE(intern->std.properties);
+ zend_hash_init(intern->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+ zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
+
+ retval->handle = zend_objects_store_put(intern, sqlite_object_dtor, sqlite_object_clone TSRMLS_CC);
+ retval->handlers = handlers;
+}
+
+static zend_object_value sqlite_object_new_db(zend_class_entry *class_type TSRMLS_DC)
+{
+ zend_object_value retval;
+
+ sqlite_object_new(class_type, &sqlite_object_handlers_db, &retval TSRMLS_CC);
+ return retval;
+}
+
+static zend_object_value sqlite_object_new_query(zend_class_entry *class_type TSRMLS_DC)
+{
+ zend_object_value retval;
+
+ sqlite_object_new(class_type, &sqlite_object_handlers_query, &retval TSRMLS_CC);
+ return retval;
+}
+
+static zend_object_value sqlite_object_new_exception(zend_class_entry *class_type TSRMLS_DC)
+{
+ zend_object_value retval;
+
+ sqlite_object_new(class_type, &sqlite_object_handlers_exception, &retval TSRMLS_CC);
+ return retval;
+}
+
+#define SQLITE_REGISTER_OBJECT(_type, _object, _ptr) \
+ { \
+ sqlite_object *obj; \
+ obj = (sqlite_object*)zend_object_store_get_object(_object TSRMLS_CC); \
+ obj->type = is_ ## _type; \
+ obj->u._type = _ptr; \
+ }
+
+static zval * sqlite_instanciate(zend_class_entry *pce, zval *object TSRMLS_DC)
+{
+ if (!object) {
+ ALLOC_ZVAL(object);
+ }
+ Z_TYPE_P(object) = IS_OBJECT;
+ object_init_ex(object, pce);
+ object->refcount = 1;
+ object->is_ref = 1;
+ return object;
+}
+/* }}} */
+
static int init_sqlite_globals(zend_sqlite_globals *g)
{
g->assoc_case = 0;
@@ -584,8 +788,12 @@ static int init_sqlite_globals(zend_sqlite_globals *g)
PHP_MINIT_FUNCTION(sqlite)
{
+ REGISTER_SQLITE_CLASS(db, NULL);
+ REGISTER_SQLITE_CLASS(query, NULL);
+ REGISTER_SQLITE_CLASS(exception, zend_exception_get_default());
+
ZEND_INIT_MODULE_GLOBALS(sqlite, init_sqlite_globals, NULL);
-
+
REGISTER_INI_ENTRIES();
le_sqlite_db = zend_register_list_destructors_ex(php_sqlite_db_dtor, NULL, "sqlite database", module_number);
@@ -626,6 +834,17 @@ PHP_MINIT_FUNCTION(sqlite)
return SUCCESS;
}
+PHP_RINIT_FUNCTION(sqlite)
+{
+#ifdef HAVE_SPL
+ if (!sqlite_ce_query->num_interfaces) {
+ spl_register_implement(sqlite_ce_query, spl_ce_forward TSRMLS_CC);
+ }
+#endif
+
+ return SUCCESS;
+}
+
PHP_MINFO_FUNCTION(sqlite)
{
php_info_print_table_start();
@@ -638,7 +857,7 @@ PHP_MINFO_FUNCTION(sqlite)
DISPLAY_INI_ENTRIES();
}
-static struct php_sqlite_db *php_sqlite_open(char *filename, int mode, char *persistent_id, zval *return_value, zval *errmsg TSRMLS_DC)
+static struct php_sqlite_db *php_sqlite_open(char *filename, int mode, char *persistent_id, zval *return_value, zval *errmsg, zval *object TSRMLS_DC)
{
char *errtext = NULL;
sqlite *sdb = NULL;
@@ -656,7 +875,12 @@ static struct php_sqlite_db *php_sqlite_open(char *filename, int mode, char *per
sqlite_freemem(errtext);
- RETVAL_FALSE;
+ /* if object is not an object then we're called from the factory() function */
+ if (object && Z_TYPE_P(object) != IS_OBJECT) {
+ RETVAL_NULL();
+ } else {
+ RETVAL_FALSE;
+ }
return NULL;
}
@@ -677,7 +901,15 @@ static struct php_sqlite_db *php_sqlite_open(char *filename, int mode, char *per
/* authorizer hook so we can enforce safe mode */
sqlite_set_authorizer(sdb, php_sqlite_authorizer, NULL);
- db->rsrc_id = ZEND_REGISTER_RESOURCE(return_value, db, persistent_id ? le_sqlite_pdb : le_sqlite_db);
+ db->rsrc_id = ZEND_REGISTER_RESOURCE(object ? NULL : return_value, db, persistent_id ? le_sqlite_pdb : le_sqlite_db);
+ if (object) {
+ /* if object is not an object then we're called from the factory() function */
+ if (Z_TYPE_P(object) != IS_OBJECT) {
+ sqlite_instanciate(sqlite_ce_db, object TSRMLS_CC);
+ }
+ /* and now register the object */
+ SQLITE_REGISTER_OBJECT(db, object, db)
+ }
if (persistent_id) {
list_entry le;
@@ -748,7 +980,7 @@ PHP_FUNCTION(sqlite_popen)
}
/* now we need to open the database */
- php_sqlite_open(fullpath, mode, hashkey, return_value, errmsg TSRMLS_CC);
+ php_sqlite_open(fullpath, mode, hashkey, return_value, errmsg, NULL TSRMLS_CC);
efree(fullpath);
efree(hashkey);
@@ -763,21 +995,68 @@ PHP_FUNCTION(sqlite_open)
char *filename;
long filename_len;
zval *errmsg = NULL;
+ zval *object = getThis();
+ php_set_error_handling(object ? EH_THROW : EH_NORMAL, zend_exception_get_default() TSRMLS_CC);
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz/",
&filename, &filename_len, &mode, &errmsg)) {
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
return;
}
if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
- RETURN_FALSE;
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+ if (object) {
+ RETURN_NULL();
+ } else {
+ RETURN_FALSE;
+ }
}
if (php_check_open_basedir(filename TSRMLS_CC)) {
- RETURN_FALSE;
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+ if (object) {
+ RETURN_NULL();
+ } else {
+ RETURN_FALSE;
+ }
}
- php_sqlite_open(filename, mode, NULL, return_value, errmsg TSRMLS_CC);
+ php_sqlite_open(filename, mode, NULL, return_value, errmsg, object TSRMLS_CC);
+
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+}
+/* }}} */
+
+/* {{{ proto object factory(string filename [, int mode, string &errmessage])
+ Opens a SQLite database and create an object for it. Will create the database if it does not exist */
+PHP_FUNCTION(sqlite_factory)
+{
+ int mode = 0666;
+ char *filename;
+ long filename_len;
+ zval *errmsg = NULL;
+
+ php_set_error_handling(EH_THROW, sqlite_ce_exception TSRMLS_CC);
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lz/",
+ &filename, &filename_len, &mode, &errmsg)) {
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+ RETURN_NULL();
+ }
+
+ if (PG(safe_mode) && (!php_checkuid(filename, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+ RETURN_NULL();
+ }
+
+ if (php_check_open_basedir(filename TSRMLS_CC)) {
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
+ RETURN_NULL();
+ }
+
+ php_sqlite_open(filename, mode, NULL, return_value, errmsg, return_value TSRMLS_CC);
+
+ php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
}
/* }}} */
@@ -788,13 +1067,20 @@ PHP_FUNCTION(sqlite_busy_timeout)
zval *zdb;
struct php_sqlite_db *db;
long ms;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zdb, &ms)) {
- return;
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ms)) {
+ return;
+ }
+ DB_FROM_OBJECT(db, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zdb, &ms)) {
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
-
sqlite_busy_timeout(db->db, ms);
}
/* }}} */
@@ -805,18 +1091,17 @@ PHP_FUNCTION(sqlite_close)
{
zval *zdb;
struct php_sqlite_db *db;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
- return;
- }
- DB_FROM_ZVAL(db, &zdb);
-
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
- return;
+ if (object) {
+ php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Ignored, you must destruct the object instead");
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
-
zend_list_delete(Z_RESVAL_P(zdb));
}
/* }}} */
@@ -911,7 +1196,7 @@ next_row:
/* }}} */
/* {{{ sqlite_query */
-void sqlite_query(struct php_sqlite_db *db, char *sql, long sql_len, int mode, int buffered, zval *return_value TSRMLS_DC)
+void sqlite_query(zval *object, struct php_sqlite_db *db, char *sql, long sql_len, int mode, int buffered, zval *return_value TSRMLS_DC)
{
struct php_sqlite_result res, *rres;
int ret;
@@ -946,7 +1231,15 @@ void sqlite_query(struct php_sqlite_db *db, char *sql, long sql_len, int mode, i
rres->curr_row = 0;
- ZEND_REGISTER_RESOURCE(return_value, rres, le_sqlite_result);
+ if (object) {
+ sqlite_object *obj;
+ sqlite_instanciate(sqlite_ce_query, return_value TSRMLS_CC);
+ obj = (sqlite_object *) zend_object_store_get_object(return_value TSRMLS_CC);
+ obj->type = is_result;
+ obj->u.res = rres;
+ } else {
+ ZEND_REGISTER_RESOURCE(object ? NULL : return_value, rres, le_sqlite_result);
+ }
}
/* }}} */
@@ -960,15 +1253,22 @@ PHP_FUNCTION(sqlite_unbuffered_query)
long sql_len;
int mode = PHPSQLITE_BOTH;
char *errtext = NULL;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &sql, &sql_len, &mode)) {
+ return;
+ }
+ DB_FROM_OBJECT(db, object);
+ } else {
+ if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
ZEND_NUM_ARGS() TSRMLS_CC, "sr|l", &sql, &sql_len, &zdb, &mode) &&
FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &zdb, &sql, &sql_len, &mode)) {
- return;
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
-
/* avoid doing work if we can */
if (!return_value_used) {
db->last_err_code = sqlite_exec(db->db, sql, NULL, NULL, &errtext);
@@ -979,8 +1279,8 @@ PHP_FUNCTION(sqlite_unbuffered_query)
}
return;
}
-
- sqlite_query(db, sql, sql_len, mode, 0, return_value TSRMLS_CC);
+
+ sqlite_query(object, db, sql, sql_len, mode, 0, return_value TSRMLS_CC);
}
/* }}} */
@@ -994,26 +1294,34 @@ PHP_FUNCTION(sqlite_query)
long sql_len;
int mode = PHPSQLITE_BOTH;
char *errtext = NULL;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
- ZEND_NUM_ARGS() TSRMLS_CC, "sr|l", &sql, &sql_len, &zdb, &mode) &&
- FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &zdb, &sql, &sql_len, &mode)) {
- return;
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &sql, &sql_len, &mode)) {
+ return;
+ }
+ DB_FROM_OBJECT(db, object);
+ } else {
+ if (FAILURE == zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET,
+ ZEND_NUM_ARGS() TSRMLS_CC, "sr|l", &sql, &sql_len, &zdb, &mode) &&
+ FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|l", &zdb, &sql, &sql_len, &mode)) {
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
/* avoid doing work if we can */
if (!return_value_used) {
db->last_err_code = sqlite_exec(db->db, sql, NULL, NULL, &errtext);
if (db->last_err_code != SQLITE_OK) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errtext);
- sqlite_freemem(errtext);
- }
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", errtext);
+ sqlite_freemem(errtext);
+ }
return;
}
-
- sqlite_query(db, sql, sql_len, mode, 1, return_value TSRMLS_CC);
+
+ sqlite_query(object, db, sql, sql_len, mode, 1, return_value TSRMLS_CC);
}
/* }}} */
@@ -1022,7 +1330,7 @@ static void php_sqlite_fetch_array(struct php_sqlite_result *res, int mode, zend
{
int j;
const char **rowdata, **colnames;
-
+
/* check range of the row */
if (res->curr_row >= res->nrows) {
/* no more */
@@ -1155,13 +1463,24 @@ PHP_FUNCTION(sqlite_fetch_array)
int mode = PHPSQLITE_BOTH;
zend_bool decode_binary = 1;
struct php_sqlite_result *res;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lb", &zres, &mode, &decode_binary)) {
- return;
- }
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
- if (ZEND_NUM_ARGS() < 2) {
- mode = res->mode;
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &mode, &decode_binary)) {
+ return;
+ }
+ RES_FROM_OBJECT(res, object);
+ if (!ZEND_NUM_ARGS()) {
+ mode = res->mode;
+ }
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lb", &zres, &mode, &decode_binary)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
+ if (ZEND_NUM_ARGS() < 2) {
+ mode = res->mode;
+ }
}
php_sqlite_fetch_array(res, mode, decode_binary, 1, return_value TSRMLS_CC);
@@ -1226,13 +1545,24 @@ PHP_FUNCTION(sqlite_current)
int mode = PHPSQLITE_BOTH;
zend_bool decode_binary = 1;
struct php_sqlite_result *res;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lb", &zres, &mode, &decode_binary)) {
- return;
- }
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
- if (ZEND_NUM_ARGS() < 2) {
- mode = res->mode;
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &mode, &decode_binary)) {
+ return;
+ }
+ RES_FROM_OBJECT(res, object);
+ if (!ZEND_NUM_ARGS()) {
+ mode = res->mode;
+ }
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|lb", &zres, &mode, &decode_binary)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
+ if (ZEND_NUM_ARGS() < 2) {
+ mode = res->mode;
+ }
}
php_sqlite_fetch_array(res, mode, decode_binary, 0, return_value TSRMLS_CC);
@@ -1247,11 +1577,19 @@ PHP_FUNCTION(sqlite_column)
zval *which;
zend_bool decode_binary = 1;
struct php_sqlite_result *res;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|b", &zres, &which, &decode_binary)) {
- return;
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &which, &decode_binary)) {
+ return;
+ }
+ RES_FROM_OBJECT(res, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rz|b", &zres, &which, &decode_binary)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
}
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
php_sqlite_fetch_column(res, which, decode_binary, return_value TSRMLS_CC);
}
@@ -1285,13 +1623,20 @@ PHP_FUNCTION(sqlite_changes)
{
zval *zdb;
struct php_sqlite_db *db;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
- return;
+ if (object) {
+ if (ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT
+ }
+ DB_FROM_OBJECT(db, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
-
RETURN_LONG(sqlite_changes(db->db));
}
/* }}} */
@@ -1302,13 +1647,20 @@ PHP_FUNCTION(sqlite_last_insert_rowid)
{
zval *zdb;
struct php_sqlite_db *db;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
- return;
+ if (object) {
+ if (ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT
+ }
+ DB_FROM_OBJECT(db, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
-
RETURN_LONG(sqlite_last_insert_rowid(db->db));
}
/* }}} */
@@ -1319,13 +1671,20 @@ PHP_FUNCTION(sqlite_num_rows)
{
zval *zres;
struct php_sqlite_result *res;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
- return;
+ if (object) {
+ if (ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT
+ }
+ RES_FROM_OBJECT(res, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
}
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
-
if (res->buffered) {
RETURN_LONG(res->nrows);
} else {
@@ -1341,11 +1700,19 @@ PHP_FUNCTION(sqlite_has_more)
{
zval *zres;
struct php_sqlite_result *res;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
- return;
+ if (object) {
+ if (ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT
+ }
+ RES_FROM_OBJECT(res, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
}
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
RETURN_BOOL(res->nrows && res->curr_row < res->nrows); /* curr_row may be -1 */
}
@@ -1357,13 +1724,20 @@ PHP_FUNCTION(sqlite_num_fields)
{
zval *zres;
struct php_sqlite_result *res;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
- return;
+ if (object) {
+ if (ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT
+ }
+ RES_FROM_OBJECT(res, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
}
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
-
RETURN_LONG(res->ncolumns);
}
/* }}} */
@@ -1375,13 +1749,20 @@ PHP_FUNCTION(sqlite_field_name)
zval *zres;
struct php_sqlite_result *res;
int field;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zres, &field)) {
- return;
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &field)) {
+ return;
+ }
+ RES_FROM_OBJECT(res, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &zres, &field)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
}
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
-
if (field < 0 || field >= res->ncolumns) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "field %d out of range", field);
RETURN_FALSE;
@@ -1398,13 +1779,20 @@ PHP_FUNCTION(sqlite_seek)
zval *zres;
struct php_sqlite_result *res;
int row;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zres, &row)) {
- return;
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &row)) {
+ return;
+ }
+ RES_FROM_OBJECT(res, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &zres, &row)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
}
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
-
if (!res->buffered) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot seek an unbuffered result set");
RETURN_FALSE;
@@ -1426,11 +1814,19 @@ PHP_FUNCTION(sqlite_rewind)
{
zval *zres;
struct php_sqlite_result *res;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
- return;
+ if (object) {
+ if (ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT
+ }
+ RES_FROM_OBJECT(res, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
}
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
if (!res->buffered) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot seek an unbuffered result set");
@@ -1453,11 +1849,19 @@ PHP_FUNCTION(sqlite_next)
{
zval *zres;
struct php_sqlite_result *res;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
- return;
+ if (object) {
+ if (ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT
+ }
+ RES_FROM_OBJECT(res, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zres)) {
+ return;
+ }
+ ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
}
- ZEND_FETCH_RESOURCE(res, struct php_sqlite_result *, &zres, -1, "sqlite result", le_sqlite_result);
if (!res->buffered && res->vm) {
php_sqlite_fetch(res TSRMLS_CC);
@@ -1511,13 +1915,20 @@ PHP_FUNCTION(sqlite_last_error)
{
zval *zdb;
struct php_sqlite_db *db;
+ zval *object = getThis();
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
- return;
+ if (object) {
+ if (ZEND_NUM_ARGS() != 0) {
+ WRONG_PARAM_COUNT
+ }
+ DB_FROM_OBJECT(db, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &zdb)) {
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
-
RETURN_LONG(db->last_err_code);
}
/* }}} */
@@ -1616,11 +2027,19 @@ PHP_FUNCTION(sqlite_create_aggregate)
struct php_sqlite_agg_functions *funcs;
char *callable = NULL;
long num_args = -1;
-
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rszz|l", &zdb, &funcname, &funcname_len, &zstep, &zfinal, &num_args)) {
- return;
+ zval *object = getThis();
+
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "szz|l", &zdb, &funcname, &funcname_len, &zstep, &zfinal, &num_args)) {
+ return;
+ }
+ DB_FROM_OBJECT(db, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rszz|l", &zdb, &funcname, &funcname_len, &zstep, &zfinal, &num_args)) {
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
if (!zend_is_callable(zstep, 0, &callable)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "step function `%s' is not callable", callable);
@@ -1636,6 +2055,7 @@ PHP_FUNCTION(sqlite_create_aggregate)
}
efree(callable);
+
if (prep_callback_struct(db, 1, funcname, zstep, zfinal, &funcs) == DO_REG) {
sqlite_create_aggregate(db->db, funcname, num_args,
php_sqlite_agg_step_function_callback,
@@ -1658,10 +2078,19 @@ PHP_FUNCTION(sqlite_create_function)
char *callable = NULL;
long num_args = -1;
- if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz|l", &zdb, &funcname, &funcname_len, &zcall, &num_args)) {
- return;
+ zval *object = getThis();
+
+ if (object) {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|l", &zdb, &funcname, &funcname_len, &zcall, &num_args)) {
+ return;
+ }
+ DB_FROM_OBJECT(db, object);
+ } else {
+ if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsz|l", &zdb, &funcname, &funcname_len, &zcall, &num_args)) {
+ return;
+ }
+ DB_FROM_ZVAL(db, &zdb);
}
- DB_FROM_ZVAL(db, &zdb);
if (!zend_is_callable(zcall, 0, &callable)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "function `%s' is not callable", callable);