Skip to content

Pdo sqlite refactor #18804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ PHP 8.5 UPGRADE NOTES
IntlListFormatter::WIDTH_NARROW widths.
It is supported from icu 67.

- PDO_Sqlite:
. Added class constant Pdo_Sqlite::ATTR_BUSY_STATEMENT.

- SOAP:
. Enumeration cases are now dumped in __getTypes().

Expand Down Expand Up @@ -424,6 +427,9 @@ PHP 8.5 UPGRADE NOTES
- PCRE:
. Upgraded to pcre2lib from 10.44 to 10.45.

- PDO_Sqlite:
. Increased minimum release version support from 3.7.7 to 3.7.17.

- Readline:
. The return types of readline_add_history(), readline_clear_history(), and
readline_callback_handler_install() have been changed to true, rather
Expand Down
2 changes: 1 addition & 1 deletion build/php.m4
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ dnl
dnl Common setup macro for SQLite library.
dnl
AC_DEFUN([PHP_SETUP_SQLITE], [
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.7], [
PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.17], [
Copy link
Member

Choose a reason for hiding this comment

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

Strictly speaking this requires an upgrading entry.

Copy link
Member

Choose a reason for hiding this comment

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

Similarly, your newly added constants need upgrading entries

PHP_EVAL_INCLINE([$SQLITE_CFLAGS])
PHP_EVAL_LIBLINE([$SQLITE_LIBS], [$1])
])
Expand Down
10 changes: 3 additions & 7 deletions ext/pdo_sqlite/pdo_sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,10 @@ static int php_sqlite_collation_callback(void *context, int string1_len, const v
zend_type_error("%s(): Return value of the collation callback must be of type int, %s returned",
ZSTR_VAL(func_name), zend_zval_value_name(&retval));
zend_string_release(func_name);
ret = FAILURE;
zval_ptr_dtor(&retval);
return FAILURE;
}
if (Z_LVAL(retval) > 0) {
ret = 1;
} else if (Z_LVAL(retval) < 0) {
ret = -1;
}
zval_ptr_dtor(&retval);
ret = ZEND_NORMALIZE_BOOL(Z_LVAL(retval));
}

return ret;
Expand Down
3 changes: 3 additions & 0 deletions ext/pdo_sqlite/pdo_sqlite.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class Sqlite extends \PDO
/** @cvalue PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES */
public const int ATTR_EXTENDED_RESULT_CODES = UNKNOWN;

/** @cvalue PDO_SQLITE_ATTR_BUSY_STATEMENT */
public const int ATTR_BUSY_STATEMENT = UNKNOWN;

/** @cvalue SQLITE_OK */
public const int OK = UNKNOWN;

Expand Down
8 changes: 7 additions & 1 deletion ext/pdo_sqlite/pdo_sqlite_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ext/pdo_sqlite/php_pdo_sqlite_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ extern const struct pdo_stmt_methods sqlite_stmt_methods;
enum {
PDO_SQLITE_ATTR_OPEN_FLAGS = PDO_ATTR_DRIVER_SPECIFIC,
PDO_SQLITE_ATTR_READONLY_STATEMENT,
PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES
PDO_SQLITE_ATTR_EXTENDED_RESULT_CODES,
PDO_SQLITE_ATTR_BUSY_STATEMENT
};

typedef int pdo_sqlite_create_collation_callback(void*, int, const void*, int, const void*);
Expand Down
10 changes: 3 additions & 7 deletions ext/pdo_sqlite/sqlite_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,10 @@ static int php_sqlite3_collation_callback(void *context, int string1_len, const
zend_type_error("%s(): Return value of the collation callback must be of type int, %s returned",
ZSTR_VAL(func_name), zend_zval_value_name(&retval));
zend_string_release(func_name);
ret = FAILURE;
}
if (Z_LVAL(retval) > 0) {
ret = 1;
} else if (Z_LVAL(retval) < 0) {
ret = -1;
zval_ptr_dtor(&retval);
return FAILURE;
}
zval_ptr_dtor(&retval);
ret = ZEND_NORMALIZE_BOOL(Z_LVAL(retval));
}

return ret;
Expand Down
15 changes: 10 additions & 5 deletions ext/pdo_sqlite/sqlite_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,18 @@ static int pdo_sqlite_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval
case PDO_SQLITE_ATTR_READONLY_STATEMENT:
ZVAL_FALSE(val);

#if SQLITE_VERSION_NUMBER >= 3007004
if (sqlite3_stmt_readonly(S->stmt)) {
ZVAL_TRUE(val);
}
#endif
if (sqlite3_stmt_readonly(S->stmt)) {
ZVAL_TRUE(val);
}
break;

case PDO_SQLITE_ATTR_BUSY_STATEMENT:
ZVAL_FALSE(val);

if (sqlite3_stmt_busy(S->stmt)) {
ZVAL_TRUE(val);
}
break;
default:
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions ext/pdo_sqlite/tests/subclasses/pdo_sqlite_constants.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var_dump(Pdo\Sqlite::OPEN_READWRITE);
var_dump(Pdo\Sqlite::OPEN_CREATE);
var_dump(Pdo\Sqlite::ATTR_READONLY_STATEMENT);
var_dump(Pdo\Sqlite::ATTR_EXTENDED_RESULT_CODES);
var_dump(Pdo\Sqlite::ATTR_BUSY_STATEMENT);

?>
--EXPECTF--
Expand All @@ -24,3 +25,4 @@ int(%d)
int(%d)
int(%d)
int(%d)
int(%d)
19 changes: 19 additions & 0 deletions ext/pdo_sqlite/tests/subclasses/pdo_sqlite_getattr_busy.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Pdo\Sqlite::ATTR_BUSY_STATEMENT usage
--EXTENSIONS--
pdo_sqlite
--FILE--
<?php

$db = new Pdo\Sqlite('sqlite::memory:');

$db->query('CREATE TABLE test_busy (a string);');
$db->query('INSERT INTO test_busy VALUES ("interleaved"), ("statements")');
$st = $db->prepare('SELECT a FROM test_busy');
var_dump($st->getAttribute(Pdo\Sqlite::ATTR_BUSY_STATEMENT));
$st->execute();
var_dump($st->getAttribute(Pdo\Sqlite::ATTR_BUSY_STATEMENT));
?>
--EXPECTF--
bool(false)
bool(true)