more cssification of diff rendering, some " -> ' in diff engine
[lhc/web/wiklou.git] / includes / Database.php
index cada7e3..60647d5 100644 (file)
@@ -1,6 +1,9 @@
 <?php
-include_once( "FulltextStoplist.php" );
-include_once( "CacheManager.php" );
+# $Id$
+# This file deals with MySQL interface functions 
+# and query specifics/optimisations
+#
+require_once( "CacheManager.php" );
 
 define( "DB_READ", -1 );
 define( "DB_WRITE", -2 );
@@ -174,13 +177,15 @@ class Database {
                }
        
                if ( false === $ret ) {
+                       $error = mysql_error( $this->mConn );
+                       $errno = mysql_errno( $this->mConn );
                        if( $this->mIgnoreErrors ) {
-                               wfDebug("SQL ERROR (ignored): " . mysql_error( $this->mConn ) . "\n");
+                               wfDebug("SQL ERROR (ignored): " . $error . "\n");
                        } else {
-                               wfDebug("SQL ERROR: " . mysql_error( $this->mConn ) . "\n");
+                               wfDebug("SQL ERROR: " . $error . "\n");
                                if ( $this->mOut ) {
                                        // this calls wfAbruptExit()
-                                       $this->mOut->databaseError( $fname, $this );                            
+                                       $this->mOut->databaseError( $fname, $sql, $error, $errno );                             
                                }
                        }
                }
@@ -204,6 +209,15 @@ class Database {
                }
                return $row;
        }
+       
+       function fetchRow( $res ) {
+               @$row = mysql_fetch_array( $res );
+               if (mysql_errno() ) {
+                       wfDebugDieBacktrace( "SQL error: " . htmlspecialchars( mysql_error() ) );
+               }
+               return $row;
+       }       
+
        function numRows( $res ) {
                @$n = mysql_num_rows( $res ); 
                if( mysql_errno() ) {
@@ -314,7 +328,10 @@ class Database {
        # If errors are explicitly ignored, returns NULL on failure
        function indexExists( $table, $index, $fname = "Database::indexExists" ) 
        {
-               $sql = "SHOW INDEXES FROM $table";
+               # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
+               # SHOW INDEX should work for 3.x and up:
+               # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html
+               $sql = "SHOW INDEX FROM $table";
                $res = $this->query( $sql, DB_READ, $fname );
                if ( !$res ) {
                        return NULL;
@@ -334,6 +351,7 @@ class Database {
        function tableExists( $table )
        {
                $old = $this->mIgnoreErrors;
+               $this->mIgnoreErrors = true;
                $res = $this->query( "SELECT 1 FROM $table LIMIT 1" );
                $this->mIgnoreErrors = $old;
                if( $res ) {
@@ -515,4 +533,9 @@ function wfInvertTimestamp( $ts ) {
                "9876543210"
        );
 }
+
+function wfLimitResult( $limit, $offset ) {
+       return " LIMIT ".(is_numeric($offset)?"{$offset},":"")."{$limit} ";
+}
+
 ?>