Aleksander Machniak
2013-06-05 aa44ce6e9703ab15bb5270251358fb756a347f17
Add optional argument to now() for simple interval calculations on SQL-side
5 files modified
64 ■■■■ changed files
program/lib/Roundcube/rcube_db.php 12 ●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_db_mssql.php 12 ●●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_db_pgsql.php 21 ●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_db_sqlite.php 10 ●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_db_sqlsrv.php 9 ●●●● patch | view | raw | blame | history
program/lib/Roundcube/rcube_db.php
@@ -711,11 +711,19 @@
    /**
     * Return SQL function for current time and date
     *
     * @param int $interval Optional interval (in seconds) to add/subtract
     *
     * @return string SQL function to use in query
     */
    public function now()
    public function now($interval = 0)
    {
        return "now()";
        if ($interval) {
            $add = ' ' . ($interval > 0 ? '+' : '-') . ' INTERVAL ';
            $add .= $interval > 0 ? intval($interval) : intval($interval) * -1;
            $add .= ' SECONDS';
        }
        return "now()" . $add;
    }
    /**
program/lib/Roundcube/rcube_db_mssql.php
@@ -48,18 +48,22 @@
    /**
     * Return SQL function for current time and date
     *
     * @param int $interval Optional interval (in seconds) to add/subtract
     *
     * @return string SQL function to use in query
     */
    public function now()
    public function now($interval = 0)
    {
        if ($interval) {
            $interval = intval($interval);
            return "dateadd(second, $interval, getdate())";
        }
        return "getdate()";
    }
    /**
     * Return SQL statement to convert a field value into a unix timestamp
     *
     * This method is deprecated and should not be used anymore due to limitations
     * of timestamp functions in Mysql (year 2038 problem)
     *
     * @param string $field Field name
     *
program/lib/Roundcube/rcube_db_pgsql.php
@@ -75,9 +75,6 @@
    /**
     * Return SQL statement to convert a field value into a unix timestamp
     *
     * This method is deprecated and should not be used anymore due to limitations
     * of timestamp functions in Mysql (year 2038 problem)
     *
     * @param string $field Field name
     *
     * @return string SQL statement to use in query
@@ -89,6 +86,24 @@
    }
    /**
     * Return SQL function for current time and date
     *
     * @param int $interval Optional interval (in seconds) to add/subtract
     *
     * @return string SQL function to use in query
     */
    public function now($interval = 0)
    {
        if ($interval) {
            $add = ' ' . ($interval > 0 ? '+' : '-') . " interval '";
            $add .= $interval > 0 ? intval($interval) : intval($interval) * -1;
            $add .= " seconds'";
        }
        return "now()" . $add;
    }
    /**
     * Return SQL statement for case insensitive LIKE
     *
     * @param string $column Field name
program/lib/Roundcube/rcube_db_sqlite.php
@@ -94,11 +94,17 @@
    /**
     * Return SQL function for current time and date
     *
     * @param int $interval Optional interval (in seconds) to add/subtract
     *
     * @return string SQL function to use in query
     */
    public function now()
    public function now($interval = 0)
    {
        return "datetime('now')";
        if ($interval) {
            $add = ($interval > 0 ? '+' : '') . intval($interval) . ' seconds';
        }
        return "datetime('now'" . ($add ? ",'$add'" : "") . ")";
    }
    /**
program/lib/Roundcube/rcube_db_sqlsrv.php
@@ -48,10 +48,17 @@
    /**
     * Return SQL function for current time and date
     *
     * @param int $interval Optional interval (in seconds) to add/subtract
     *
     * @return string SQL function to use in query
     */
    public function now()
    public function now($interval = 0)
    {
        if ($interval) {
            $interval = intval($interval);
            return "dateadd(second, $interval, getdate())";
        }
        return "getdate()";
    }