-
-
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
Extract Result from the Statement interface #4045
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
morozov
force-pushed
the
split-statement-result
branch
2 times, most recently
from
June 2, 2020 22:06
f04bced
to
3ed62db
Compare
|
greg0ire
reviewed
Jun 3, 2020
morozov
force-pushed
the
split-statement-result
branch
from
June 8, 2020 22:24
3ed62db
to
db3d72d
Compare
Codecov Report
@@ Coverage Diff @@
## 3.0.x #4045 +/- ##
============================================
+ Coverage 78.01% 78.09% +0.07%
+ Complexity 4616 4603 -13
============================================
Files 181 189 +8
Lines 11579 11552 -27
============================================
- Hits 9033 9021 -12
+ Misses 2546 2531 -15
Continue to review full report at Codecov.
|
morozov
force-pushed
the
split-statement-result
branch
from
June 9, 2020 05:23
db3d72d
to
0e74935
Compare
morozov
force-pushed
the
split-statement-result
branch
from
June 9, 2020 05:30
0e74935
to
48625f1
Compare
greg0ire
approved these changes
Jun 9, 2020
Merged
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Rationale
The
Statement
interface currently fulfills two roles: “statement execution” and “fetching the resulting data and metadata”. There are certain problems with this approach:dbal/src/Driver/Mysqli/MysqliStatement.php
Lines 307 to 311 in 96f8cab
dbal/tests/Functional/Schema/SqliteSchemaManagerTest.php
Lines 275 to 276 in b0ca943
Portability\Statement
that have to deal with the statement in its different phases have to depend on union types:dbal/src/Portability/Statement.php
Lines 15 to 16 in 7204a7d
dbal/src/Portability/Statement.php
Line 37 in 7204a7d
Summary of the changes
Statement
interface no longer extendsResultStatement
ResultStatement
interface has been renamed toResult
.bool
(orvoid
inmaster
), the query-related methods now explicitly return aResult
.Result
interface and its implementors have been reordered as “fetching data”, “fetching metadata”, “close” from most to least commonly used and more or less corresponding to the statement result lifecycle.Abstraction
package is introduced for abstraction-level interfaces. Currently, only theResult
interface is available. TheConnection
and theStatement
ones are to follow.Additional benefits
testFetchFromNonExecutedStatement()
,testCloseCursorAfterCursorEnd()
andtestFetchFromNonExecutedStatementWithClosedCursor()
tests and had to be handled at runtime are no longer possible by design.$conn->prepare($sql)->execute($params)->fetch()
;Implementation details
ArrayStatement
has been renamed toArrayResult
.ResultCacheStatement
has been renamed toCachingResult
.Statement::testPrepareWithIterator()
had to and could be reworked but was deleted instead since it doesn't cover any special case (binding parameters and iteration over the statement are orthogonal and don't need to be tested together).Discoveries (future scope)
Connection
class extends the DBAL connection. It leads to the double wrapping of the abstraction-level result into a driver-level portable result and then again into an abstraction-level result to fulfill the API contract. This can be avoided if the layer is moved to the driver level completely.Connection
class can be made a driver-level wrapper to simplify the code.query()
asprepare()->execute()
. While it's valid, it's suboptimal for those drivers that implementquery()
natively (mysqli
,sqlsrv
). It takes only one TCP round-trip to execute a query and three to prepare a statement, execute it and discard the handle.Questions
Given that the newfetchColumn()
is now called on a result instead of the statement, it's no longer a silent change in an existing method’s semantics. Can we use this name instead of having to usefetchFirstColumn()
?We could if we provided an upgrade path in
2.11.x
but it wasn't possible.Should we renamecloseCursor()
to something likefree()
? A “free” procedure is called by themysqli
andibm_db2
implementations internally and seems more applicable to a result.Done.
TODO:
2.11.x
(Replace forward-compatible ResultStatement interfaces with Result #4049).UPGRADE.md
.