]> git.wh0rd.org Git - tt-rss.git/commitdiff
code cleanup, test for db_escape() crazyness in DB sanity check
authorAndrew Dolgov <fox@madoka.spb.ru>
Mon, 10 Nov 2008 05:29:19 +0000 (06:29 +0100)
committerAndrew Dolgov <fox@madoka.spb.ru>
Mon, 10 Nov 2008 05:29:19 +0000 (06:29 +0100)
12 files changed:
backend.php
errors.php
functions.php
mobile/tt-rss.php
mysql_convert_unicode.php
opml.php
update.php
update_daemon.php
update_daemon2.php
update_daemon_loop.php
update_feeds.php
xml-rpc.php

index fa116458c1bb33276176a2e4680ba7eb5855f74b..b298ec738a058d54a591b4e9c8b5743eece92580 100644 (file)
                return;
        }
 
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'UTF-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
+       init_connection($link);
 
        $op = $_REQUEST["op"];
 
index dc47f38e40f888b88997909fb5d7436e1ddb46ba..bd7b53fe40d3a4149bd366c2f0a633ab9c93c765 100644 (file)
@@ -28,4 +28,6 @@
                official site for more information.");
 
        $ERRORS[11] = "[This error is not returned by server]";
+
+       $ERRORS[12] = __("SQL escaping test failed, check your database and PHP configuration");
 ?>
index e1f4a229fcce9f5a0e50fd605092b291fba8abb7..48d6e3a858adb4926c7d372781be8567c4dfce6e 100644 (file)
                        }
                }
 
+               if (db_escape_string("testTEST") != "testTEST") {
+                       $error_code = 12;
+               }
+
                error_reporting (DEFAULT_ERROR_LEVEL);
 
                if ($error_code != 0) {
        function feed_has_icon($id) {
                return is_file(ICONS_DIR . "/$id.ico") && filesize(ICONS_DIR . "/$id.ico") > 0;
        }
+
+       function init_connection($link) {
+               if (DB_TYPE == "pgsql") {
+                       pg_query("set client_encoding = 'UTF-8'");
+                       pg_set_client_encoding("UNICODE");
+               } else {
+                       if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
+                               db_query($link, "SET NAMES " . MYSQL_CHARSET);
+       //                      db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
+                       }
+               }
+       }
 ?>
index 11316d4d3cfe4bace1f2fea1236111f253d3037f..a8bf6fb5f734f0cbb6edd8226798481afa69508d 100644 (file)
 
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
 
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'UTF-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
+       init_connection($link);
 
        login_sequence($link, true);
 
index 6fe72994c2a234b46d870c1a892c2cce11967839..6d43c234c5fbd57ef8a237db1205c8714c699023 100644 (file)
@@ -9,16 +9,8 @@
        require_once "db.php";
        
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
-       
-       if (DB_TYPE == "pgsql") {
-               pg_query($link, "set client_encoding = 'utf-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
+
+       init_connection($link); 
 
        login_sequence($link);
        
index 35d7a070c8ae1a17896df8e52cc66a652fd6cffc..44e94ee37e60bf76429650cd407d794a54f7bc98 100644 (file)
--- a/opml.php
+++ b/opml.php
 
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
 
-       if (DB_TYPE == "pgsql") {
-               pg_query($link, "set client_encoding = 'utf-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
-
+       init_connection($link);
        login_sequence($link);
 
        $owner_uid = $_SESSION["uid"];
index f59f9ef3e56c04397c6a2d7de718df1d7305f353..76e3088567128eb19375742248f1cc347515b354 100644 (file)
@@ -9,17 +9,8 @@
        require_once "db.php";
        
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
-       
-       if (DB_TYPE == "pgsql") {
-               pg_query($link, "set client_encoding = 'utf-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
 
+       init_connection($link); 
        login_sequence($link);
        
        $owner_uid = $_SESSION["uid"];
index 67a8781dea697f6a64b0a72301233bd5a617e892..35177edd621639e7a4c078ac124bf9e9713fd29b 100644 (file)
@@ -57,6 +57,8 @@
                        "Maybe another daemon is already running.\n");
        }
 
+       // Testing database connection.
+       // It is unnecessary to start the fork loop if database is not ok.
        $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); 
 
        if (!$link) {
                return;
        }
 
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'utf-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
-
        db_close($link);
 
        $last_purge = 0;
index be652777e28b792bfb48957e6c9b2d2be553c8c6..08f5d74c3e292c4be6c0544d1120dfb4f4114c29 100644 (file)
 
        db_close($link);
 
-
        while (true) {
 
                // Since sleep is interupted by SIGCHLD, we need another way to
                                                return;
                                        }
 
-                                       if (DB_TYPE == "pgsql") {
-                                               pg_query("set client_encoding = 'utf-8'");
-                                               pg_set_client_encoding("UNICODE");
-                                       } else {
-                                               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                                                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-                                                       // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-                                               }
-                                       }
+                                       init_connection($link);
 
                                        // We disable stamp file, since it is of no use in a multiprocess update.
                                        // not really, tho for the time being -fox
index 737194aee4fa5e6183013cdf4e5d9bb309bc1f1e..b1197ff3494801862920989f0e1c6e50a31ef0fb 100644 (file)
                return;
        }
 
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'utf-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
+       init_connection($link);
 
        $last_purge = 0;
 
index 139da699925cf575cdfddb432b960ca5c351ffa4..2bb91dc30182d47547e6beaf027de1794941da85 100644 (file)
                return;
        }
 
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'utf-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
+       init_connection($link);
 
        // Purge all posts (random 30 feeds)
        global_purge_old_posts($link, true, 30);
index 0117657d0339944aa9b4ff71ba0af57730efab76..2a23f57f677bcc175e4bc9cbf47c402c6407ccba 100644 (file)
                return;
        }
 
-       if (DB_TYPE == "pgsql") {
-               pg_query("set client_encoding = 'utf-8'");
-               pg_set_client_encoding("UNICODE");
-       } else {
-               if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
-                       db_query($link, "SET NAMES " . MYSQL_CHARSET);
-//                     db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
-               }
-       }
+       init_connection($link);
 
        function getVirtualFeeds($msg) {
                global $link;