diff options
author | Tim Starling <tstarling@users.mediawiki.org> | 2004-07-18 08:48:43 +0000 |
---|---|---|
committer | Tim Starling <tstarling@users.mediawiki.org> | 2004-07-18 08:48:43 +0000 |
commit | ac549401d4ddaf655ec47cd1e66092fdc83ab30b (patch) | |
tree | 44156235c5ff0c2a40406d3c211895da41177a03 /includes/DatabasePostgreSQL.php | |
parent | d052c2c95d346baa97a57af975d67be92f33f45c (diff) | |
download | mediawikicore-ac549401d4ddaf655ec47cd1e66092fdc83ab30b.tar.gz mediawikicore-ac549401d4ddaf655ec47cd1e66092fdc83ab30b.zip |
* Support for table name prefixes throughout the code. No support yet for converting static SQL, which also means no installation. But it has been tested by creating the tables in the ordinary way and then renaming them
* DB_WRITE now called DB_MASTER, DB_READ now called DB_SLAVE
* Converted to use SQL wrapper functions instead of direct SQL in various places
* Experimental method for preserving the chronological order of events when slave servers are used. Untested.
* Fixes to the new post-parse existence test feature
* Some.. other stuff
Notes
Notes:
http://mediawiki.org/wiki/Special:Code/MediaWiki/4318
Diffstat (limited to 'includes/DatabasePostgreSQL.php')
-rw-r--r-- | includes/DatabasePostgreSQL.php | 100 |
1 files changed, 52 insertions, 48 deletions
diff --git a/includes/DatabasePostgreSQL.php b/includes/DatabasePostgreSQL.php index 5edaa8c4e65d..06a79aa47f64 100644 --- a/includes/DatabasePostgreSQL.php +++ b/includes/DatabasePostgreSQL.php @@ -209,14 +209,23 @@ class DatabasePgsql extends Database { function insertArray( $table, $a, $fname = "Database::insertArray", $options = array() ) { # PostgreSQL doesn't support options - # We have a go at faking some of them + # We have a go at faking one of them + # TODO: DELAYED, LOW_PRIORITY + + # IGNORE is performed using single-row inserts, ignoring errors in each if ( in_array( 'IGNORE', $options ) ) { - $ignore = true; + # FIXME: need some way to distiguish between key collision and other types of error $oldIgnore = $this->setIgnoreErrors( true ); - } - $retVal = parent::insertArray( $table, $a, $fname, array() ); - if ( $ignore ) { + if ( !is_array( reset( $a ) ) ) { + $a = array( $a ); + } + foreach ( $a as $row ) { + parent::insertArray( $table, $row, $fname, array() ); + } $this->setIgnoreErrors( $oldIgnore ); + $retVal = true; + } else { + $retVal = parent::insertArray( $table, $a, $fname, array() ); } return $retVal; } @@ -273,56 +282,46 @@ class DatabasePgsql extends Database { function replace( $table, $uniqueIndexes, $rows, $fname = "Database::replace" ) { $table = $this->tableName( $table ); - # Delete rows which collide - if ( $uniqueIndexes ) { - $sql = "DELETE FROM $table WHERE ("; - $first = true; - foreach ( $uniqueIndexes as $index ) { - if ( $first ) { - $first = false; - } else { - $sql .= ") OR ("; - } - if ( is_array( $col ) ) { - $first2 = true; - $sql .= "("; - foreach ( $index as $col ) { - if ( $first2 ) { - $first2 = false; - } else { - $sql .= " AND "; - } - //midom: atleast unbreak the class (remove syntax errors) - //$sql .= "$col = " $this->strencode; + # Single row case + if ( !is_array( reset( $rows ) ) ) { + $rows = array( $rows ); + } + + foreach( $rows as $row ) { + # Delete rows which collide + if ( $uniqueIndexes ) { + $sql = "DELETE FROM $table WHERE ("; + $first = true; + foreach ( $uniqueIndexes as $index ) { + if ( $first ) { + $first = false; + } else { + $sql .= ") OR ("; } - } - if ( $first ) { - $first = false; + if ( is_array( $index ) ) { + $first2 = true; + $sql .= "("; + foreach ( $index as $col ) { + if ( $first2 ) { + $first2 = false; + } else { + $sql .= " AND "; + } + $sql .= "$col=" . $this->addQuotes( $row[$col] ) + } } else { - $sql .= "OR "; + $sql .= "$index=" . $this->addQuotes( $row[$index] ); } - $sql .= "$col IN ("; - $indexValues = array(); - foreach ( $rows as $row ) { - $indexValues[] = $row[$col]; } - $sql .= $this->makeList( $indexValues, LIST_COMMA ) . ") "; + $sql .= ")"; + $this->query( $sql, $fname ); } - $this->query( $sql, $fname ); - } - # Now insert the rows - $sql = "INSERT INTO $table (" . $this->makeList( array_flip( $rows[0] ) ) .") VALUES "; - $first = true; - foreach ( $rows as $row ) { - if ( $first ) { - $first = false; - } else { - $sql .= ","; - } - $sql .= "(" . $this->makeList( $row, LIST_COMMA ) . ")"; + # Now insert the row + $sql = "INSERT INTO $table (" . $this->makeList( array_flip( $row ) ) .') VALUES (' . + $this->makeList( $row, LIST_COMMA ) . ')'; + $this->query( $sql, $fname ); } - $this->query( $sql, $fname ); } # DELETE where the condition is a join @@ -358,6 +357,11 @@ class DatabasePgsql extends Database { function limitResult($limit,$offset) { return " LIMIT $limit ".(is_numeric($offset)?" OFFSET {$offset} ":""); } + + # FIXME: actually detecting deadlocks might be nice + function wasDeadlock() { + return false; + } } # Just an alias. |