?
avatar Fedik
Fedik
23 Nov 2015

FOFTable::store always return false on _db->updateObject, when Joomla database driver is MySql PDO
The reason that the PDO result is PDO Object not a boolean, but the code expect boolean in some reason.

Maybe it more complex issue with MySQL PDO, cause it not the first time when I see such fail. When developers test for $result === true it always fail with MySQL PDO.

For now I do not have an example code. Just want to write before I forget ?

avatar Fedik Fedik - open - 23 Nov 2015
avatar zero-24
zero-24 - comment - 23 Nov 2015

@Fedik fof is an external project not owned / controled by Joomla ;) It is owned by Nicholas K. Dionysopoulos / Akeeba Ltd. Please report any issues to the original repo / owner: https://github.com/akeeba/fof/tree/fof-2.x

Thanks.

avatar zero-24 zero-24 - close - 23 Nov 2015
avatar zero-24 zero-24 - change - 23 Nov 2015
Status New Closed
Closed_Date 0000-00-00 00:00:00 2015-11-23 14:31:03
Closed_By zero-24
avatar zero-24 zero-24 - close - 23 Nov 2015
avatar Fedik
Fedik - comment - 23 Nov 2015

ok, thanks

avatar Fedik
Fedik - comment - 23 Nov 2015

@nikosdion say it Joomla bug :smile: .. @zero-24 can you please reopen this one?

avatar nikosdion
nikosdion - comment - 23 Nov 2015

I am cross-posting here from my reply on the issue opened on FOF

That's a bug in Joomla! and I believe @mbabker has already told you. The updateObject's signature says that the method returns a boolean. See https://github.com/joomla/joomla-cms/blob/5c0f405d5f4f9a26e275bec375cefe641cb209b5/libraries/joomla/database/driver.php#L1838-L1838

Please fix Joomla!. FYI the problem is that JDatabaseDriverPdo::execute() returns an object (instead of boolean) when a non-SELECT statement is executed. As a result you should overload JDatabaseDriverPdo::updateObject (and insertObject) with something like return (parent::updateObject(.....) !== false).

I mean, guys, it's trivial. The method signature promises to return a boolean. We rely on that published signature in our code, checking if the result is boolean true. I have no idea why you insist on sending people to us when the bug in Joomla!'s code is so obvious...

avatar mbabker
mbabker - comment - 23 Nov 2015

In Tobias' defense the initial report, without any deep digging into the issue or awareness of the misbehavior (I'm pretty sure I've seen it a few times, moaned about it in closed channels, and moved on without thinking about a fix), the opening post does lean heavily toward sending the report to FOF.

avatar Fedik
Fedik - comment - 23 Nov 2015

similar issue #8322 .. but there was fixed locally, by cast the result to the boolean

avatar nikosdion
nikosdion - comment - 23 Nov 2015

