r90363 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r90362‎ | r90363 | r90364 >
Date:20:26, 18 June 2011
Author:platonides
Status:ok
Tags:
Comment:
All the databases but MySQL were overriding DatabaseBase::deleteJoin() with the same code.
Move DatabaseBase::deleteJoin() to DatabaseMysql::deleteJoin() and the common code to DatabaseBase::deleteJoin()
Follow up r90356
Modified paths:
  • /trunk/phase3/includes/db/Database.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseIbm_db2.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMssql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseMysql.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseOracle.php (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/db/DatabaseSqlite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/db/DatabaseMysql.php
@@ -483,6 +483,25 @@
484484 }
485485
486486 /**
 487+ * DELETE where the condition is a join. MySql uses multi-table deletes.
 488+ */
 489+ function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseBase::deleteJoin' ) {
 490+ if ( !$conds ) {
 491+ throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' );
 492+ }
 493+
 494+ $delTable = $this->tableName( $delTable );
 495+ $joinTable = $this->tableName( $joinTable );
 496+ $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
 497+
 498+ if ( $conds != '*' ) {
 499+ $sql .= ' AND ' . $this->makeList( $conds, LIST_AND );
 500+ }
 501+
 502+ return $this->query( $sql, $fname );
 503+ }
 504+
 505+ /**
487506 * Determines if the last failure was due to a deadlock
488507 */
489508 function wasDeadlock() {
Index: trunk/phase3/includes/db/DatabaseOracle.php
@@ -767,23 +767,6 @@
768768 }
769769 }
770770
771 - # DELETE where the condition is a join
772 - function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseOracle::deleteJoin' ) {
773 - if ( !$conds ) {
774 - throw new DBUnexpectedError( $this, 'DatabaseOracle::deleteJoin() called with empty $conds' );
775 - }
776 -
777 - $delTable = $this->tableName( $delTable );
778 - $joinTable = $this->tableName( $joinTable );
779 - $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
780 - if ( $conds != '*' ) {
781 - $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
782 - }
783 - $sql .= ')';
784 -
785 - $this->query( $sql, $fname );
786 - }
787 -
788771 # Returns the size of a text field, or -1 for "unlimited"
789772 function textFieldSize( $table, $field ) {
790773 $fieldInfoData = $this->fieldInfo( $table, $field );
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -707,23 +707,6 @@
708708 }
709709 }
710710
711 - # DELETE where the condition is a join
712 - function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabasePostgres::deleteJoin' ) {
713 - if ( !$conds ) {
714 - throw new DBUnexpectedError( $this, 'DatabasePostgres::deleteJoin() called with empty $conds' );
715 - }
716 -
717 - $delTable = $this->tableName( $delTable );
718 - $joinTable = $this->tableName( $joinTable );
719 - $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
720 - if ( $conds != '*' ) {
721 - $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
722 - }
723 - $sql .= ')';
724 -
725 - $this->query( $sql, $fname );
726 - }
727 -
728711 # Returns the size of a text field, or -1 for "unlimited"
729712 function textFieldSize( $table, $field ) {
730713 $table = $this->tableName( $table );
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php
@@ -1480,39 +1480,6 @@
14811481 }
14821482
14831483 /**
1484 - * DELETE where the condition is a join
1485 - * @param $delTable String: deleting from this table
1486 - * @param $joinTable String: using data from this table
1487 - * @param $delVar String: variable in deleteable table
1488 - * @param $joinVar String: variable in data table
1489 - * @param $conds Array: conditionals for join table
1490 - * @param $fname String: function name for profiling
1491 - */
1492 - public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar,
1493 - $conds, $fname = "DatabaseIbm_db2::deleteJoin" )
1494 - {
1495 - if ( !$conds ) {
1496 - throw new DBUnexpectedError( $this,
1497 - 'DatabaseIbm_db2::deleteJoin() called with empty $conds' );
1498 - }
1499 -
1500 - $delTable = $this->tableName( $delTable );
1501 - $joinTable = $this->tableName( $joinTable );
1502 - $sql = <<<SQL
1503 -DELETE FROM $delTable
1504 -WHERE $delVar IN (
1505 - SELECT $joinVar FROM $joinTable
1506 -
1507 -SQL;
1508 - if ( $conds != '*' ) {
1509 - $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
1510 - }
1511 - $sql .= ' )';
1512 -
1513 - $this->query( $sql, $fname );
1514 - }
1515 -
1516 - /**
15171484 * Description is left as an exercise for the reader
15181485 * @param $b Mixed: data to be encoded
15191486 * @return IBM_DB2Blob
Index: trunk/phase3/includes/db/Database.php
@@ -2004,7 +2004,7 @@
20052005
20062006 /**
20072007 * DELETE where the condition is a join
2008 - * MySQL does this with a multi-table DELETE syntax, PostgreSQL does it with sub-selects
 2008+ * MySQL overrides this to use a multi-table DELETE syntax, in other databases we use sub-selects
20092009 *
20102010 * For safety, an empty $conds will not delete everything. If you want to delete all rows where the
20112011 * join condition matches, set $conds='*'
@@ -2025,13 +2025,13 @@
20262026
20272027 $delTable = $this->tableName( $delTable );
20282028 $joinTable = $this->tableName( $joinTable );
2029 - $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
2030 -
 2029+ $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
20312030 if ( $conds != '*' ) {
2032 - $sql .= ' AND ' . $this->makeList( $conds, LIST_AND );
 2031+ $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
20332032 }
 2033+ $sql .= ')';
20342034
2035 - return $this->query( $sql, $fname );
 2035+ $this->query( $sql, $fname );
20362036 }
20372037
20382038 /**
Index: trunk/phase3/includes/db/DatabaseMssql.php
@@ -598,23 +598,6 @@
599599 }
600600 }
601601
602 - # DELETE where the condition is a join
603 - function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = "DatabaseMssql::deleteJoin" ) {
604 - if ( !$conds ) {
605 - throw new DBUnexpectedError( $this, 'DatabaseMssql::deleteJoin() called with empty $conds' );
606 - }
607 -
608 - $delTable = $this->tableName( $delTable );
609 - $joinTable = $this->tableName( $joinTable );
610 - $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable ";
611 - if ( $conds != '*' ) {
612 - $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND );
613 - }
614 - $sql .= ')';
615 -
616 - $this->query( $sql, $fname );
617 - }
618 -
619602 # Returns the size of a text field, or -1 for "unlimited"
620603 function textFieldSize( $table, $field ) {
621604 $table = $this->tableName( $table );
Index: trunk/phase3/includes/db/DatabaseSqlite.php
@@ -544,35 +544,6 @@
545545 }
546546
547547 /**
548 - * DELETE where the condition is a join
549 - *
550 - * @param $delTable String: The table to delete from.
551 - * @param $joinTable String: The other table.
552 - * @param $delVar String: The variable to join on, in the first table.
553 - * @param $joinVar String: The variable to join on, in the second table.
554 - * @param $conds Array: Condition array of field names mapped to variables, ANDed together in the WHERE clause
555 - * @param $fname String: Calling function name (use __METHOD__) for logs/profiling
556 - */
557 - public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
558 - $fname = 'DatabaseSqlite::deleteJoin' )
559 - {
560 - if ( !$conds ) {
561 - throw new DBUnexpectedError( $this,
562 - 'DatabaseSqlite::deleteJoin() called with empty $conds' );
563 - }
564 -
565 - $delTable = $this->tableName( $delTable );
566 - $joinTable = $this->tableName( $joinTable );
567 - $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable";
568 - if ( $conds != '*' ) {
569 - $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
570 - }
571 - $sql .= ')';
572 -
573 - $this->query( $sql, $fname );
574 - }
575 -
576 - /**
577548 * Returns the size of a text field, or -1 for "unlimited"
578549 * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though.
579550 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r90364Follow-up r90356 & r90363: test deleteJoin() on SQLitemaxsem20:37, 18 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90356(bug 29476) DatabaseBase::deleteJoin fails for Sqlite...mgrabovsky18:58, 18 June 2011

Status & tagging log