Give SQLite a translation for MySQL's UNIX_TIMESTAMP() functions. Pg will probably...
authorMark A. Hershberger <mah@users.mediawiki.org>
Thu, 25 Nov 2010 07:39:51 +0000 (07:39 +0000)
committerMark A. Hershberger <mah@users.mediawiki.org>
Thu, 25 Nov 2010 07:39:51 +0000 (07:39 +0000)
includes/db/Database.php
includes/db/DatabaseSqlite.php

index 26d4d2b..94b95fe 100644 (file)
@@ -596,6 +596,14 @@ abstract class DatabaseBase implements DatabaseType {
                return !preg_match( '/^(?:SELECT|BEGIN|COMMIT|SET|SHOW|\(SELECT)\b/i', $sql );
        }
 
+       /**
+        * Database specific translations like MySQL's UNIX_TIMESTAMP() to
+        * something the DB can use.
+        */
+       function translateSQLFunctions( $vars ) {
+               return $vars;
+       }
+
        /**
         * Usually aborts on failure.  If errors are explicitly ignored, returns success.
         *
@@ -650,7 +658,7 @@ abstract class DatabaseBase implements DatabaseType {
                        } else {
                                $userName = '';
                        }
-                       $commentedSql = preg_replace( '/\s/', " /* $fname $userName */ ", $sql, 1 );
+                       $commentedSql = $this->translateSQLFunctions( preg_replace( '/\s/', " /* $fname $userName */ ", $sql, 1 ) );
                # } else {
                #       $commentedSql = $sql;
                # }
index e29e1a4..3eb978a 100644 (file)
@@ -363,6 +363,15 @@ class DatabaseSqlite extends DatabaseBase {
                return parent::makeSelectOptions( $options );
        }
 
+       /**
+        * Database specific translations like MySQL's UNIX_TIMESTAMP() to
+        * something the DB can use.
+        */
+       function translateSQLFunctions( $vars ) {
+               return preg_replace( '/UNIX_TIMESTAMP\(([^()]+)\)/', 'strftime("%s",\1)', $vars );
+       }
+
+
        /**
         * Based on generic method (parent) with some prior SQLite-sepcific adjustments
         */