From: Greg Sabino Mullane Date: Tue, 15 May 2007 12:14:20 +0000 (+0000) Subject: Re-add tableName call to insert, whitespace/docs cleanup. X-Git-Tag: 1.31.0-rc.0~52906 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=3658901cbead8211953dc84e1766e131af4c0dd9;p=lhc%2Fweb%2Fwiklou.git Re-add tableName call to insert, whitespace/docs cleanup. --- diff --git a/includes/DatabasePostgres.php b/includes/DatabasePostgres.php index 574c482696..84e8c64f7e 100644 --- a/includes/DatabasePostgres.php +++ b/includes/DatabasePostgres.php @@ -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 "FAILED. You need to install the language plpgsql in the database $wgDBname"; dieout(""); @@ -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;