summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott MacVicar <scottmac@php.net>2008-12-24 19:22:16 +0000
committerScott MacVicar <scottmac@php.net>2008-12-24 19:22:16 +0000
commit3fb7f05991431de5a6c48bc3ee775e3579438a49 (patch)
tree7a9803bb250eab04b6691d9619c6d383163b69cb
parent4b3197a9cd9179327d06e51be38e828590a48a85 (diff)
downloadphp-git-3fb7f05991431de5a6c48bc3ee775e3579438a49.tar.gz
MFH Stop using sqlite3_aggregate_count() as this is now deprecated.
-rw-r--r--ext/sqlite3/php_sqlite3_structs.h6
-rw-r--r--ext/sqlite3/sqlite3.c33
-rw-r--r--ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt2
3 files changed, 27 insertions, 14 deletions
diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h
index 5ac70505db..8c6b51efc0 100644
--- a/ext/sqlite3/php_sqlite3_structs.h
+++ b/ext/sqlite3/php_sqlite3_structs.h
@@ -72,6 +72,12 @@ typedef struct _php_sqlite3_db_object {
zend_llist free_list;
} php_sqlite3_db_object;
+/* Structure for SQLite Database object. */
+typedef struct _php_sqlite3_agg_context {
+ zval *zval_context;
+ long row_count;
+} php_sqlite3_agg_context;
+
typedef struct _php_sqlite3_stmt_object php_sqlite3_stmt;
typedef struct _php_sqlite3_result_object php_sqlite3_result;
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index 7668fc8a8e..bab91ba8fb 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -596,7 +596,7 @@ static int sqlite3_do_callback(struct php_sqlite3_fci *fc, zval *cb, int argc, s
int i;
int ret;
int fake_argc;
- zval **agg_context = NULL;
+ php_sqlite3_agg_context *agg_context = NULL;
if (is_agg) {
is_agg = 2;
@@ -620,16 +620,17 @@ static int sqlite3_do_callback(struct php_sqlite3_fci *fc, zval *cb, int argc, s
if (is_agg) {
/* summon the aggregation context */
- agg_context = (zval**)sqlite3_aggregate_context(context, sizeof(zval*));
- if (!*agg_context) {
- MAKE_STD_ZVAL(*agg_context);
- ZVAL_NULL(*agg_context);
+ agg_context = (php_sqlite3_agg_context *)sqlite3_aggregate_context(context, sizeof(php_sqlite3_agg_context));
+
+ if (!agg_context->zval_context) {
+ MAKE_STD_ZVAL(agg_context->zval_context);
+ ZVAL_NULL(agg_context->zval_context);
}
- zargs[0] = agg_context;
+ zargs[0] = &agg_context->zval_context;
zargs[1] = emalloc(sizeof(zval*));
MAKE_STD_ZVAL(*zargs[1]);
- ZVAL_LONG(*zargs[1], sqlite3_aggregate_count(context));
+ ZVAL_LONG(*zargs[1], agg_context->row_count);
}
for (i = 0; i < argc; i++) {
@@ -702,20 +703,20 @@ static int sqlite3_do_callback(struct php_sqlite3_fci *fc, zval *cb, int argc, s
sqlite3_result_error(context, "failed to invoke callback", 0);
}
- if (agg_context) {
- zval_ptr_dtor(agg_context);
+ if (agg_context && agg_context->zval_context) {
+ zval_ptr_dtor(&agg_context->zval_context);
}
} else {
/* we're stepping in an aggregate; the return value goes into
* the context */
- if (agg_context) {
- zval_ptr_dtor(agg_context);
+ if (agg_context && agg_context->zval_context) {
+ zval_ptr_dtor(&agg_context->zval_context);
}
if (retval) {
- *agg_context = retval;
+ agg_context->zval_context = retval;
retval = NULL;
} else {
- *agg_context = NULL;
+ agg_context->zval_context = NULL;
}
}
@@ -738,7 +739,10 @@ static void php_sqlite3_callback_func(sqlite3_context *context, int argc, sqlite
static void php_sqlite3_callback_step(sqlite3_context *context, int argc, sqlite3_value **argv) /* {{{ */
{
php_sqlite3_func *func = (php_sqlite3_func *)sqlite3_user_data(context);
+ php_sqlite3_agg_context *agg_context = (php_sqlite3_agg_context *)sqlite3_aggregate_context(context, sizeof(php_sqlite3_agg_context));
+
TSRMLS_FETCH();
+ agg_context->row_count++;
sqlite3_do_callback(&func->astep, func->step, argc, argv, context, 1 TSRMLS_CC);
}
@@ -747,7 +751,10 @@ static void php_sqlite3_callback_step(sqlite3_context *context, int argc, sqlite
static void php_sqlite3_callback_final(sqlite3_context *context) /* {{{ */
{
php_sqlite3_func *func = (php_sqlite3_func *)sqlite3_user_data(context);
+ php_sqlite3_agg_context *agg_context = (php_sqlite3_agg_context *)sqlite3_aggregate_context(context, sizeof(php_sqlite3_agg_context));
+
TSRMLS_FETCH();
+ agg_context->row_count = 0;
sqlite3_do_callback(&func->afini, func->fini, 0, NULL, context, 1 TSRMLS_CC);
}
diff --git a/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt b/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt
index 05913f89a9..6626ed687f 100644
--- a/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt
+++ b/ext/sqlite3/tests/sqlite3_25_create_aggregate.phpt
@@ -7,7 +7,7 @@ SQLite3::createAggregate() test
require_once(dirname(__FILE__) . '/new_db.inc');
-function sum_list_step($context, $num_args, $string) {
+function sum_list_step($context, $rows, $string) {
if (empty($context))
{
$context = array('total' => 0, 'values' => array());