PHPDocumentor [http://en.wikipedia.org/wiki/PhpDocumentor] documentation tweaking...
[lhc/web/wiklou.git] / includes / Database.php
index 5d56064..0b1462c 100644 (file)
@@ -15,6 +15,9 @@ define( 'DEADLOCK_DELAY_MAX', 1500000 );
  * Utility classes
  *****************************************************************************/
 
+/**
+ * Utility class.
+ */
 class DBObject {
        public $mData;
 
@@ -31,6 +34,58 @@ class DBObject {
        }
 };
 
+/**
+ * Utility class.
+ */
+class MySQLField {
+       private $name, $tablename, $default, $max_length, $nullable,
+               $is_pk, $is_unique, $is_key, $type;
+       function __construct ($info) {
+               $this->name = $info->name;
+               $this->tablename = $info->table;
+               $this->default = $info->def;
+               $this->max_length = $info->max_length;
+               $this->nullable = !$info->not_null;
+               $this->is_pk = $info->primary_key;
+               $this->is_unique = $info->unique_key;
+               $this->is_multiple = $info->multiple_key;
+               $this->is_key = ($this->is_pk || $this->is_unique || $this->is_multiple);
+               $this->type = $info->type;
+       }
+
+       function name() {
+               return $this->name;
+       }
+
+       function tableName() {
+               return $this->tableName;
+       }
+
+       function defaultValue() {
+               return $this->default;
+       }
+
+       function maxLength() {
+               return $this->max_length;
+       }
+
+       function nullable() {
+               return $this->nullable;
+       }
+
+       function isKey() {
+               return $this->is_key;
+       }
+
+       function isMultipleKey() {
+               return $this->is_multiple;
+       }
+
+       function type() {
+               return $this->type;
+       }
+}
+
 /******************************************************************************
  * Error classes
  *****************************************************************************/
@@ -246,9 +301,6 @@ class Database {
        protected $mTrxLevel = 0;
        protected $mErrorCount = 0;
        protected $mLBInfo = array();
-       protected $mCascadingDeletes = false;
-       protected $mCleanupTriggers = false;
-       protected $mStrictIPs = false;
 
 #------------------------------------------------------------------------------
 # Accessors
@@ -343,14 +395,14 @@ class Database {
         * Returns true if this database supports (and uses) cascading deletes
         */
        function cascadingDeletes() {
-               return $this->mCascadingDeletes;
+               return false;
        }
 
        /**
         * Returns true if this database supports (and uses) triggers (e.g. on the page table)
         */
        function cleanupTriggers() {
-               return $this->mCleanupTriggers;
+               return false;
        }
 
        /**
@@ -358,7 +410,7 @@ class Database {
         * Specifically, it uses a NULL value instead of an empty string.
         */
        function strictIPs() {
-               return $this->mStrictIPs;
+               return false;
        }
 
        /**
@@ -413,14 +465,12 @@ class Database {
 # Other functions
 #------------------------------------------------------------------------------
 
-       /**@{{
+       /**
+        * Constructor.
         * @param string $server database server host
         * @param string $user database user name
         * @param string $password database user password
         * @param string $dbname database name
-        */
-
-       /**
         * @param failFunction
         * @param $flags
         * @param $tablePrefix String: database table prefixes. By default use the prefix gave in LocalSettings.php
@@ -470,8 +520,7 @@ class Database {
         * @param failFunction
         * @param $flags
         */
-       static function newFromParams( $server, $user, $password, $dbName,
-               $failFunction = false, $flags = 0 )
+       static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 )
        {
                return new Database( $server, $user, $password, $dbName, $failFunction, $flags );
        }
@@ -562,7 +611,6 @@ class Database {
                wfProfileOut( __METHOD__ );
                return $success;
        }
-       /**@}}*/
 
        /**
         * Closes a database connection.
@@ -984,7 +1032,7 @@ class Database {
         * @return array
         */
        function makeSelectOptions( $options ) {
-               $tailOpts = '';
+               $preLimitTail = $postLimitTail = '';
                $startOpts = '';
 
                $noKeyOptions = array();
@@ -994,8 +1042,8 @@ class Database {
                        }
                }
 
-               if ( isset( $options['GROUP BY'] ) ) $tailOpts .= " GROUP BY {$options['GROUP BY']}";
-               if ( isset( $options['ORDER BY'] ) ) $tailOpts .= " ORDER BY {$options['ORDER BY']}";
+               if ( isset( $options['GROUP BY'] ) ) $preLimitTail .= " GROUP BY {$options['GROUP BY']}";
+               if ( isset( $options['ORDER BY'] ) ) $preLimitTail .= " ORDER BY {$options['ORDER BY']}";
                
                //if (isset($options['LIMIT'])) {
                //      $tailOpts .= $this->limitResult('', $options['LIMIT'],
@@ -1003,8 +1051,8 @@ class Database {
                //              : false);
                //}
 
-               if ( isset( $noKeyOptions['FOR UPDATE'] ) ) $tailOpts .= ' FOR UPDATE';
-               if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) $tailOpts .= ' LOCK IN SHARE MODE';
+               if ( isset( $noKeyOptions['FOR UPDATE'] ) ) $postLimitTail .= ' FOR UPDATE';
+               if ( isset( $noKeyOptions['LOCK IN SHARE MODE'] ) ) $postLimitTail .= ' LOCK IN SHARE MODE';
                if ( isset( $noKeyOptions['DISTINCT'] ) && isset( $noKeyOptions['DISTINCTROW'] ) ) $startOpts .= 'DISTINCT';
 
                # Various MySQL extensions
@@ -1023,7 +1071,7 @@ class Database {
                        $useIndex = '';
                }
                
-               return array( $startOpts, $useIndex, $tailOpts );
+               return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail );
        }
 
        /**
@@ -1060,20 +1108,21 @@ class Database {
                        $from = '';
                }
 
-               list( $startOpts, $useIndex, $tailOpts ) = $this->makeSelectOptions( $options );
+               list( $startOpts, $useIndex, $preLimitTail, $postLimitTail ) = $this->makeSelectOptions( $options );
 
                if( !empty( $conds ) ) {
                        if ( is_array( $conds ) ) {
                                $conds = $this->makeList( $conds, LIST_AND );
                        }
-                       $sql = "SELECT $startOpts $vars $from $useIndex WHERE $conds $tailOpts";
+                       $sql = "SELECT $startOpts $vars $from $useIndex WHERE $conds $preLimitTail";
                } else {
-                       $sql = "SELECT $startOpts $vars $from $useIndex $tailOpts";
+                       $sql = "SELECT $startOpts $vars $from $useIndex $preLimitTail";
                }
 
                if (isset($options['LIMIT']))
                        $sql = $this->limitResult($sql, $options['LIMIT'],
                                isset($options['OFFSET']) ? $options['OFFSET'] : false);
+               $sql = "$sql $postLimitTail";
 
                return $this->query( $sql, $fname );
        }
@@ -1228,7 +1277,7 @@ class Database {
                for( $i = 0; $i < $n; $i++ ) {
                        $meta = mysql_fetch_field( $res, $i );
                        if( $field == $meta->name ) {
-                               return $meta;
+                               return new MySQLField($meta);
                        }
                }
                return false;
@@ -1438,7 +1487,7 @@ class Database {
        }
        
        /**
-        * @desc: Fetch a number of table names into an zero-indexed numerical array
+        * Fetch a number of table names into an zero-indexed numerical array
         * This is handy when you need to construct SQL for joins
         *
         * Example: