Jump to content

Wrong result returning on database query function


Toucan Web Design

Recommended Posts

Just been looking into an issue for a client who recently upgraded his store, not sure what he was on before unfortunately, but he's now on 5.2.5

 

Anyhow, a previous script we'd wrote had broke, where it runs a simple query like so:

SELECT product_id FROM CubeCart_image_index WHERE `product_id` = '1302' AND `file_id` = '6268' LIMIT 1

That file reference isn't found, so I'd expect it to return either an empty array or false, but it's actually returning bool(true)

 

Anyone else seen any problems like that? Not too sure what's causing it. Max results is false, as is cache, and no page is set

Here's the actual line in fact:

$imageCheck = $GLOBALS['db']->query("SELECT product_id FROM ".$GLOBALS['config']->get("config", "dbprefix")."CubeCart_image_index WHERE `product_id` = '".$GLOBALS['db']->sqlSafe($productId)."' AND `file_id` = '".$GLOBALS['db']->sqlSafe($fileId)."' LIMIT 1", false, 0, false);

Closest thing I can ever see to it returning that, is on the mysqli class:

                if (is_bool($result)) {
                    $this->_result    = $result;

But that shouldn't be returning a bool on a select either, so a bit nonplussed as to what's going on with it really. I know early on there were some issues with the error logging overriding the result returned with its own results, but that was more of an issue on inserts and updates, plus, there isn't actually any error being thrown as the query is fine, just no results to return.

 

Bit of a mystery really, anyone have any clue what that might be?

Link to comment
Share on other sites

I traced it out once with the mysql file. I have been making this edit ever since. Note however, I still use mysql and I see that the mysqli->_execute() is a bit different from mysql->_execute().

 

In the file database,class.php, at the bottom of the query() method, find:

return (!$this->error()) ? $this->_result : false;

Change to:

return (!$this->error()) ? (!empty($this->_result) ? $this->_result : true ) : false;

 

This adds the case where an empty result returns true instead of an unset result.

 

I don't know if the above will help.

Link to comment
Share on other sites

Hi Brian,

 

Yeah, I've been through the database files a few times in the past, but this is the first one that I've seen that's this weird.

 

Hmm, in theory, that code change wouldn't fix anything, as $this->_result is apparently being set to bool(true) regardless, so in either case it'd return true, and start breaking things again.

 

Well, I tried setting up a run to see if I could get it to happen again for debugging, and it flat out won't happen anymore.. so that's weird.. just brings back the empty array like it always used to

 

array(0) { }

 

Maybe it was a database problem and I was jumping the gun? Lasted a good 20 min or so of debugging though, so odd

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...