Issue #3186934 by mondrake, daffie, donquixote, alexpott: Introduce an...
Issue #3186934 by mondrake, daffie, donquixote, alexpott: Introduce an ExceptionHandler class in the database API, deprecate Connection::handleQueryException
thrownewDatabaseExceptionWrapper("Statement preparation failure for query: $query");
}
return$statement;
}
/**
* Prepares a query string and returns the prepared statement.
@@ -793,21 +808,10 @@ public function query($query, array $args = [], $options = []) {
$options+=$this->defaultOptions();
assert(!isset($options['target']),'Passing "target" option to query() has no effect. See https://www.drupal.org/node/2993033');
try{
// We allow either a pre-bound statement object (deprecated) or a literal
// string. In either case, we want to end up with an executed statement
// object, which we pass to PDOStatement::execute.
if($queryinstanceofStatementInterface){
@trigger_error('Passing a StatementInterface object as a $query argument to '.__METHOD__.' is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439',E_USER_DEPRECATED);
$stmt=$query;
$stmt->execute(NULL,$options);
}
elseif($queryinstanceof\PDOStatement){
@trigger_error('Passing a \\PDOStatement object as a $query argument to '.__METHOD__.' is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439',E_USER_DEPRECATED);
$stmt=$query;
$stmt->execute();
}
else{
// object, which we pass to StatementInterface::execute.
if(is_string($query)){
$this->expandArguments($query,$args);
// To protect against SQL injection, Drupal only supports executing one
// statement at a time. Thus, the presence of a SQL delimiter (the
@@ -824,8 +828,26 @@ public function query($query, array $args = [], $options = []) {
thrownew\InvalidArgumentException('; is not supported in SQL strings. Use only one statement at a time.');
}
$stmt=$this->prepareStatement($query,$options);
}
elseif($queryinstanceofStatementInterface){
@trigger_error('Passing a StatementInterface object as a $query argument to '.__METHOD__.' is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439',E_USER_DEPRECATED);
$stmt=$query;
}
elseif($queryinstanceof\PDOStatement){
@trigger_error('Passing a \\PDOStatement object as a $query argument to '.__METHOD__.' is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Call the execute method from the StatementInterface object directly instead. See https://www.drupal.org/node/3154439',E_USER_DEPRECATED);
$stmt=$query;
}
try{
if(is_string($query)){
$stmt->execute($args,$options);
}
elseif($queryinstanceofStatementInterface){
$stmt->execute(NULL,$options);
}
elseif($queryinstanceof\PDOStatement){
$stmt->execute();
}
// Depending on the type of query we may need to return a different value.
// See DatabaseConnection::defaultOptions() for a description of each
@@ -847,15 +869,21 @@ public function query($query, array $args = [], $options = []) {
@trigger_error('Connection::handleQueryException() is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Get a handler through $this->exceptionHandler() instead, and use one of its methods. See https://www.drupal.org/node/3187222',E_USER_DEPRECATED);
if($options['throw_exception']){
// Wrap the exception in another exception, because PHP does not allow
// overriding Exception::getMessage(). Its message is the extra database
@@ -999,6 +1034,10 @@ public function getDriverClass($class) {
@trigger_error('Connection::handleQueryException() is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Get a handler through $this->exceptionHandler() instead, and use one of its methods. See https://www.drupal.org/node/3187222',E_USER_DEPRECATED);
@trigger_error('Connection::handleQueryException() is deprecated in drupal:9.2.0 and is removed in drupal:10.0.0. Get a handler through $this->exceptionHandler() instead, and use one of its methods. See https://www.drupal.org/node/3187222',E_USER_DEPRECATED);