Add CAST for "value" column when selecting mf_hCalendar data (#115)

Otherwise PostgreSQL will throw an "operator does not exist" error
This commit is contained in:
Andreas Scherbaum 2020-05-03 21:29:30 +02:00 committed by GitHub
parent 7d57fd7f88
commit a018270712
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -153,7 +153,13 @@ class serendipity_plugin_microformats extends serendipity_plugin
'mf_hCalendar_enddate' => 'DTEND',
'mf_hCalendar_desc' => 'DESC');
if ($this->get_config('include_entries') === true) {
$query = 'SELECT * FROM ' . $serendipity['dbPrefix'] . 'entryproperties WHERE property LIKE \'mf_hCalendar_%\' AND entryid IN (SELECT entryid FROM ' . $serendipity['dbPrefix'] . 'entryproperties WHERE property = \'mf_hCalendar_startdate\' AND value > (' . time() . ($this->get_config('purge') !== false ? ' - ' . 86400 * intval($this->get_config('purge')) : ' ') . '))';
if ($serendipity['dbType'] == "postgres") {
// "value" needs to be casted to INT, otherwise PostgreSQL will raise an error:
// operator does not exist: text > integer
$query = 'SELECT * FROM ' . $serendipity['dbPrefix'] . 'entryproperties WHERE property LIKE \'mf_hCalendar_%\' AND entryid IN (SELECT entryid FROM ' . $serendipity['dbPrefix'] . 'entryproperties WHERE property = \'mf_hCalendar_startdate\' AND value::INT > (' . time() . ($this->get_config('purge') !== false ? ' - ' . 86400 * intval($this->get_config('purge')) : ' ') . '))';
} else {
$query = 'SELECT * FROM ' . $serendipity['dbPrefix'] . 'entryproperties WHERE property LIKE \'mf_hCalendar_%\' AND entryid IN (SELECT entryid FROM ' . $serendipity['dbPrefix'] . 'entryproperties WHERE property = \'mf_hCalendar_startdate\' AND value > (' . time() . ($this->get_config('purge') !== false ? ' - ' . 86400 * intval($this->get_config('purge')) : ' ') . '))';
}
$result = serendipity_db_query($query, false, 'assoc');
$counter = count($event)-1;
if (is_array($result)) {
@ -205,4 +211,4 @@ class serendipity_plugin_microformats extends serendipity_plugin
echo '<div style="text-align:right;"><a href="http://microformats.org/wiki/hcalendar" title="hCalendar microformat enabled"><img src="' . $serendipity['baseURL'] . 'plugins/' . $plugin_dir . '/img/icon-hcalendar.png" width=29" height="18" alt="hCalendar" style="border:none;" /></a></div>';
}
}
}
}