-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Deallocate prepared statements #6665
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
Merged
kenjis
merged 20 commits into
codeigniter4:4.3
from
fpoy:FEAT_deallocate_prepared_statements
Oct 17, 2022
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
d0df1e2
feat: Abstract method and database dependants versions of the "close"…
fpoy 7e244b3
test: add test for deallocation of prepared query
fpoy ce3b698
docs: remove todo comment
fpoy 63d50b4
fix: escape identifier for Postgre's DEALLOCATE statement
fpoy 344bc6f
fix: Undefined property: CodeIgniter\Database\OCI8\PreparedQuery::$st…
fpoy 7a4017f
fix: Removes recasting of the same type
fpoy 1523d83
docs: add breaking change to the changelog
fpoy a4f09b1
docs: add enhancement the changelog
fpoy 072a620
docs: add inline markup for close() method
fpoy 78ae90d
fix: change the visibility of close() to "protected"
fpoy 0b6e0e4
refactor: move duplication in the implementations of _close() to the …
fpoy 5f482d1
typo: database-dependent
fpoy 82e37fd
refactor: if pg_query() returns an object, _close returns true
fpoy 3b7465f
docs: complete the example query with the error return
fpoy 77377a7
fix: return BadMethodCallException when trying to close a non-existin…
fpoy 78a34c9
tests: use expectException() for unit-tests, not try/catch
fpoy dbe460e
fix: do not unset statement after closing it, instead set to null
fpoy f859e46
docs: add @throws statement in the docblock of close()
fpoy 2f5bce7
fix phpstan after rebase
fpoy 1a72ba8
test: remove spurious null check in unit test
fpoy 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
namespace CodeIgniter\Database\Live; | ||
|
||
use BadMethodCallException; | ||
use CodeIgniter\Database\BasePreparedQuery; | ||
use CodeIgniter\Database\Exceptions\DatabaseException; | ||
use CodeIgniter\Database\Query; | ||
|
@@ -41,8 +42,10 @@ protected function tearDown(): void | |
{ | ||
parent::tearDown(); | ||
|
||
if ($this->query !== null) { | ||
try { | ||
$this->query->close(); | ||
} catch (BadMethodCallException $e) { | ||
$this->query = null; | ||
} | ||
} | ||
|
||
|
@@ -148,4 +151,38 @@ public function testExecuteRunsInvalidQuery() | |
|
||
$this->query->execute('foo', '[email protected]', 'US'); | ||
} | ||
|
||
public function testDeallocatePreparedQueryThenTryToExecute() | ||
{ | ||
$this->query = $this->db->prepare(static fn ($db) => $db->table('user')->insert([ | ||
'name' => 'a', | ||
'email' => '[email protected]', | ||
'country' => 'x', | ||
])); | ||
|
||
$this->query->close(); | ||
|
||
// Try to execute a non-existing prepared statement | ||
$this->expectException(BadMethodCallException::class); | ||
$this->expectExceptionMessage('You must call prepare before trying to execute a prepared statement.'); | ||
|
||
$this->query->execute('bar', '[email protected]', 'GB'); | ||
} | ||
|
||
public function testDeallocatePreparedQueryThenTryToClose() | ||
{ | ||
$this->query = $this->db->prepare(static fn ($db) => $db->table('user')->insert([ | ||
'name' => 'a', | ||
'email' => '[email protected]', | ||
'country' => 'x', | ||
])); | ||
|
||
$this->query->close(); | ||
|
||
// Try to close a non-existing prepared statement | ||
$this->expectException(BadMethodCallException::class); | ||
$this->expectExceptionMessage('Cannot call close on a non-existing prepared statement.'); | ||
|
||
$this->query->close(); | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<?php | ||
|
||
$pQuery->close(); | ||
if ($pQuery->close()) { | ||
echo 'Success!'; | ||
} else { | ||
echo 'Deallocation of prepared statements failed!'; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.