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

exec(..) does not always return Integer as promised #949

Open
Jemt opened this issue Oct 2, 2024 · 2 comments
Open

exec(..) does not always return Integer as promised #949

Jemt opened this issue Oct 2, 2024 · 2 comments

Comments

@Jemt
Copy link

Jemt commented Oct 2, 2024

Hi,

I'm cleaning up a table in a SQLite database that has not yet had its "ip" column added. This results in an array being returned from R::exec(..), even though it promises to return an integer:

image

You can se the SQL statement being executed in the screenshot, as well as the exception being thrown, resulting in either null or array() being returned. The query function is called from exec.

In this particular case, wouldn't it be safe to return 0 (zero) when the column or table is missing? I understand query might be used somewhere else, so we'd probably need a $_calledFromExec argument to apply this rule.
If not, I'd rather have the actual exception re-thrown.

@Lynesth
Copy link
Collaborator

Lynesth commented Oct 2, 2024

If you freeze the database before running your queries then it will simply throw the exception.
Is that something you could use for your case?

Regarding the fact that exec should return an integer, I think we could probably just make it clear in the comments that it can return more types when executed in Fluid mode?

@Jemt
Copy link
Author

Jemt commented Oct 8, 2024

Hi @Lynesth. Thanks for replying back.

I'm not a fan of inconsistent behaviour, so personally I would prefer having the same behaviour during both development and when running in production.

exec is supposed to return number of affected rows, right? If so, I'm not sure why we would want it to return anything other than an integer. The API docs are not clear on this - it just states that an Integer is returned without further explaination: https://redbeanphp.com/api/classes/RedBeanPHP.Facade.html#method_exec

No matter the decision, please consider improving the description for exec.

-- Thank you 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants