Skip to content

Commit 1afcced

Browse files
committed
Add stubs for PDO SQLite extension methods
Putting these under a dummy PDO_SQLite_Ext class.
1 parent 047474c commit 1afcced

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

ext/pdo_sqlite/sqlite_driver.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "php_pdo_sqlite.h"
2727
#include "php_pdo_sqlite_int.h"
2828
#include "zend_exceptions.h"
29+
#include "sqlite_driver_arginfo.h"
2930

3031
int _pdo_sqlite_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line) /* {{{ */
3132
{
@@ -516,7 +517,7 @@ static int php_sqlite3_collation_callback(void *context,
516517

517518
/* {{{ bool SQLite::sqliteCreateFunction(string name, callable callback [, int argcount, int flags])
518519
Registers a UDF with the sqlite db handle */
519-
static PHP_METHOD(SQLite, sqliteCreateFunction)
520+
PHP_METHOD(PDO_SQLite_Ext, sqliteCreateFunction)
520521
{
521522
struct pdo_sqlite_func *func;
522523
zend_fcall_info fci;
@@ -583,7 +584,7 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
583584
aggregate UDF.
584585
*/
585586

586-
static PHP_METHOD(SQLite, sqliteCreateAggregate)
587+
PHP_METHOD(PDO_SQLite_Ext, sqliteCreateAggregate)
587588
{
588589
struct pdo_sqlite_func *func;
589590
zend_fcall_info step_fci, fini_fci;
@@ -634,7 +635,7 @@ static PHP_METHOD(SQLite, sqliteCreateAggregate)
634635

635636
/* {{{ bool SQLite::sqliteCreateCollation(string name, callable callback)
636637
Registers a collation with the sqlite db handle */
637-
static PHP_METHOD(SQLite, sqliteCreateCollation)
638+
PHP_METHOD(PDO_SQLite_Ext, sqliteCreateCollation)
638639
{
639640
struct pdo_sqlite_collation *collation;
640641
zend_fcall_info fci;
@@ -674,18 +675,11 @@ static PHP_METHOD(SQLite, sqliteCreateCollation)
674675
}
675676
/* }}} */
676677

677-
static const zend_function_entry dbh_methods[] = {
678-
PHP_ME(SQLite, sqliteCreateFunction, NULL, ZEND_ACC_PUBLIC)
679-
PHP_ME(SQLite, sqliteCreateAggregate, NULL, ZEND_ACC_PUBLIC)
680-
PHP_ME(SQLite, sqliteCreateCollation, NULL, ZEND_ACC_PUBLIC)
681-
PHP_FE_END
682-
};
683-
684678
static const zend_function_entry *get_driver_methods(pdo_dbh_t *dbh, int kind)
685679
{
686680
switch (kind) {
687681
case PDO_DBH_DRIVER_METHOD_KIND_DBH:
688-
return dbh_methods;
682+
return class_PDO_SQLite_Ext_methods;
689683

690684
default:
691685
return NULL;

ext/pdo_sqlite/sqlite_driver.stub.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/** @generate-function-entries */
4+
5+
// These are extension methods for PDO. This is not a real class.
6+
class PDO_SQLite_Ext {
7+
/** @return bool */
8+
public function sqliteCreateFunction(string $function_name, callable $callback, int $num_args = -1, int $flags = 0) {}
9+
10+
/** @return bool */
11+
public function sqliteCreateAggregate(string $function_name, callable $step_func, callable $finalize_func, int $num_args = -1) {}
12+
13+
/** @return bool */
14+
public function sqliteCreateCollation(string $name, callable $callback) {}
15+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* This is a generated file, edit the .stub.php file instead.
2+
* Stub hash: 5134a0b80848f852557b1c22ec102573d79ed9a4 */
3+
4+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_SQLite_Ext_sqliteCreateFunction, 0, 0, 2)
5+
ZEND_ARG_TYPE_INFO(0, function_name, IS_STRING, 0)
6+
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
7+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, num_args, IS_LONG, 0, "-1")
8+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
9+
ZEND_END_ARG_INFO()
10+
11+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_SQLite_Ext_sqliteCreateAggregate, 0, 0, 3)
12+
ZEND_ARG_TYPE_INFO(0, function_name, IS_STRING, 0)
13+
ZEND_ARG_TYPE_INFO(0, step_func, IS_CALLABLE, 0)
14+
ZEND_ARG_TYPE_INFO(0, finalize_func, IS_CALLABLE, 0)
15+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, num_args, IS_LONG, 0, "-1")
16+
ZEND_END_ARG_INFO()
17+
18+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PDO_SQLite_Ext_sqliteCreateCollation, 0, 0, 2)
19+
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
20+
ZEND_ARG_TYPE_INFO(0, callback, IS_CALLABLE, 0)
21+
ZEND_END_ARG_INFO()
22+
23+
24+
ZEND_METHOD(PDO_SQLite_Ext, sqliteCreateFunction);
25+
ZEND_METHOD(PDO_SQLite_Ext, sqliteCreateAggregate);
26+
ZEND_METHOD(PDO_SQLite_Ext, sqliteCreateCollation);
27+
28+
29+
static const zend_function_entry class_PDO_SQLite_Ext_methods[] = {
30+
ZEND_ME(PDO_SQLite_Ext, sqliteCreateFunction, arginfo_class_PDO_SQLite_Ext_sqliteCreateFunction, ZEND_ACC_PUBLIC)
31+
ZEND_ME(PDO_SQLite_Ext, sqliteCreateAggregate, arginfo_class_PDO_SQLite_Ext_sqliteCreateAggregate, ZEND_ACC_PUBLIC)
32+
ZEND_ME(PDO_SQLite_Ext, sqliteCreateCollation, arginfo_class_PDO_SQLite_Ext_sqliteCreateCollation, ZEND_ACC_PUBLIC)
33+
ZEND_FE_END
34+
};

ext/pdo_sqlite/tests/pdo_sqlite_createaggregate_002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ try {
2020

2121
?>
2222
--EXPECT--
23-
PDO::sqliteCreateAggregate(): Argument #2 must be a valid callback, function "a" not found or invalid function name
24-
PDO::sqliteCreateAggregate(): Argument #3 must be a valid callback, function "" not found or invalid function name
23+
PDO::sqliteCreateAggregate(): Argument #2 ($step_func) must be a valid callback, function "a" not found or invalid function name
24+
PDO::sqliteCreateAggregate(): Argument #3 ($finalize_func) must be a valid callback, function "" not found or invalid function name

ext/pdo_sqlite/tests/pdo_sqlite_createfunction_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ try {
1818

1919
?>
2020
--EXPECT--
21-
PDO::sqliteCreateFunction(): Argument #2 must be a valid callback, function "bar" not found or invalid function name
21+
PDO::sqliteCreateFunction(): Argument #2 ($callback) must be a valid callback, function "bar" not found or invalid function name

0 commit comments

Comments
 (0)