-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Predictable QueryBuilder::executeQuery()
and QueryBuilder::executeStatement()
#4578
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -300,19 +300,57 @@ public function fetchFirstColumn(): array | |
return $this->connection->fetchFirstColumn($this->getSQL(), $this->params, $this->paramTypes); | ||
} | ||
|
||
/** | ||
* Executes an SQL query (SELECT) and returns a Result. | ||
* | ||
* @throws Exception | ||
*/ | ||
public function executeQuery(): Result | ||
{ | ||
return $this->connection->executeQuery($this->getSQL(), $this->params, $this->paramTypes); | ||
} | ||
|
||
/** | ||
* Executes an SQL statement and returns the number of affected rows. | ||
* | ||
* Should be used for INSERT, UPDATE and DELETE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not limited to DML ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Idem, the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, you're right. |
||
* | ||
* @return int The number of affected rows. | ||
* | ||
* @throws Exception | ||
*/ | ||
public function executeStatement(): int | ||
{ | ||
return $this->connection->executeStatement($this->getSQL(), $this->params, $this->paramTypes); | ||
} | ||
|
||
/** | ||
* Executes this query using the bound parameters and their types. | ||
* | ||
* @deprecated Use {@link executeQuery()} or {@link executeStatement()} instead. | ||
* | ||
* @return Result|int | ||
* | ||
* @throws Exception | ||
*/ | ||
public function execute() | ||
{ | ||
if ($this->type === self::SELECT) { | ||
Deprecation::trigger( | ||
'doctrine/dbal', | ||
'https://github.com/doctrine/dbal/pull/4578', | ||
'QueryBuilder::execute() is deprecated, use QueryBuilder::executeQuery() for SQL queries instead.' | ||
); | ||
|
||
return $this->connection->executeQuery($this->getSQL(), $this->params, $this->paramTypes); | ||
} | ||
|
||
Deprecation::trigger( | ||
'doctrine/dbal', | ||
'https://github.com/doctrine/dbal/pull/4578', | ||
'QueryBuilder::execute() is deprecated, use QueryBuilder::executeStatement() for SQL statements instead.' | ||
); | ||
|
||
return $this->connection->executeStatement($this->getSQL(), $this->params, $this->paramTypes); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be misleading since it works also for
DESCRIBE
,SHOW
and so on. Let's rephrase to:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd agree with that on the
Connection
class, but AFAIK, there is no way to build anything else than aSELECT
query with aQueryBuilder
. So I don't think we should document an impossible use-case.WDYT ?
see:
dbal/src/Query/QueryBuilder.php
Lines 40 to 46 in 461b3b7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I didn't take the scope into account. Sorry for the confusion.