summaryrefslogtreecommitdiff
path: root/ext/pdo_sqlite/sqlite_driver.c
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2019-06-12 11:28:07 +0200
committerNikita Popov <nikita.ppv@gmail.com>2019-06-12 11:54:12 +0200
commit1d8c323b64191873c9f06a3c4a3126eca97e3c05 (patch)
treedd435776dc4caae0e5487b4648bac8f6974281b7 /ext/pdo_sqlite/sqlite_driver.c
parent26a1b2e28e621923c7199862e5f0b5012537d91d (diff)
downloadphp-git-1d8c323b64191873c9f06a3c4a3126eca97e3c05.tar.gz
Don't use sqlite3_aggregate_count()
This function has been deprecated, with the recommendation that the count should be explicitly tracked in the aggregate context, if it is needed.
Diffstat (limited to 'ext/pdo_sqlite/sqlite_driver.c')
-rw-r--r--ext/pdo_sqlite/sqlite_driver.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c
index 9e86a82323..ab65049a96 100644
--- a/ext/pdo_sqlite/sqlite_driver.c
+++ b/ext/pdo_sqlite/sqlite_driver.c
@@ -309,6 +309,11 @@ static int pdo_sqlite_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
return 0;
}
+typedef struct {
+ zval val;
+ zend_long row;
+} aggregate_context;
+
static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
int argc, sqlite3_value **argv, sqlite3_context *context,
int is_agg)
@@ -318,7 +323,7 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
int i;
int ret;
int fake_argc;
- zend_reference *agg_context = NULL;
+ aggregate_context *agg_context = NULL;
if (is_agg) {
is_agg = 2;
@@ -339,18 +344,16 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
}
if (is_agg) {
- agg_context = (zend_reference*)sqlite3_aggregate_context(context, sizeof(zend_reference));
+ agg_context = sqlite3_aggregate_context(context, sizeof(aggregate_context));
if (!agg_context) {
- ZVAL_NULL(&zargs[0]);
- } else {
- if (Z_ISUNDEF(agg_context->val)) {
- GC_SET_REFCOUNT(agg_context, 1);
- GC_TYPE_INFO(agg_context) = IS_REFERENCE;
- ZVAL_NULL(&agg_context->val);
- }
- ZVAL_REF(&zargs[0], agg_context);
+ efree(zargs);
+ return FAILURE;
}
- ZVAL_LONG(&zargs[1], sqlite3_aggregate_count(context));
+ if (Z_ISUNDEF(agg_context->val)) {
+ ZVAL_NEW_REF(&agg_context->val, &EG(uninitialized_zval));
+ }
+ ZVAL_COPY_VALUE(&zargs[0], &agg_context->val);
+ ZVAL_LONG(&zargs[1], ++agg_context->row);
}
for (i = 0; i < argc; i++) {
@@ -429,13 +432,13 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
/* we're stepping in an aggregate; the return value goes into
* the context */
if (agg_context) {
- zval_ptr_dtor(&agg_context->val);
- }
- if (!Z_ISUNDEF(retval)) {
- ZVAL_COPY_VALUE(&agg_context->val, &retval);
+ if (Z_ISUNDEF(retval)) {
+ zval_ptr_dtor(&agg_context->val);
+ return FAILURE;
+ }
+ zval_ptr_dtor(Z_REFVAL(agg_context->val));
+ ZVAL_COPY_VALUE(Z_REFVAL(agg_context->val), &retval);
ZVAL_UNDEF(&retval);
- } else {
- ZVAL_UNDEF(&agg_context->val);
}
}