freetag plugin generates SQL error

Found a bug? Tell us!!
ads
Regular
Posts: 93
Joined: Sun Oct 29, 2006 11:39 am

freetag plugin generates SQL error

Post by ads »

Hi,

i'm using the freetag plugin and can see the following error in my database log:

2010-02-24 13:27:08 CET ERROR: syntax error at or near ")" at character 66
2010-02-24 13:27:08 CET STATEMENT: SELECT entryid, tag from serendipity_entrytags WHERE entryid IN () order by entryid, tag

In addition there's a nasty PHP warning, if i create a new blog posting. But i'm not not sure, if that's related:

Warning: Invalid argument supplied for foreach() in /www/blog/plugins/serendipity_event_microformats/serendipity_event_microformats.php on line 137
Warning: Invalid argument supplied for foreach() in /www/blog/plugins/serendipity_event_microformats/serendipity_event_microformats.php on line 251
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: freetag plugin generates SQL error

Post by garvinhicking »

Hi!

Hm, the first error should not occur. Are you using the most recent version of the plugin?

The same applies to the microformats plugin, are you using a recent version there as well?

In both places you mentioned, current versions check if the input data is an array or not...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
ads
Regular
Posts: 93
Joined: Sun Oct 29, 2006 11:39 am

Re: freetag plugin generates SQL error

Post by ads »

Yes, plugins are up to date, according to spartacus (i wrote this script which checks regularly for plugin updates). For what code should i look to find out, if the changes you mentioned are applied to my plugins?

Note that the database in question is PostgreSQL and the "()" really looks like empty values.
I remember, that i have seen the php warnings before, just the database error is new to me.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: freetag plugin generates SQL error

Post by garvinhicking »

Hi!

The first one would be in serendipity_event_freetag.php at around line 1456. The code says:

Code: Select all

  function getTagsForEntries($entries) {
        global $serendipity;

        if (!is_array($entries) || count($entries) < 1) {
            return false;
        }

        $q = "SELECT entryid, tag from {$serendipity['dbPrefix']}entrytags WHERE entryid IN (".implode(',', $entries).") order by entryid, tag";
So if $entries is empty, it should bail out due to the is_array check at the beginning.

You might want to modify it like this:

Code: Select all

  function getTagsForEntries($entries) {
        global $serendipity;

        if (!is_array($entries) || count($entries) < 1) {
            return false;
        }

        $string = implode(',', $entries);
        $string = trim($string);
        if (empty($string)) { $fp = fopen('/tmp/s9y.log', 'a'); fwrite($fp, print_r($entries, true)); fclose($fp); }

        $q = "SELECT entryid, tag from {$serendipity['dbPrefix']}entrytags WHERE entryid IN (".implode(',', $entries).") order by entryid, tag";
Then this would log possible empty strings and give the input array into the logfile /tmp/s9y.log (make sure you pick a file/dir thats writable).

Inside serendipity_event_microformats.php there's a similar thing. The actual error happens in the "getSupportedProperties()" method. This is called with an input parameter called "mf_type".

But all references to this really specify a proper input array:

line 165:

Code: Select all

        $supported_formats = array('hReview', 'hCalendar');
        $supported_properties =& $this->getSupportedProperties($supported_formats);
line 234:

Code: Select all

                        $supported_formats = array('hReview', 'hCalendar');
                        $supported_properties =& $this->getSupportedProperties($supported_formats);
line 250:

Code: Select all

                    if (is_array($serendipity['POST']['properties']) && count($serendipity['POST']['properties']) > 0){
                        $supported_properties =& $this->getSupportedProperties($serendipity['POST']['properties']['mf_type']);
line 288:

Code: Select all

                        $supported_formats = array('hReview', 'hCalendar');
                        $supported_properties =& $this->getSupportedProperties($supported_formats);
Which PHP version are you running? Some PHP versions had a bug when a bytecode cache was used that did not properly pass along arrays...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
ads
Regular
Posts: 93
Joined: Sun Oct 29, 2006 11:39 am

Re: freetag plugin generates SQL error

Post by ads »

First of all, before i try to debug and add your code:

I found two serendipity_event_freetag.php files:

./plugins/freetag/serendipity_event_freetag.php
./plugins/serendipity_event_freetag/serendipity_event_freetag.php

The first one is:

$Id: serendipity_event_freetag.php,v 1.124 2008/12/10 10:34:52 lstrojny Exp $

The second one is:

$Id: serendipity_event_freetag.php,v 1.136 2010/01/06 23:37:08 onli Exp $

Is this correct? If no, which one should i remove, if yes: which one should i add your debugging code?
onli
Regular
Posts: 2830
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: freetag plugin generates SQL error

Post by onli »

Which one gets used? The one in /plugins/serendipity_event_freetag/ is newer and should be the only one.
sincerely
ads
Regular
Posts: 93
Joined: Sun Oct 29, 2006 11:39 am

Re: freetag plugin generates SQL error

Post by ads »

Both contain the array checks which garvin posted earlier in this thread.
I don't know which one get's used - and/or if the other one get's used if i remove one.

Which one is the official one?
onli
Regular
Posts: 2830
Joined: Tue Sep 09, 2008 10:04 pm
Contact:

Re: freetag plugin generates SQL error

Post by onli »

The one in /plugins/serendipity_event_freetag/ is the official one, it's the one in spartacus.
ads
Regular
Posts: 93
Joined: Sun Oct 29, 2006 11:39 am

Re: freetag plugin generates SQL error

Post by ads »

I moved away the "freetag" directory and added some debugging code. From what i can see, this happens if i press the "preview" button:

Code: Select all

empty array: Array
(
    [0] =>
)

query string:
SELECT entryid, tag from serendipity_entrytags WHERE entryid IN () order by entryid, tag
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: freetag plugin generates SQL error

Post by garvinhicking »

Hi!

Ah, great. In fact we didn't check for that, thanks for helping the debugging. I committed a patch to the freetag plugin so that this case will now also be checked.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
ads
Regular
Posts: 93
Joined: Sun Oct 29, 2006 11:39 am

Re: freetag plugin generates SQL error

Post by ads »

Ah, fine ;-)

I will wait for the module update and then check again if the php warnings are gone.


Andreas
ads
Regular
Posts: 93
Joined: Sun Oct 29, 2006 11:39 am

Re: freetag plugin generates SQL error

Post by ads »

Ok, the SQL bug is gone.

There is still the PHP warning:

Code: Select all

Warning: Invalid argument supplied for foreach() in /www/blog/plugins/serendipity_event_microformats/serendipity_event_microformats.php on line 137
Warning: Invalid argument supplied for foreach() in /www/blog/plugins/serendipity_event_microformats/serendipity_event_microformats.php on line 251
In addition, the microformats output is buggy:

http://base.wars-nicht.de/microformats_2010-02-28.jpg

Short PHP tags are NOT allowed on this host ;-)
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: freetag plugin generates SQL error

Post by garvinhicking »

Hi!

I removed the short-open required code in the latest version, maybe this can also corret your problem with the line 137/251 bug?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
ads
Regular
Posts: 93
Joined: Sun Oct 29, 2006 11:39 am

Re: freetag plugin generates SQL error

Post by ads »

Version 3.10.4 is installed here. Should there be a newer version?
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: freetag plugin generates SQL error

Post by garvinhicking »

Hi!
ads wrote:Version 3.10.4 is installed here. Should there be a newer version?
I'm talking about Microformats, there 0.44 is the now recent version :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply