This repository has been archived by the owner on Sep 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Fix SQLite scroll cursors fail #36
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -116,7 +116,7 @@ protected function setConnection(\PDO $connection) | |
/** | ||
* Get the connection instance. | ||
* | ||
* @return PDO | ||
* @return \PDO | ||
* @throws \Hoa\Database\Exception | ||
*/ | ||
protected function getConnection() | ||
|
@@ -194,7 +194,12 @@ public function lastInsertId($name = null) | |
public function prepare($statement, array $options = []) | ||
{ | ||
if (!isset($options[\PDO::ATTR_CURSOR])) { | ||
$options[\PDO::ATTR_CURSOR] = \PDO::CURSOR_SCROLL; | ||
try { | ||
$this->getConnection()->getAttribute(\PDO::ATTR_CURSOR); | ||
$options[\PDO::ATTR_CURSOR] = \PDO::CURSOR_SCROLL; | ||
} catch (\PDOException $e) { | ||
// Cursors isn't supported by the driver, see issue #35. | ||
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. - isn't
+ are not Fixed by me. |
||
} | ||
} | ||
|
||
$handle = $this->getConnection()->prepare($statement, $options); | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
"hoa/event" : "~1.0", | ||
"hoa/exception" : "~1.0", | ||
"hoa/iterator" : "~2.0", | ||
"hoa/protocol" : "~1.0", | ||
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. 👍 |
||
"hoa/zformat" : "~1.0", | ||
"ext-pdo" : "*" | ||
}, | ||
|
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.
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.
Actually, the
ATTR_CURSOR
is supported, but not theCURSOR_SCROLL
value.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.
Did you try with this branch ?
I had the same error as you and this patch fix it (with sqlite3 on win10 x64)
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.
Hmm, I will try. However, iterator support will no be longer be available if scroll cursor is not enabled. Should we throw an error then?
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.
Also, if this patch works, then this is a bug in PDO with SQLite driver and we should open a bug on bugs.php.net, do you agree?
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.
Yes.
Forward only iterator will be available. Scrollable cursor is used to customize the fetch orientation.
Throw an error if the user want to use a feature which is not supported by the driver is interesting but we have to re-think the way we prepare our statement.
Currently we enable the scroll cursor before the user has chosen if he want to use the feature so we can't throw an error according to his choice.
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.
Agree with your strategy. Are you willing to do a PR?