Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -483,6 +483,25 @@ |
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
| 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 | + /** |
487 | 506 | * Determines if the last failure was due to a deadlock |
488 | 507 | */ |
489 | 508 | function wasDeadlock() { |
Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -767,23 +767,6 @@ |
768 | 768 | } |
769 | 769 | } |
770 | 770 | |
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 | | - |
788 | 771 | # Returns the size of a text field, or -1 for "unlimited" |
789 | 772 | function textFieldSize( $table, $field ) { |
790 | 773 | $fieldInfoData = $this->fieldInfo( $table, $field ); |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -707,23 +707,6 @@ |
708 | 708 | } |
709 | 709 | } |
710 | 710 | |
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 | | - |
728 | 711 | # Returns the size of a text field, or -1 for "unlimited" |
729 | 712 | function textFieldSize( $table, $field ) { |
730 | 713 | $table = $this->tableName( $table ); |
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php |
— | — | @@ -1480,39 +1480,6 @@ |
1481 | 1481 | } |
1482 | 1482 | |
1483 | 1483 | /** |
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 | | - /** |
1517 | 1484 | * Description is left as an exercise for the reader |
1518 | 1485 | * @param $b Mixed: data to be encoded |
1519 | 1486 | * @return IBM_DB2Blob |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -2004,7 +2004,7 @@ |
2005 | 2005 | |
2006 | 2006 | /** |
2007 | 2007 | * 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 |
2009 | 2009 | * |
2010 | 2010 | * For safety, an empty $conds will not delete everything. If you want to delete all rows where the |
2011 | 2011 | * join condition matches, set $conds='*' |
— | — | @@ -2025,13 +2025,13 @@ |
2026 | 2026 | |
2027 | 2027 | $delTable = $this->tableName( $delTable ); |
2028 | 2028 | $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 "; |
2031 | 2030 | if ( $conds != '*' ) { |
2032 | | - $sql .= ' AND ' . $this->makeList( $conds, LIST_AND ); |
| 2031 | + $sql .= 'WHERE ' . $this->makeList( $conds, LIST_AND ); |
2033 | 2032 | } |
| 2033 | + $sql .= ')'; |
2034 | 2034 | |
2035 | | - return $this->query( $sql, $fname ); |
| 2035 | + $this->query( $sql, $fname ); |
2036 | 2036 | } |
2037 | 2037 | |
2038 | 2038 | /** |
Index: trunk/phase3/includes/db/DatabaseMssql.php |
— | — | @@ -598,23 +598,6 @@ |
599 | 599 | } |
600 | 600 | } |
601 | 601 | |
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 | | - |
619 | 602 | # Returns the size of a text field, or -1 for "unlimited" |
620 | 603 | function textFieldSize( $table, $field ) { |
621 | 604 | $table = $this->tableName( $table ); |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -544,35 +544,6 @@ |
545 | 545 | } |
546 | 546 | |
547 | 547 | /** |
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 | | - /** |
577 | 548 | * Returns the size of a text field, or -1 for "unlimited" |
578 | 549 | * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though. |
579 | 550 | * |