Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -329,6 +329,10 @@ |
330 | 330 | return "`" . $this->strencode( $s ) . "`"; |
331 | 331 | } |
332 | 332 | |
| 333 | + public function isQuotedIdentifier( $name ) { |
| 334 | + return $name[0] == '`' && substr( $name, -1, 1 ) == '`'; |
| 335 | + } |
| 336 | + |
333 | 337 | function ping() { |
334 | 338 | $ping = mysql_ping( $this->mConn ); |
335 | 339 | if ( $ping ) { |
Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -648,46 +648,7 @@ |
649 | 649 | break; |
650 | 650 | } |
651 | 651 | |
652 | | - /* |
653 | | - The rest of procedure is equal to generic Databse class |
654 | | - except for the quoting style |
655 | | - */ |
656 | | - if ( $name[0] == '"' && substr( $name, - 1, 1 ) == '"' ) { |
657 | | - return $name; |
658 | | - } |
659 | | - if ( preg_match( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i', $name ) !== 0 ) { |
660 | | - return $name; |
661 | | - } |
662 | | - $dbDetails = array_reverse( explode( '.', $name, 2 ) ); |
663 | | - if ( isset( $dbDetails[1] ) ) { |
664 | | - @list( $table, $database ) = $dbDetails; |
665 | | - } else { |
666 | | - @list( $table ) = $dbDetails; |
667 | | - } |
668 | | - |
669 | | - $prefix = $this->mTablePrefix; |
670 | | - |
671 | | - if ( isset( $database ) ) { |
672 | | - $table = ( $table[0] == '`' ? $table : "`{$table}`" ); |
673 | | - } |
674 | | - |
675 | | - if ( !isset( $database ) && isset( $wgSharedDB ) && $table[0] != '"' |
676 | | - && isset( $wgSharedTables ) |
677 | | - && is_array( $wgSharedTables ) |
678 | | - && in_array( $table, $wgSharedTables ) |
679 | | - ) { |
680 | | - $database = $wgSharedDB; |
681 | | - $prefix = isset( $wgSharedPrefix ) ? $wgSharedPrefix : $prefix; |
682 | | - } |
683 | | - |
684 | | - if ( isset( $database ) ) { |
685 | | - $database = ( $database[0] == '"' ? $database : "\"{$database}\"" ); |
686 | | - } |
687 | | - $table = ( $table[0] == '"') ? $table : "\"{$prefix}{$table}\"" ; |
688 | | - |
689 | | - $tableName = ( isset( $database ) ? "{$database}.{$table}" : "{$table}" ); |
690 | | - |
691 | | - return strtoupper( $tableName ); |
| 652 | + return parent::tableName( strtoupper( $name ) ); |
692 | 653 | } |
693 | 654 | |
694 | 655 | /** |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -1521,7 +1521,7 @@ |
1522 | 1522 | # Note that we check the end so that we will still quote any use of |
1523 | 1523 | # use of `database`.table. But won't break things if someone wants |
1524 | 1524 | # to query a database table with a dot in the name. |
1525 | | - if ( $name[0] == '`' && substr( $name, -1, 1 ) == '`' ) { |
| 1525 | + if ( $this->isQuotedIdentifier( $name ) ) { |
1526 | 1526 | return $name; |
1527 | 1527 | } |
1528 | 1528 | |
— | — | @@ -1550,14 +1550,14 @@ |
1551 | 1551 | # A database name has been specified in input. Quote the table name |
1552 | 1552 | # because we don't want any prefixes added. |
1553 | 1553 | if ( isset( $database ) ) { |
1554 | | - $table = ( $table[0] == '`' ? $table : "`{$table}`" ); |
| 1554 | + $table = ( $this->isQuotedIdentifier( $table ) ? $table : $this->addIdentifierQuotes( $table ) ); |
1555 | 1555 | } |
1556 | 1556 | |
1557 | 1557 | # Note that we use the long format because php will complain in in_array if |
1558 | 1558 | # the input is not an array, and will complain in is_array if it is not set. |
1559 | 1559 | if ( !isset( $database ) # Don't use shared database if pre selected. |
1560 | 1560 | && isset( $wgSharedDB ) # We have a shared database |
1561 | | - && $table[0] != '`' # Paranoia check to prevent shared tables listing '`table`' |
| 1561 | + && !$this->isQuotedIdentifier( $table ) # Paranoia check to prevent shared tables listing '`table`' |
1562 | 1562 | && isset( $wgSharedTables ) |
1563 | 1563 | && is_array( $wgSharedTables ) |
1564 | 1564 | && in_array( $table, $wgSharedTables ) ) { # A shared table is selected |
— | — | @@ -1567,9 +1567,9 @@ |
1568 | 1568 | |
1569 | 1569 | # Quote the $database and $table and apply the prefix if not quoted. |
1570 | 1570 | if ( isset( $database ) ) { |
1571 | | - $database = ( $database[0] == '`' ? $database : "`{$database}`" ); |
| 1571 | + $database = ( $this->isQuotedIdentifier( $database ) ? $database : $this->addIdentifierQuotes( $database ) ); |
1572 | 1572 | } |
1573 | | - $table = ( $table[0] == '`' ? $table : "`{$prefix}{$table}`" ); |
| 1573 | + $table = ( $this->isQuotedIdentifier( $table ) ? $table : $this->addIdentifierQuotes( "{$prefix}{$table}" ) ); |
1574 | 1574 | |
1575 | 1575 | # Merge our database and table into our final table name. |
1576 | 1576 | $tableName = ( isset( $database ) ? "{$database}.{$table}" : "{$table}" ); |
— | — | @@ -1747,6 +1747,15 @@ |
1748 | 1748 | } |
1749 | 1749 | |
1750 | 1750 | /** |
| 1751 | + * Returns if the given identifier looks quoted or not according to |
| 1752 | + * the database convention for quoting identifiers . |
| 1753 | + * @return boolean |
| 1754 | + */ |
| 1755 | + public function isQuotedIdentifier( $name ) { |
| 1756 | + return $name[0] == '"' && substr( $name, -1, 1 ) == '"'; |
| 1757 | + } |
| 1758 | + |
| 1759 | + /** |
1751 | 1760 | * Backwards compatibility, identifier quoting originated in DatabasePostgres |
1752 | 1761 | * which used quote_ident which does not follow our naming conventions |
1753 | 1762 | * was renamed to addIdentifierQuotes. |
Index: trunk/phase3/includes/db/DatabaseMssql.php |
— | — | @@ -452,14 +452,14 @@ |
453 | 453 | $sql .= ','; |
454 | 454 | } |
455 | 455 | if ( is_string( $value ) ) { |
456 | | - $sql .= $this->addIdentifierQuotes( $value ); |
| 456 | + $sql .= $this->addQuotes( $value ); |
457 | 457 | } elseif ( is_null( $value ) ) { |
458 | 458 | $sql .= 'null'; |
459 | 459 | } elseif ( is_array( $value ) || is_object( $value ) ) { |
460 | 460 | if ( is_object( $value ) && strtolower( get_class( $value ) ) == 'blob' ) { |
461 | | - $sql .= $this->addIdentifierQuotes( $value->fetch() ); |
| 461 | + $sql .= $this->addQuotes( $value ); |
462 | 462 | } else { |
463 | | - $sql .= $this->addIdentifierQuotes( serialize( $value ) ); |
| 463 | + $sql .= $this->addQuotes( serialize( $value ) ); |
464 | 464 | } |
465 | 465 | } else { |
466 | 466 | $sql .= $value; |
— | — | @@ -989,6 +989,15 @@ |
990 | 990 | } |
991 | 991 | } |
992 | 992 | |
| 993 | + public function addIdentifierQuotes( $s ) { |
| 994 | + // http://msdn.microsoft.com/en-us/library/aa223962.aspx |
| 995 | + return '[' . $s . ']'; |
| 996 | + } |
| 997 | + |
| 998 | + public function isQuotedIdentifier( $name ) { |
| 999 | + return $name[0] == '[' && substr( $name, -1, 1 ) == ']'; |
| 1000 | + } |
| 1001 | + |
993 | 1002 | function selectDB( $db ) { |
994 | 1003 | return ( $this->query( "SET DATABASE $db" ) !== false ); |
995 | 1004 | } |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -257,7 +257,7 @@ |
258 | 258 | function tableName( $name ) { |
259 | 259 | // table names starting with sqlite_ are reserved |
260 | 260 | if ( strpos( $name, 'sqlite_' ) === 0 ) return $name; |
261 | | - return str_replace( '`', '', parent::tableName( $name ) ); |
| 261 | + return str_replace( '"', '', parent::tableName( $name ) ); |
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |