Skip to content

Commit 224a680

Browse files
committed
less heavy approach
1 parent 466ddc8 commit 224a680

File tree

2 files changed

+47
-37
lines changed

2 files changed

+47
-37
lines changed

ext/pdo_sqlite/config.m4

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,38 @@ if test "$PHP_PDO_SQLITE" != "no"; then
3232
https://www.sqlite.org/compile.html.])],
3333
[$PDO_SQLITE_SHARED_LIBADD])
3434

35+
AC_CACHE_CHECK([checking sqlite3_stmt_explain support],
36+
[php_cv_have_stmt_explain],
37+
[AC_RUN_IFELSE([AC_LANG_SOURCE([[
38+
#include <sqlite3.h>
39+
#if defined(__APPLE__)
40+
#include <Availability.h>
41+
#endif
42+
43+
int main(void) {
44+
#if SQLITE_VERSION_NUMBER >= 3041000
45+
#if defined(__APPLE__)
46+
if (__builtin_available(macOS 14.2, *)) {
47+
#endif
48+
(void)sqlite3_stmt_explain(NULL, 0);
49+
return 0;
50+
#if defined(__APPLE__)
51+
} else {
52+
return 1;
53+
}
54+
#endif
55+
#else
56+
return 1;
57+
#endif
58+
}
59+
]])],
60+
[php_cv_have_stmt_explain=no],
61+
[php_cv_have_stmt_explain=yes],
62+
[php_cv_have_stmt_explain=no])])
63+
AS_VAR_IF([php_cv_have_stmt_explain], [yes],
64+
[AC_DEFINE([HAVE_SQLITE3_STMT_EXPLAIN], [1],
65+
[Define to 1 if sqlite3_stmt_explain is supported.])])
66+
3567
PHP_SUBST([PDO_SQLITE_SHARED_LIBADD])
3668
PHP_NEW_EXTENSION([pdo_sqlite],
3769
[pdo_sqlite.c sqlite_driver.c sqlite_statement.c sqlite_sql_parser.c],

ext/pdo_sqlite/sqlite_statement.c

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
#include "php_pdo_sqlite.h"
2727
#include "php_pdo_sqlite_int.h"
2828

29-
#if defined(__APPLE__)
30-
#include <Availability.h>
31-
#endif
32-
3329
static int pdo_sqlite_stmt_dtor(pdo_stmt_t *stmt)
3430
{
3531
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
@@ -391,18 +387,9 @@ static int pdo_sqlite_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval
391387
}
392388
break;
393389
case PDO_SQLITE_ATTR_EXPLAIN_STATEMENT:
394-
#if SQLITE_VERSION_NUMBER >= 3041000
395-
#if defined(__APPLE__)
396-
if (__builtin_available(macOS 14.2, *)) {
397-
#endif
398-
ZVAL_LONG(val, (zend_long)sqlite3_stmt_isexplain(S->stmt));
399-
return 1;
400-
#if defined(__APPLE__)
401-
} else {
402-
zend_value_error("explain statement unsupported");
403-
return 0;
404-
}
405-
#endif
390+
#if defined(HAVE_SQLITE3_STMT_EXPLAIN)
391+
ZVAL_LONG(val, (zend_long)sqlite3_stmt_isexplain(S->stmt));
392+
return 1;
406393
#else
407394
zend_value_error("explain statement unsupported");
408395
return 0;
@@ -420,29 +407,20 @@ static int pdo_sqlite_stmt_set_attribute(pdo_stmt_t *stmt, zend_long attr, zval
420407

421408
switch (attr) {
422409
case PDO_SQLITE_ATTR_EXPLAIN_STATEMENT:
423-
#if SQLITE_VERSION_NUMBER >= 3041000
424-
#if defined(__APPLE__)
425-
if (__builtin_available(macOS 14.2, *)) {
426-
#endif
427-
if (Z_TYPE_P(zval) != IS_LONG) {
428-
zend_type_error("explain mode must be of type int");
429-
return 0;
430-
}
431-
if (Z_TYPE_P(zval) < 0 || Z_TYPE_P(zval) > 2) {
432-
zend_value_error("explain mode must be one of the EXPLAIN_MODE_* constants");
433-
return 0;
434-
}
435-
if (sqlite3_stmt_explain(S->stmt, (int)Z_LVAL_P(zval)) != SQLITE_OK) {
436-
return 0;
437-
}
438-
439-
return 1;
440-
#if defined(__APPLE__)
441-
} else {
442-
zend_value_error("explain statement unsupported");
410+
#if defined(HAVE_SQLITE3_STMT_EXPLAIN)
411+
if (Z_TYPE_P(zval) != IS_LONG) {
412+
zend_type_error("explain mode must be of type int");
443413
return 0;
444414
}
445-
#endif
415+
if (Z_TYPE_P(zval) < 0 || Z_TYPE_P(zval) > 2) {
416+
zend_value_error("explain mode must be one of the EXPLAIN_MODE_* constants");
417+
return 0;
418+
}
419+
if (sqlite3_stmt_explain(S->stmt, (int)Z_LVAL_P(zval)) != SQLITE_OK) {
420+
return 0;
421+
}
422+
423+
return 1;
446424
#else
447425
zend_value_error("explain statement unsupported");
448426
return 0;

0 commit comments

Comments
 (0)