From a0182707121a0c0fd9927fb24d83e6ac96e376b1 Mon Sep 17 00:00:00 2001 From: Andreas Scherbaum Date: Sun, 3 May 2020 21:29:30 +0200 Subject: [PATCH] Add CAST for "value" column when selecting mf_hCalendar data (#115) Otherwise PostgreSQL will throw an "operator does not exist" error --- .../serendipity_plugin_microformats.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/serendipity_event_microformats/serendipity_plugin_microformats.php b/serendipity_event_microformats/serendipity_plugin_microformats.php index 2253acaa..4d43cad9 100644 --- a/serendipity_event_microformats/serendipity_plugin_microformats.php +++ b/serendipity_event_microformats/serendipity_plugin_microformats.php @@ -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 '
hCalendar
'; } } -} \ No newline at end of file +}