summaryrefslogtreecommitdiff
path: root/ext/pdo_sqlite
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2017-03-12 17:04:02 +0100
committerNikita Popov <nikita.ppv@gmail.com>2017-03-12 17:04:02 +0100
commite31342ef843f98523722b2d37ea23190bf2781af (patch)
tree90012a557646b3a69617c1579b4ef0c4463269b4 /ext/pdo_sqlite
parent22e6b5ef220345bb187c93a293ee436a80f897d1 (diff)
parentfbf0e0587f8455525466e6d4ab2c1f0fc24bfe26 (diff)
downloadphp-git-e31342ef843f98523722b2d37ea23190bf2781af.tar.gz
Merge branch 'PHP-7.1'
Diffstat (limited to 'ext/pdo_sqlite')
-rw-r--r--ext/pdo_sqlite/pdo_sqlite.c2
-rw-r--r--ext/pdo_sqlite/sqlite_driver.c8
-rw-r--r--ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt38
3 files changed, 45 insertions, 3 deletions
diff --git a/ext/pdo_sqlite/pdo_sqlite.c b/ext/pdo_sqlite/pdo_sqlite.c
index c5bba02d07..621123b39a 100644
--- a/ext/pdo_sqlite/pdo_sqlite.c
+++ b/ext/pdo_sqlite/pdo_sqlite.c
@@ -69,6 +69,8 @@ ZEND_GET_MODULE(pdo_sqlite)
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(pdo_sqlite)
{
+ REGISTER_PDO_CLASS_CONST_LONG("SQLITE_DETERMINISTIC", (zend_long)SQLITE_DETERMINISTIC);
+
return php_pdo_register_driver(&pdo_sqlite_driver);
}
/* }}} */
diff --git a/ext/pdo_sqlite/sqlite_driver.c b/ext/pdo_sqlite/sqlite_driver.c
index c5fd54cfb4..1e3e071fef 100644
--- a/ext/pdo_sqlite/sqlite_driver.c
+++ b/ext/pdo_sqlite/sqlite_driver.c
@@ -505,7 +505,7 @@ static int php_sqlite3_collation_callback(void *context,
return ret;
}
-/* {{{ bool SQLite::sqliteCreateFunction(string name, mixed callback [, int argcount])
+/* {{{ bool SQLite::sqliteCreateFunction(string name, mixed callback [, int argcount, int flags])
Registers a UDF with the sqlite db handle */
static PHP_METHOD(SQLite, sqliteCreateFunction)
{
@@ -514,16 +514,18 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
char *func_name;
size_t func_name_len;
zend_long argc = -1;
+ zend_long flags = 0;
zend_string *cbname = NULL;
pdo_dbh_t *dbh;
pdo_sqlite_db_handle *H;
int ret;
- ZEND_PARSE_PARAMETERS_START(2, 3)
+ ZEND_PARSE_PARAMETERS_START(2, 4)
Z_PARAM_STRING(func_name, func_name_len)
Z_PARAM_ZVAL_DEREF(callback)
Z_PARAM_OPTIONAL
Z_PARAM_LONG(argc)
+ Z_PARAM_LONG(flags)
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
dbh = Z_PDO_DBH_P(getThis());
@@ -540,7 +542,7 @@ static PHP_METHOD(SQLite, sqliteCreateFunction)
func = (struct pdo_sqlite_func*)ecalloc(1, sizeof(*func));
- ret = sqlite3_create_function(H->db, func_name, argc, SQLITE_UTF8,
+ ret = sqlite3_create_function(H->db, func_name, argc, flags | SQLITE_UTF8,
func, php_sqlite3_func_callback, NULL, NULL);
if (ret == SQLITE_OK) {
func->funcname = estrdup(func_name);
diff --git a/ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt
new file mode 100644
index 0000000000..4f0b6754a1
--- /dev/null
+++ b/ext/pdo_sqlite/tests/pdo_sqlite_createfunction_with_flags.phpt
@@ -0,0 +1,38 @@
+--TEST--
+PDO_sqlite: Testing sqliteCreateFunction() with flags
+--SKIPIF--
+<?php if (!extension_loaded('pdo_sqlite')) print 'skip not loaded'; ?>
+--FILE--
+<?php
+
+$db = new pdo('sqlite::memory:');
+
+$db->query('CREATE TABLE IF NOT EXISTS foobar (id INT AUTO INCREMENT, name TEXT)');
+
+$db->query('INSERT INTO foobar VALUES (NULL, "PHP")');
+$db->query('INSERT INTO foobar VALUES (NULL, "PHP6")');
+
+
+$db->sqliteCreateFunction('testing', function($v) { return strtolower($v); }, 1, PDO::SQLITE_DETERMINISTIC);
+
+
+foreach ($db->query('SELECT testing(name) FROM foobar') as $row) {
+ var_dump($row);
+}
+
+$db->query('DROP TABLE foobar');
+
+?>
+--EXPECTF--
+array(2) {
+ ["testing(name)"]=>
+ string(3) "php"
+ [0]=>
+ string(3) "php"
+}
+array(2) {
+ ["testing(name)"]=>
+ string(4) "php6"
+ [0]=>
+ string(4) "php6"
+}