Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ext/pdo_sqlite/sqlite_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,11 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
/* get the value */
switch (sqlite3_value_type(argv[i])) {
case SQLITE_INTEGER:
#if ZEND_LONG_MAX > 2147483647

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use #ifdef ZEND_ENABLE_ZVAL_LONG64 instead (below too)

ZVAL_LONG(&zargs[i + is_agg], sqlite3_value_int64(argv[i]));
#else
ZVAL_LONG(&zargs[i + is_agg], sqlite3_value_int(argv[i]));
#endif
break;

case SQLITE_FLOAT:
Expand Down Expand Up @@ -410,7 +414,11 @@ static int do_callback(struct pdo_sqlite_fci *fc, zval *cb,
if (!Z_ISUNDEF(retval)) {
switch (Z_TYPE(retval)) {
case IS_LONG:
#if ZEND_LONG_MAX > 2147483647
sqlite3_result_int64(context, Z_LVAL(retval));
#else
sqlite3_result_int(context, Z_LVAL(retval));
#endif
break;

case IS_NULL:
Expand Down
28 changes: 28 additions & 0 deletions ext/pdo_sqlite/tests/gh25021-udf.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
GH-25021 UDF isn't using sqlite3_*_int64 API

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GH-25021 UDF isn't using sqlite3_*_int64 API
GH-25021 (UDF isn't using sqlite3_*_int64 API)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some names are formatted this way, some are not, why?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because people are inconsistent

--EXTENSIONS--
pdo_sqlite
--FILE--
<?php

$conn = new PDO('sqlite::memory:');

$conn->sqliteCreateFunction('my_udf_pass_int', static fn(int $v): int => $v);

foreach ([
10,
PHP_INT_MIN,
PHP_INT_MAX,
] as $v) {
$stmt = $conn->prepare('select my_udf_pass_int(:v)');
$stmt->bindValue(':v', $v, PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->fetch();

var_dump($result[0] === $v);
}
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
27 changes: 27 additions & 0 deletions ext/sqlite3/tests/gh25021-udf.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
GH-25021 UDF isn't using sqlite3_*_int64 API

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
GH-25021 UDF isn't using sqlite3_*_int64 API
GH-25021 (UDF isn't using sqlite3_*_int64 API)

--EXTENSIONS--
sqlite3
--FILE--
<?php

$conn = new SQLite3(':memory:');

$conn->createFunction('my_udf_pass_int', static fn(int $v): int => $v);

foreach ([
10,
PHP_INT_MIN,
PHP_INT_MAX,
] as $v) {
$stmt = $conn->prepare('select my_udf_pass_int(:v)');
$stmt->bindValue(':v', $v, SQLITE3_INTEGER);
$result = $stmt->execute()->fetchArray();

var_dump($result[0] === $v);
}
?>
--EXPECT--
bool(true)
bool(true)
bool(true)
Loading