Re-add tableName call to insert, whitespace/docs cleanup.
authorGreg Sabino Mullane <greg@users.mediawiki.org>
Tue, 15 May 2007 12:14:20 +0000 (12:14 +0000)
committerGreg Sabino Mullane <greg@users.mediawiki.org>
Tue, 15 May 2007 12:14:20 +0000 (12:14 +0000)
includes/DatabasePostgres.php

index 574c482..84e8c64 100644 (file)
@@ -378,7 +378,10 @@ class DatabasePostgres extends Database {
                                        "WHERE relname = 'pg_pltemplate' AND nspname='pg_catalog'";
                                $rows = $this->numRows($this->doQuery($SQL));
                                if ($rows >= 1) {
+                                       $olde = error_reporting(0);
+                                       error_reporting($olde - E_WARNING);
                                        $result = $this->doQuery("CREATE LANGUAGE plpgsql");
+                                       error_reporting($olde);
                                        if (!$result) {
                                                print "<b>FAILED</b>. You need to install the language plpgsql in the database <tt>$wgDBname</tt></li>";
                                                dieout("</ul>");
@@ -622,34 +625,50 @@ class DatabasePostgres extends Database {
 
        }
 
-       function insert( $table, $a, $fname = 'DatabasePostgres::insert', $options = array() ) {
+       /**
+        * INSERT wrapper, inserts an array into a table
+        *
+        * $args may be a single associative array, or an array of these with numeric keys, 
+        * for multi-row insert (Postgres version 8.2 and above only).
+        *
+        * @param array $table   String: Name of the table to insert to.
+        * @param array $args    Array: Items to insert into the table.
+        * @param array $fname   String: Name of the function, for profiling
+        * @param mixed $options String or Array. Valid options: IGNORE
+        *
+        * @return bool Success of insert operation. IGNORE always returns true.
+        */
+       function insert( $table, $args, $fname = 'DatabasePostgres::insert', $options = array() ) {
                global $wgDBversion;
 
-               if (! defined( $wgDBversion ) )
-                       $wgDBversion = 8.1;
+               $table = $this->tableName( $table );
+               if (! defined( $wgDBversion ) ) {
+                       $this->getServerVersion();
+                       $wgDBversion = $this->numeric_version;
+               }
 
-               if ( !is_array($options))
-                       $options = array($options);
+               if ( !is_array( $options ) )
+                       $options = array( $options );
 
-               if ( isset( $a[0] ) && is_array( $a[0] ) ) {
+               if ( isset( $args[0] ) && is_array( $args[0] ) ) {
                        $multi = true;
-                       $keys = array_keys( $a[0] );
+                       $keys = array_keys( $args[0] );
                }
                else {
                        $multi = false;
-                       $keys = array_keys( $a );
+                       $keys = array_keys( $args );
                }
 
-               $ignore = in_array('IGNORE',$options) ? 1 : 0;
-               if ($ignore)
-                       $olde = error_reporting(0);
+               $ignore = in_array( 'IGNORE', $options ) ? 1 : 0;
+               if ( $ignore )
+                       $olde = error_reporting( 0 );
 
                $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES ';
 
                if ( $multi ) {
                        if ( $wgDBversion >= 8.1 ) {
                                $first = true;
-                               foreach ( $a as $row ) {
+                               foreach ( $args as $row ) {
                                        if ( $first ) {
                                                $first = false;
                                        } else {
@@ -662,7 +681,7 @@ class DatabasePostgres extends Database {
                        else {
                                $res = true;
                                $origsql = $sql;
-                               foreach ( $a as $row ) {
+                               foreach ( $args as $row ) {
                                        $tempsql = $origsql;
                                        $tempsql .= '(' . $this->makeList( $row ) . ')';
                                        $tempres = (bool)$this->query( $tempsql, $fname, $ignore );
@@ -672,12 +691,14 @@ class DatabasePostgres extends Database {
                        }
                }
                else {
-                       $sql .= '(' . $this->makeList( $a ) . ')';
+                       $sql .= '(' . $this->makeList( $args ) . ')';
                        $res = (bool)$this->query( $sql, $fname, $ignore );
                }
 
-               if ($ignore)
+               if ( $ignore ) {
                        $olde = error_reporting( $olde );
+                       return true;
+               }
 
                return $res;