That issue (#8332) is an architecturally incorrect approach. It assumes that the method signature is not to be trusted (wtf?!!!) and instead tries to monkey a solution around the actual bug.

And that's how every Joomla! developer worth their salt have resorted to building their own frameworks.

avatar zero-24 zero-24 - reopen - 23 Nov 2015
avatar zero-24
zero-24 - comment - 23 Nov 2015

I'm very sorry. Thanks for correcting me.

avatar zero-24 zero-24 - change - 23 Nov 2015
Status Closed New
Closed_Date 2015-11-23 14:31:01
Closed_By zero-24
avatar zero-24 zero-24 - reopen - 23 Nov 2015
avatar zero-24 zero-24 - change - 25 Nov 2015
Category Libraries
avatar zero-24 zero-24 - change - 25 Nov 2015
Status New Confirmed
Labels Added: ?
avatar photodude
photodude - comment - 25 Nov 2015

@zero-24 @Fedik This issue should be retitled
something like JDatabaseDriverPdo::updateObject PDO Object not a boolean

avatar zero-24 zero-24 - change - 25 Nov 2015
Title
FOFTable::store always return false on db->updateObject, when Joomla database driver is MySql PDO
JDatabaseDriverPdo::updateObject PDO Object not a boolean
avatar zero-24
zero-24 - comment - 25 Nov 2015

Done. Thanks

avatar mbabker
mbabker - comment - 8 May 2016

This probably needs to be tossed into the 4.0 pile because it technically constitutes a B/C break (even though the current return contradicts the documented type). One of those existing behavior versus documented standard judgement calls.

Actually, the documentation on JDatabaseDriver::execute() (and its subclasses' implementations) is wrong too as the method no longer returns a boolean on an error condition but throws exceptions; it'll only return a database resource.

In general, anything returning the result of $this->execute() in the database layer right now will return the database resource object (it's not unique to PDO either). In JDatabaseDriver there are 3 methods doing this; updateObject() (documented to return a boolean), alterDbCharacterSet, and createDatabase (both of those documented to return strings).

So there's a whole heap of code in the database layer that's inconsistent with the documentation and it needs to be decided whether the documentation should be changed to reflect the existing behavior or if it should be noted that a B/C break will occur at 4.0 and the returns will change to what's documented.

avatar cheesegrits
cheesegrits - comment - 5 Jul 2016

@nikosdion @mbabker - just ran in to this one (using j2store with PDO).

You both have valid points. But unless I'm missing something obvious, could this not be "fixed" for now by simply changing line 1298 in the FOF table.php store() from "if ($result !== true)" to "if ($result === false)"?

https://github.com/joomla/joomla-cms/blob/staging/libraries/fof/table/table.php#L1298


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8525.

avatar mbabker
mbabker - comment - 5 Jul 2016

For 3.x support only you'd need a try/catch around $db->execute() calls (or anything inherently calling it). The execute methods won't return a boolean false.

So at least with ext/mysql and ext/mysqli, the return values from mysql(i)_query() are either a resource object for queries returning a result set, boolean true for other statement types, or boolean false on fail. A check is made in the driver for a false return and throws an exception otherwise returns the query result (either the resource object or boolean true). It looks the same for ext/pgsql and ext/sqlsrv. In the PDO stack, a check is made against whether the stored PDOStatement object was executed and said object returns on success.

So long and short we still have a documentation issue, but since I've been messing with database code the last couple of weeks I can say it's not as bad as I implied a couple of months ago; just hugely inconsistent. In either case, a check against a boolean false return isn't suitable. $db->insertObject() triggers $db->execute() without a try/catch so it'll never reach the return false condition and $db->updateObject() just returns $db->execute() so you hit the wall of text above for the possible return conditions.

avatar mbabker
mbabker - comment - 5 Jul 2016

And then it gets tricky. IIRC FOF 2 supports Joomla 2.5, which doesn't have exception handling but boolean returns. So in that case you need a try/catch for the 3.x code and the checks for boolean returns for 2.5 code.

avatar nikosdion
nikosdion - comment - 5 Jul 2016

Right now FOF 2 isn't supported anymore. So any change you make into the copy in J! 3 won't be a problem.

avatar cheesegrits
cheesegrits - comment - 5 Jul 2016

Ah, OK. I submitted a PR on the 2.0x branch just now ...

akeeba/fof#610

Should I submit that on the cms instead?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8525.

avatar cheesegrits
cheesegrits - comment - 7 Jul 2016

@mbabker @nikosdion - any opinion on which repo changes to FOF 2 should be PR'ed against?


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8525.

avatar cheesegrits
cheesegrits - comment - 27 Jul 2016

@mbabker - ping ...

-- hugh


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/8525.

avatar mbabker
mbabker - comment - 27 Jul 2016

Just make them here for the reason commented above.

avatar rvbgnu
rvbgnu - comment - 3 Jun 2017

@mbabker If this issue still relevant, or should it be closed?


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/8525.

avatar mbabker
mbabker - comment - 3 Jun 2017

Honestly, I don't remember exactly what the problem is/was.

avatar franz-wohlkoenig franz-wohlkoenig - change - 3 Jun 2017
Status Confirmed Information Required
avatar joomla-cms-bot joomla-cms-bot - edited - 3 Jun 2017
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 22 Jun 2017

If this PR get no Response, it will be closed at 23th July 2017.

avatar franz-wohlkoenig franz-wohlkoenig - change - 23 Jul 2017
Status Information Required Closed
Closed_Date 0000-00-00 00:00:00 2017-07-23 05:52:25
Closed_By franz-wohlkoenig
avatar joomla-cms-bot joomla-cms-bot - change - 23 Jul 2017
Closed_By franz-wohlkoenig joomla-cms-bot
avatar joomla-cms-bot joomla-cms-bot - close - 23 Jul 2017
avatar joomla-cms-bot
joomla-cms-bot - comment - 23 Jul 2017
avatar franz-wohlkoenig
franz-wohlkoenig - comment - 23 Jul 2017

closed as stated above.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/8525.

Add a Comment

Login with GitHub to post a comment