db icon indicating copy to clipboard operation
db copied to clipboard

Throw exception if value cannot be cast to a string in `AbstractQueryBuilder::prepareValue()`

Open vjik opened this issue 5 months ago • 6 comments

https://github.com/yiisoft/db/blob/8e175974dabf6da4ff8e4197a6e3b9a9014c79ee/src/QueryBuilder/AbstractQueryBuilder.php#L493-L497

vjik avatar Aug 17 '25 08:08 vjik

Currently it already throws an exception Fatal error: Uncaught Error: Object of class DateTime could not be converted to string

Tigrov avatar Aug 17 '25 11:08 Tigrov

I mean something like DB param value don't support "DateTimeInterface".

Fatal error: Uncaught Error: Object of class DateTime could not be converted to string looks like bug in Yii DB.

But exception adding can lead to performance degradation.

vjik avatar Aug 17 '25 12:08 vjik

This is an unhandled exception. We don't care much about performance in this case, since it is executed only once.

samdark avatar Aug 17 '25 20:08 samdark

But, overall, I think that binding DateTimeInterface instances is quite common...

samdark avatar Aug 17 '25 20:08 samdark

This is an unhandled exception. We don't care much about performance in this case, since it is executed only once.

Currently it is not exception, it is fatal error. For introduce exception we should add new checks and throw exception manually.

vjik avatar Aug 17 '25 20:08 vjik

I think this is a common-enough case to try handling it.

samdark avatar Aug 18 '25 06:08 samdark