]> git.wh0rd.org Git - tt-rss.git/commitdiff
add workaround for psql 8.3 stricter typechecking on SUBSTRING() (refs #201)
authorAndrew Dolgov <fox@madoka.spb.ru>
Mon, 21 Apr 2008 04:53:19 +0000 (05:53 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Mon, 21 Apr 2008 04:53:19 +0000 (05:53 +0100)
12 files changed:
backend.php
functions.php
mobile/functions.php
modules/pref-feed-browser.php
modules/pref-feeds.php
modules/pref-users.php
sanity_check.php
schema/ttrss_schema_mysql.sql
schema/ttrss_schema_pgsql.sql
schema/versions/mysql/35.sql [new file with mode: 0644]
schema/versions/pgsql/35.sql [new file with mode: 0644]
xml-rpc.php

index a7606c5b7c5a77e91d541efba96fd0a40dab0d0f..47c5529cda6231b18819c02950f643b3fec91334 100644 (file)
                        print "<div class='infoBoxContents'>";
 
                        $result = db_query($link, "SELECT login,
-                               SUBSTRING(last_login,1,16) AS last_login,
+                               ".SUBSTRING_FOR_DATE."(last_login,1,16) AS last_login,
                                access_level,
                                (SELECT COUNT(int_id) FROM ttrss_user_entries 
                                        WHERE owner_uid = id) AS stored_articles,
-                               SUBSTRING(created,1,16) AS created
+                               ".SUBSTRING_FOR_DATE."(created,1,16) AS created
                                FROM ttrss_users 
                                WHERE id = '$uid'");
                                
index 6f5e0288db16d07a48ec261b04a9be9644754757..9dbe9b27063bea6c3dc2eb39cdef5dcdf89136f3 100644 (file)
@@ -8,6 +8,12 @@
 
        require_once 'config.php';
 
+       if (DB_TYPE == "pgsql") {
+               define('SUBSTRING_FOR_DATE', 'SUBSTRING_FOR_DATE');
+       } else {
+               define('SUBSTRING_FOR_DATE', 'SUBSTRING');
+       }
+
        /**
         * Return available translations names.
         * 
                }
 
                $result = db_query($link, "SELECT feed_url,id,
-                       SUBSTRING(last_updated,1,19) AS last_updated,
+                       ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated,
                        update_interval FROM ttrss_feeds WHERE owner_uid = '$user_id'
                        ORDER BY $q_order");
 
                $old_counters = $_SESSION["fctr_last_value"];
 
 /*             $result = db_query($link, "SELECT id,last_error,parent_feed,
-                       SUBSTRING(last_updated,1,19) AS last_updated,
+                       ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated,
                        (SELECT count(id) 
                                FROM ttrss_entries,ttrss_user_entries 
                                WHERE feed_id = ttrss_feeds.id AND 
 
                $query = "SELECT ttrss_feeds.id,
                                ttrss_feeds.title,
-                               SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated, 
+                               ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated, 
                                last_error, 
                                COUNT(ttrss_entries.id) AS count 
                        FROM ttrss_feeds 
                                                ttrss_entries.id,ttrss_entries.title,
                                                updated,
                                                unread,feed_id,marked,published,link,last_read,
-                                               SUBSTRING(last_read,1,19) as last_read_noms,
+                                               ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms,
                                                $vfeed_query_part
                                                $content_query_part
-                                               SUBSTRING(updated,1,19) as updated_noms,
+                                               ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms,
                                                author
                                        FROM
                                                ttrss_entries,ttrss_user_entries,ttrss_feeds
                                        updated,
                                        unread,feed_id,
                                        marked,link,last_read,                          
-                                       SUBSTRING(last_read,1,19) as last_read_noms,
+                                       ".SUBSTRING_FOR_DATE."(last_read,1,19) as last_read_noms,
                                        $vfeed_query_part
                                        $content_query_part
-                                       SUBSTRING(updated,1,19) as updated_noms
+                                       ".SUBSTRING_FOR_DATE."(updated,1,19) as updated_noms
                                        FROM
                                                ttrss_entries,ttrss_user_entries,ttrss_tags
                                        WHERE
                                ttrss_user_entries.ref_id,
                                link,
                                SUBSTRING(content, 1, 120) AS excerpt,
-                               SUBSTRING(last_updated,1,19) AS last_updated
+                               ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
                        FROM 
                                ttrss_user_entries,ttrss_entries,ttrss_feeds 
                        WHERE 
                        $age_qpart = getMaxAgeSubquery();
 
                        $result = db_query($link, "SELECT ttrss_feeds.*,
-                               SUBSTRING(last_updated,1,19) AS last_updated_noms,
+                               ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
                                (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
                                        WHERE feed_id = ttrss_feeds.id AND unread = true
                                                AND $age_qpart
                }
 
                $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
-                       SUBSTRING(updated,1,16) as updated,
+                       ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
                        (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
                        num_comments,
                        author
 
                // We search for feed needing update.
                $result = db_query($link, "SELECT ttrss_feeds.feed_url,ttrss_feeds.id, ttrss_feeds.owner_uid,
-                               SUBSTRING(ttrss_feeds.last_updated,1,19) AS last_updated,
+                               ".SUBSTRING_FOR_DATE."(ttrss_feeds.last_updated,1,19) AS last_updated,
                                ttrss_feeds.update_interval 
                        FROM 
                                ttrss_feeds, ttrss_users, ttrss_user_prefs
index fe9dab4ed2375602b30f34c986a190219ba14b2f..b1085b9c5fb0f5ad5de868fc90d73395b77d3534 100644 (file)
                        }
 
                        $result = db_query($link, "SELECT ttrss_feeds.*,
-                               SUBSTRING(last_updated,1,19) AS last_updated_noms,
+                               ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated_noms,
                                (SELECT COUNT(id) FROM ttrss_entries,ttrss_user_entries
                                        WHERE feed_id = ttrss_feeds.id AND 
                                        ttrss_user_entries.ref_id = ttrss_entries.id AND
 
                $result = db_query($link, "SELECT title,link,content,feed_id,comments,int_id,
                        marked,published,
-                       SUBSTRING(updated,1,16) as updated,
+                       ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
                        (SELECT icon_url FROM ttrss_feeds WHERE id = feed_id) as icon_url,
                        num_comments,
                        author
index e331035019514faf7689d27639afc36ec1a20b31..bdbb930d4a293b5d6bbb50363a4f4f151ad1662d 100644 (file)
@@ -16,7 +16,7 @@
 
                        $result = db_query($link, "SELECT 
                                        feed_url,site_url,
-                                       SUBSTRING(last_updated,1,19) AS last_updated 
+                                       ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated 
                                FROM ttrss_feeds WHERE id = '$id' AND
                                        auth_login = '' AND auth_pass = '' AND private IS NOT true");
 
index 9b718ace61a09a981a522c3cd85beca82ec22fce..43be1cbe397febb98e3e0d5eaadb8d36e9fccb03 100644 (file)
                if ($_GET["slat"] == "true") {
                        $show_last_article_info = true;
                        $show_last_article_checked = "checked";
-                       $show_last_article_qpart = ", (SELECT SUBSTRING(MAX(updated),1,16) FROM ttrss_user_entries,
+                       $show_last_article_qpart = ", (SELECT ".SUBSTRING_FOR_DATE."(MAX(updated),1,16) FROM ttrss_user_entries,
                                ttrss_entries WHERE ref_id = ttrss_entries.id
                                AND feed_id = F1.id) AS last_article";
                } else if ($feeds_sort == "last_article") {
index 4872a0d8fa8561f122ee6b6a13996b84d4aaefa9..399fc5e1ef2e237ed7fb8257c2d3a0dbd349f4bf 100644 (file)
 
                $result = db_query($link, "SELECT 
                                id,login,access_level,email,
-                               SUBSTRING(last_login,1,16) as last_login
+                               ".SUBSTRING_FOR_DATE."(last_login,1,16) as last_login
                        FROM 
                                ttrss_users
                        ORDER BY $sort");
index 3dc6eaaf7d7a0a4b31741d8013c1556717be7091..3735d6c4fc31f0bf6f19740a2b1888efb0c00c46 100644 (file)
@@ -2,7 +2,7 @@
        require_once "functions.php";
 
        define('EXPECTED_CONFIG_VERSION', 15);
-       define('SCHEMA_VERSION', 34);
+       define('SCHEMA_VERSION', 35);
 
        if (!file_exists("config.php")) {
                print __("<b>Fatal Error</b>: You forgot to copy 
index 9edb4b12cd0e0a049bde855fdf03940ee30ff0df..f2daa69fbc9ba7a6f815db72538ddaeabbc16741 100644 (file)
@@ -205,7 +205,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) TYPE=InnoDB;
 
-insert into ttrss_version values (34);
+insert into ttrss_version values (35);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
index 7ea72cd751f90d14b322fd7d47e5cde164bb3b8c..c35781a698212ffbc978cfedaf3f16a8f87c0380 100644 (file)
@@ -18,6 +18,7 @@ drop table ttrss_feed_categories;
 drop table ttrss_users;
 drop table ttrss_themes;
 drop table ttrss_sessions;
+drop function SUBSTRING_FOR_DATE(timestamp, int, int);
 
 begin;
 
@@ -184,7 +185,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (34);
+insert into ttrss_version values (35);
 
 create table ttrss_enclosures (id serial not null primary key,
        content_url text not null,
@@ -317,4 +318,6 @@ create table ttrss_sessions (id varchar(250) unique not null primary key,
 
 create index ttrss_sessions_expire_index on ttrss_sessions(expire);
 
+create function SUBSTRING_FOR_DATE(timestamp, int, int) RETURNS text AS 'SELECT SUBSTRING(CAST($1 AS text), $2, $3)' LANGUAGE 'sql';
+
 commit;
diff --git a/schema/versions/mysql/35.sql b/schema/versions/mysql/35.sql
new file mode 100644 (file)
index 0000000..ad112a0
--- /dev/null
@@ -0,0 +1 @@
+update ttrss_version set schema_version = 35;
diff --git a/schema/versions/pgsql/35.sql b/schema/versions/pgsql/35.sql
new file mode 100644 (file)
index 0000000..e624d66
--- /dev/null
@@ -0,0 +1,3 @@
+create function SUBSTRING_FOR_DATE(timestamp, int, int) RETURNS text AS 'SELECT SUBSTRING(CAST($1 AS text), $2, $3)' LANGUAGE 'sql';
+
+update ttrss_version set schema_version = 35;
index 07f423cbd492f3cba7cc28dd500ea526fa2fa2cb..0117657d0339944aa9b4ff71ba0af57730efab76 100644 (file)
                if (authenticate_user($link, $login, $pass)) {
 
                        $result = db_query($link, "SELECT 
-                               id, feed_url, cat_id, title, SUBSTRING(last_updated,1,19) AS last_updated
+                               id, feed_url, cat_id, title, ".SUBSTRING_FOR_DATE."(last_updated,1,19) AS last_updated
                                        FROM ttrss_feeds WHERE owner_uid = " . 
                                $_SESSION["uid"]);
 
 
                        $query = "SELECT title,link,content,feed_id,comments,int_id,
                                marked,unread,
-                               SUBSTRING(updated,1,16) as updated,
+                               ".SUBSTRING_FOR_DATE."(updated,1,16) as updated,
                                author
                                FROM ttrss_entries,ttrss_user_entries
                                WHERE   id = '$article_id' AND ref_id = id AND owner_uid = " . $_SESSION["uid"] ;