Skip to content
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: BasePreparedQuery class to return boolean values for write-type queries #6750

Merged
merged 5 commits into from
Oct 31, 2022

Conversation

michalsn
Copy link
Member

@michalsn michalsn commented Oct 24, 2022

Description
Fixes #4342

This PR fixes the behavior of Prepared Queries, which always return a Result object.

Some time ago, we fixed the regular query: #4176, but somehow Prepared Queries were forgotten.

Desired behavior is the same as for regular queries, return:

  • Result object for "read" queries
  • bool value for "write" queries

Potentially this is a breaking change, but we should treat it as a bug fix.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer labels Oct 24, 2022
@paulbalandan paulbalandan mentioned this pull request Oct 25, 2022
5 tasks
@MGatner MGatner requested a review from a team October 26, 2022 10:37
* @return ResultInterface
* @return bool|ResultInterface
*
* @throws Exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why throws Exception?
If the query execution fails, it seems it should throw DatabaseException.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it will throw different exceptions depending on the driver. For MySQL it will be mysqli_sql_exception for others ErrorException. There is no point in changing this and hiding the actual exception - at least I don't think it would be appropriate. I believe that the DatabaseException should be used for things that are coming from the framework side and are in our gesture to handle.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have changed the exception classes already in v4.3.
See #6163 and https://github.com/codeigniter4/CodeIgniter4/blob/4.3/user_guide_src/source/changelogs/v4.3.0.rst#id1

When CI throws many kind of Exception, if we switch DBMS, our code will break when we want to catch the execption.
Or we must always catch Exception. But it is too wide. It is not good practice.

Anyway this PR is for develop. So it seems okay. But what about 4.3?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh... blame on me. I wasn't aware of these changes in 4.3 branch. Making these changes in 4.2 branch has no real sense then. I switched the target branch to 4.3.

@michalsn michalsn changed the base branch from develop to 4.3 October 28, 2022 06:17
@kenjis kenjis added the 4.3 label Oct 28, 2022
@MGatner
Copy link
Member

MGatner commented Oct 30, 2022

What's the status on this? Can we get it in soon for 4.3?

@kenjis kenjis merged commit 0e3d5cc into codeigniter4:4.3 Oct 31, 2022
@michalsn michalsn deleted the fix/preparedQuery branch December 13, 2022 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.3 bug Verified issues on the current code behavior or pull requests that will fix them database Issues or pull requests that affect the database layer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: prepared statement execute() returns Result object for all queries
4 participants