Add \PDO::SQLITE_ATTR_READONLY_STATEMENT

This attribute is a boolean value. It is taken from the return value of
sqlite3_stmt_readonly(), indicating if and only if the prepared statement makes
no direct changes to the content of the database.
This commit is contained in:
BohwaZ 2018-08-01 17:45:20 -04:00 committed by Adam Baratz
parent 1a303f1a2b
commit 6f9ebe677b
4 changed files with 45 additions and 1 deletions

View file

@ -350,6 +350,28 @@ static int pdo_sqlite_stmt_cursor_closer(pdo_stmt_t *stmt)
return 1;
}
static int pdo_sqlite_stmt_get_attribute(pdo_stmt_t *stmt, zend_long attr, zval *val)
{
pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
switch (attr) {
case PDO_SQLITE_ATTR_READONLY_STATEMENT:
ZVAL_FALSE(val);
#if SQLITE_VERSION_NUMBER >= 3007004
if (sqlite3_stmt_readonly(S->stmt)) {
ZVAL_TRUE(val);
}
#endif
break;
default:
return 0;
}
return 1;
}
const struct pdo_stmt_methods sqlite_stmt_methods = {
pdo_sqlite_stmt_dtor,
pdo_sqlite_stmt_execute,
@ -358,7 +380,7 @@ const struct pdo_stmt_methods sqlite_stmt_methods = {
pdo_sqlite_stmt_get_col,
pdo_sqlite_stmt_param_hook,
NULL, /* set_attr */
NULL, /* get_attr */
pdo_sqlite_stmt_get_attribute, /* get_attr */
pdo_sqlite_stmt_col_meta,
NULL, /* next_rowset */
pdo_sqlite_stmt_cursor_closer