Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -276,6 +276,23 @@ |
277 | 277 | function getServerVersion() { |
278 | 278 | return mysql_get_server_info( $this->mConn ); |
279 | 279 | } |
| 280 | + |
| 281 | + function useIndexClause( $index ) { |
| 282 | + return "FORCE INDEX (" . $this->indexName( $index ) . ")"; |
| 283 | + } |
| 284 | + |
| 285 | + function lowPriorityOption() { |
| 286 | + return 'LOW_PRIORITY'; |
| 287 | + } |
| 288 | + |
| 289 | + function getSoftwareLink() { |
| 290 | + return '[http://www.mysql.com/ MySQL]'; |
| 291 | + } |
| 292 | + |
| 293 | + public function setTimeout( $timeout ) { |
| 294 | + $this->query( "SET net_read_timeout=$timeout" ); |
| 295 | + $this->query( "SET net_write_timeout=$timeout" ); |
| 296 | + } |
280 | 297 | } |
281 | 298 | |
282 | 299 | /** |
Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -589,13 +589,6 @@ |
590 | 590 | return $this->mInsertId; |
591 | 591 | } |
592 | 592 | |
593 | | - /** |
594 | | - * Oracle does not have a "USE INDEX" clause, so return an empty string |
595 | | - */ |
596 | | - function useIndexClause($index) { |
597 | | - return ''; |
598 | | - } |
599 | | - |
600 | 593 | # REPLACE query wrapper |
601 | 594 | # Oracle simulates this with a DELETE followed by INSERT |
602 | 595 | # $row is the row to insert, an associative array |
— | — | @@ -687,10 +680,6 @@ |
688 | 681 | return $size; |
689 | 682 | } |
690 | 683 | |
691 | | - function lowPriorityOption() { |
692 | | - return ''; |
693 | | - } |
694 | | - |
695 | 684 | function limitResult($sql, $limit, $offset) { |
696 | 685 | if ($offset === false) |
697 | 686 | $offset = 0; |
— | — | @@ -703,19 +692,6 @@ |
704 | 693 | return 'SELECT * '.($all?'':'/* UNION_UNIQUE */ ').'FROM ('.implode( $glue, $sqls ).')' ; |
705 | 694 | } |
706 | 695 | |
707 | | - /** |
708 | | - * Returns an SQL expression for a simple conditional. |
709 | | - * Uses CASE on Oracle |
710 | | - * |
711 | | - * @param $cond String: SQL expression which will result in a boolean value |
712 | | - * @param $trueVal String: SQL expression to return if true |
713 | | - * @param $falseVal String: SQL expression to return if false |
714 | | - * @return String: SQL fragment |
715 | | - */ |
716 | | - function conditional( $cond, $trueVal, $falseVal ) { |
717 | | - return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) "; |
718 | | - } |
719 | | - |
720 | 696 | function wasDeadlock() { |
721 | 697 | return $this->lastErrno() == 'OCI-00060'; |
722 | 698 | } |
— | — | @@ -1043,10 +1019,6 @@ |
1044 | 1020 | return 'BITOR('.$fieldLeft.', '.$fieldRight.')'; |
1045 | 1021 | } |
1046 | 1022 | |
1047 | | - public function setTimeout( $timeout ) { |
1048 | | - // @todo fixme no-op |
1049 | | - } |
1050 | | - |
1051 | 1023 | /** |
1052 | 1024 | * How lagged is this slave? |
1053 | 1025 | * |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -909,13 +909,6 @@ |
910 | 910 | return $currval; |
911 | 911 | } |
912 | 912 | |
913 | | - /** |
914 | | - * Postgres does not have a "USE INDEX" clause, so return an empty string |
915 | | - */ |
916 | | - function useIndexClause( $index ) { |
917 | | - return ''; |
918 | | - } |
919 | | - |
920 | 913 | # REPLACE query wrapper |
921 | 914 | # Postgres simulates this with a DELETE followed by INSERT |
922 | 915 | # $row is the row to insert, an associative array |
— | — | @@ -1009,27 +1002,10 @@ |
1010 | 1003 | return $size; |
1011 | 1004 | } |
1012 | 1005 | |
1013 | | - function lowPriorityOption() { |
1014 | | - return ''; |
1015 | | - } |
1016 | | - |
1017 | 1006 | function limitResult($sql, $limit, $offset=false) { |
1018 | 1007 | return "$sql LIMIT $limit ".(is_numeric($offset)?" OFFSET {$offset} ":""); |
1019 | 1008 | } |
1020 | 1009 | |
1021 | | - /** |
1022 | | - * Returns an SQL expression for a simple conditional. |
1023 | | - * Uses CASE on Postgres |
1024 | | - * |
1025 | | - * @param $cond String: SQL expression which will result in a boolean value |
1026 | | - * @param $trueVal String: SQL expression to return if true |
1027 | | - * @param $falseVal String: SQL expression to return if false |
1028 | | - * @return String: SQL fragment |
1029 | | - */ |
1030 | | - function conditional( $cond, $trueVal, $falseVal ) { |
1031 | | - return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) "; |
1032 | | - } |
1033 | | - |
1034 | 1010 | function wasDeadlock() { |
1035 | 1011 | return $this->lastErrno() == '40P01'; |
1036 | 1012 | } |
— | — | @@ -1387,10 +1363,6 @@ |
1388 | 1364 | return array( $startOpts, $useIndex, $preLimitTail, $postLimitTail ); |
1389 | 1365 | } |
1390 | 1366 | |
1391 | | - public function setTimeout( $timeout ) { |
1392 | | - // @todo fixme no-op |
1393 | | - } |
1394 | | - |
1395 | 1367 | /** |
1396 | 1368 | * How lagged is this slave? |
1397 | 1369 | * |
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php |
— | — | @@ -1238,15 +1238,6 @@ |
1239 | 1239 | } |
1240 | 1240 | |
1241 | 1241 | /** |
1242 | | - * USE INDEX clause |
1243 | | - * DB2 doesn't have them and returns "" |
1244 | | - * @param sting $index |
1245 | | - */ |
1246 | | - public function useIndexClause( $index ) { |
1247 | | - return ""; |
1248 | | - } |
1249 | | - |
1250 | | - /** |
1251 | 1242 | * Simulates REPLACE with a DELETE followed by INSERT |
1252 | 1243 | * @param $table Object |
1253 | 1244 | * @param array $uniqueIndexes array consisting of indexes and arrays of indexes |
— | — | @@ -1462,19 +1453,6 @@ |
1463 | 1454 | return "[http://www.ibm.com/software/data/db2/express/?s_cmp=ECDDWW01&s_tact=MediaWiki IBM DB2]"; |
1464 | 1455 | } |
1465 | 1456 | |
1466 | | - /** |
1467 | | - * Returns an SQL expression for a simple conditional. |
1468 | | - * Uses CASE on DB2 |
1469 | | - * |
1470 | | - * @param string $cond SQL expression which will result in a boolean value |
1471 | | - * @param string $trueVal SQL expression to return if true |
1472 | | - * @param string $falseVal SQL expression to return if false |
1473 | | - * @return string SQL fragment |
1474 | | - */ |
1475 | | - public function conditional( $cond, $trueVal, $falseVal ) { |
1476 | | - return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) "; |
1477 | | - } |
1478 | | - |
1479 | 1457 | ### |
1480 | 1458 | # Fix search crash |
1481 | 1459 | ### |
— | — | @@ -1539,11 +1517,6 @@ |
1540 | 1518 | public function getStatus( $which ) { wfDebug('Not implemented for DB2: getStatus()'); return ''; } |
1541 | 1519 | /** |
1542 | 1520 | * Not implemented |
1543 | | - * @deprecated |
1544 | | - */ |
1545 | | - public function setTimeout( $timeout ) { wfDebug('Not implemented for DB2: setTimeout()'); } |
1546 | | - /** |
1547 | | - * Not implemented |
1548 | 1521 | * TODO |
1549 | 1522 | * @return bool true |
1550 | 1523 | */ |
— | — | @@ -1570,12 +1543,6 @@ |
1571 | 1544 | * @deprecated |
1572 | 1545 | */ |
1573 | 1546 | public function limitResultForUpdate($sql, $num) { return $sql; } |
1574 | | - /** |
1575 | | - * No such option |
1576 | | - * @return string '' |
1577 | | - * @deprecated |
1578 | | - */ |
1579 | | - public function lowPriorityOption() { return ''; } |
1580 | 1547 | |
1581 | 1548 | ###################################### |
1582 | 1549 | # Reflection |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -1481,11 +1481,15 @@ |
1482 | 1482 | } |
1483 | 1483 | |
1484 | 1484 | /** |
1485 | | - * USE INDEX clause |
1486 | | - * PostgreSQL doesn't have them and returns "" |
| 1485 | + * USE INDEX clause. Unlikely to be useful for anything but MySQL. This |
| 1486 | + * is only needed because a) MySQL must be as efficient as possible due to |
| 1487 | + * its use on Wikipedia, and b) MySQL 4.0 is kind of dumb sometimes about |
| 1488 | + * which index to pick. Anyway, other databases might have different |
| 1489 | + * indexes on a given table. So don't bother overriding this unless you're |
| 1490 | + * MySQL. |
1487 | 1491 | */ |
1488 | 1492 | function useIndexClause( $index ) { |
1489 | | - return "FORCE INDEX (" . $this->indexName( $index ) . ")"; |
| 1493 | + return ''; |
1490 | 1494 | } |
1491 | 1495 | |
1492 | 1496 | /** |
— | — | @@ -1573,10 +1577,14 @@ |
1574 | 1578 | } |
1575 | 1579 | |
1576 | 1580 | /** |
| 1581 | + * A string to insert into queries to show that they're low-priority, like |
| 1582 | + * MySQL's LOW_PRIORITY. If no such feature exists, return an empty |
| 1583 | + * string and nothing bad should happen. |
| 1584 | + * |
1577 | 1585 | * @return string Returns the text of the low priority option if it is supported, or a blank string otherwise |
1578 | 1586 | */ |
1579 | 1587 | function lowPriorityOption() { |
1580 | | - return 'LOW_PRIORITY'; |
| 1588 | + return ''; |
1581 | 1589 | } |
1582 | 1590 | |
1583 | 1591 | /** |
— | — | @@ -1630,22 +1638,33 @@ |
1631 | 1639 | } |
1632 | 1640 | |
1633 | 1641 | /** |
1634 | | - * Construct a LIMIT query with optional offset |
1635 | | - * This is used for query pages |
| 1642 | + * Construct a LIMIT query with optional offset. This is used for query |
| 1643 | + * pages. The SQL should be adjusted so that only the first $limit rows |
| 1644 | + * are returned. If $offset is provided as well, then the first $offset |
| 1645 | + * rows should be discarded, and the next $limit rows should be returned. |
| 1646 | + * If the result of the query is not ordered, then the rows to be returned |
| 1647 | + * are theoretically arbitrary. |
| 1648 | + * |
| 1649 | + * $sql is expected to be a SELECT, if that makes a difference. For |
| 1650 | + * UPDATE, limitResultForUpdate should be used. |
| 1651 | + * |
| 1652 | + * The version provided by default works in MySQL and SQLite. It will very |
| 1653 | + * likely need to be overridden for most other DBMSes. |
| 1654 | + * |
1636 | 1655 | * @param $sql String: SQL query we will append the limit too |
1637 | 1656 | * @param $limit Integer: the SQL limit |
1638 | 1657 | * @param $offset Integer the SQL offset (default false) |
1639 | 1658 | */ |
1640 | | - function limitResult($sql, $limit, $offset=false) { |
1641 | | - if( !is_numeric($limit) ) { |
| 1659 | + function limitResult( $sql, $limit, $offset=false ) { |
| 1660 | + if( !is_numeric( $limit ) ) { |
1642 | 1661 | throw new DBUnexpectedError( $this, "Invalid non-numeric limit passed to limitResult()\n" ); |
1643 | 1662 | } |
1644 | 1663 | return "$sql LIMIT " |
1645 | 1664 | . ( (is_numeric($offset) && $offset != 0) ? "{$offset}," : "" ) |
1646 | 1665 | . "{$limit} "; |
1647 | 1666 | } |
1648 | | - function limitResultForUpdate($sql, $num) { |
1649 | | - return $this->limitResult($sql, $num, 0); |
| 1667 | + function limitResultForUpdate( $sql, $num ) { |
| 1668 | + return $this->limitResult( $sql, $num, 0 ); |
1650 | 1669 | } |
1651 | 1670 | |
1652 | 1671 | /** |
— | — | @@ -1662,8 +1681,8 @@ |
1663 | 1682 | } |
1664 | 1683 | |
1665 | 1684 | /** |
1666 | | - * Returns an SQL expression for a simple conditional. |
1667 | | - * Uses IF on MySQL. |
| 1685 | + * Returns an SQL expression for a simple conditional. This doesn't need |
| 1686 | + * to be overridden unless CASE isn't supported in your DBMS. |
1668 | 1687 | * |
1669 | 1688 | * @param $cond String: SQL expression which will result in a boolean value |
1670 | 1689 | * @param $trueVal String: SQL expression to return if true |
— | — | @@ -1671,7 +1690,7 @@ |
1672 | 1691 | * @return String: SQL fragment |
1673 | 1692 | */ |
1674 | 1693 | function conditional( $cond, $trueVal, $falseVal ) { |
1675 | | - return " IF($cond, $trueVal, $falseVal) "; |
| 1694 | + return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) "; |
1676 | 1695 | } |
1677 | 1696 | |
1678 | 1697 | /** |
— | — | @@ -1922,13 +1941,21 @@ |
1923 | 1942 | } |
1924 | 1943 | |
1925 | 1944 | /** |
| 1945 | + * Returns a wikitext link to the DB's website, e.g., |
| 1946 | + * return "[http://www.mysql.com/ MySQL]"; |
| 1947 | + * Should probably be overridden to at least contain plain text, if for |
| 1948 | + * some reason your database has no website. |
| 1949 | + * |
1926 | 1950 | * @return String: wikitext of a link to the server software's web site |
1927 | 1951 | */ |
1928 | 1952 | function getSoftwareLink() { |
1929 | | - return "[http://www.mysql.com/ MySQL]"; |
| 1953 | + return '(no software link given)'; |
1930 | 1954 | } |
1931 | 1955 | |
1932 | 1956 | /** |
| 1957 | + * A string describing the current software version, like from |
| 1958 | + * mysql_get_server_info(). Will be listed on Special:Version, etc. |
| 1959 | + * |
1933 | 1960 | * @return String: Version information from the database |
1934 | 1961 | */ |
1935 | 1962 | abstract function getServerVersion(); |
— | — | @@ -2007,16 +2034,14 @@ |
2008 | 2035 | } |
2009 | 2036 | |
2010 | 2037 | /** |
2011 | | - * Override database's default connection timeout. |
2012 | | - * May be useful for very long batch queries such as |
2013 | | - * full-wiki dumps, where a single query reads out |
2014 | | - * over hours or days. |
| 2038 | + * Override database's default connection timeout. May be useful for very |
| 2039 | + * long batch queries such as full-wiki dumps, where a single query reads |
| 2040 | + * out over hours or days. May or may not be necessary for non-MySQL |
| 2041 | + * databases. For most purposes, leaving it as a no-op should be fine. |
| 2042 | + * |
2015 | 2043 | * @param $timeout Integer in seconds |
2016 | 2044 | */ |
2017 | | - public function setTimeout( $timeout ) { |
2018 | | - $this->query( "SET net_read_timeout=$timeout" ); |
2019 | | - $this->query( "SET net_write_timeout=$timeout" ); |
2020 | | - } |
| 2045 | + public function setTimeout( $timeout ) {} |
2021 | 2046 | |
2022 | 2047 | /** |
2023 | 2048 | * Read and execute SQL commands from a file. |
Index: trunk/phase3/includes/db/DatabaseMssql.php |
— | — | @@ -708,13 +708,6 @@ |
709 | 709 | } |
710 | 710 | |
711 | 711 | /** |
712 | | - * USE INDEX clause |
713 | | - */ |
714 | | - function useIndexClause( $index ) { |
715 | | - return ""; |
716 | | - } |
717 | | - |
718 | | - /** |
719 | 712 | * REPLACE query wrapper |
720 | 713 | * PostgreSQL simulates this with a DELETE followed by INSERT |
721 | 714 | * $row is the row to insert, an associative array |
— | — | @@ -858,18 +851,6 @@ |
859 | 852 | } |
860 | 853 | |
861 | 854 | /** |
862 | | - * Returns an SQL expression for a simple conditional. |
863 | | - * |
864 | | - * @param $cond String: SQL expression which will result in a boolean value |
865 | | - * @param $trueVal String: SQL expression to return if true |
866 | | - * @param $falseVal String: SQL expression to return if false |
867 | | - * @return string SQL fragment |
868 | | - */ |
869 | | - function conditional( $cond, $trueVal, $falseVal ) { |
870 | | - return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) "; |
871 | | - } |
872 | | - |
873 | | - /** |
874 | 855 | * Should determine if the last failure was due to a deadlock |
875 | 856 | * @return bool |
876 | 857 | */ |
— | — | @@ -931,11 +912,6 @@ |
932 | 913 | } |
933 | 914 | |
934 | 915 | /** |
935 | | - * not done |
936 | | - */ |
937 | | - public function setTimeout($timeout) { return; } |
938 | | - |
939 | | - /** |
940 | 916 | * How lagged is this slave? |
941 | 917 | */ |
942 | 918 | public function getLag() { |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -265,13 +265,6 @@ |
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
269 | | - * SQLite does not have a "USE INDEX" clause, so return an empty string |
270 | | - */ |
271 | | - function useIndexClause($index) { |
272 | | - return ''; |
273 | | - } |
274 | | - |
275 | | - /** |
276 | 269 | * Returns the size of a text field, or -1 for "unlimited" |
277 | 270 | * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though. |
278 | 271 | */ |
— | — | @@ -279,21 +272,6 @@ |
280 | 273 | return -1; |
281 | 274 | } |
282 | 275 | |
283 | | - /** |
284 | | - * No low priority option in SQLite |
285 | | - */ |
286 | | - function lowPriorityOption() { |
287 | | - return ''; |
288 | | - } |
289 | | - |
290 | | - /** |
291 | | - * Returns an SQL expression for a simple conditional. |
292 | | - * - uses CASE on SQLite |
293 | | - */ |
294 | | - function conditional($cond, $trueVal, $falseVal) { |
295 | | - return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) "; |
296 | | - } |
297 | | - |
298 | 276 | function wasDeadlock() { |
299 | 277 | return $this->lastErrno() == SQLITE_BUSY; |
300 | 278 | } |
— | — | @@ -390,11 +368,6 @@ |
391 | 369 | function quote_ident($s) { return $s; } |
392 | 370 | |
393 | 371 | /** |
394 | | - * not done |
395 | | - */ |
396 | | - public function setTimeout($timeout) { return; } |
397 | | - |
398 | | - /** |
399 | 372 | * How lagged is this slave? |
400 | 373 | */ |
401 | 374 | public function getLag() { |