-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
fix: isWriteType() to recognize CTE; always excluding RETURNING #8599
fix: isWriteType() to recognize CTE; always excluding RETURNING #8599
Conversation
…pace at query start, RETURNING with DELETE
Thank you! |
|
@markconnellypro Can you add new test methods to test |
add testAssertTypeReturning function for which databases support RETURNING
Each test is now in its own function. The code for determining whether CodeIgniter supports RETURNING is now centralized in one function, so that any future expansions of functionality only need to be fixed in one location, instead of in 15. (To separate out Postgre, I would have had to add an additional 15 tests.) |
…rtType and instead use if statement
Omit RETURNING from isWriteType for all database types; Modify tests for uniform handling for all database types
@@ -1657,7 +1657,7 @@ public function resetDataCache() | |||
*/ | |||
public function isWriteType($sql): bool | |||
{ | |||
return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX|MERGE)\s/i', $sql); | |||
return (bool) preg_match('/^\s*(WITH\s.+(\s|[)]))?"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX|MERGE)\s(?!.*\sRETURNING\s)/is', $sql); |
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.
Do you know why "?
is needed?
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 don't, but since it was already there, I left it.
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, it came from CI3.
https://github.com/bcit-ci/CodeIgniter/blob/70d0a0edbee5e5814aefddb77f67628e68de080f/system/database/DB_driver.php#L999
So it is not easy to remove it.
But I don't imagine a use case. And it seems there is no test case for it.
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.
Thank you! The test code is now much cleaner.
@markconnellypro Thank you! |
Description
This pull request attempts to fix some issues I ran into with queries being miscategorized as isWriteType or not, particularly with PostgreSQL:
Edit: this pull request has been modified to remove the Postgre override of isWriteType, and to incorporate RETURNING handling in isWriteType on a uniform basis for all database types.
Checklist: