r106025 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106024‎ | r106025 | r106026 >
Date:15:06, 13 December 2011
Author:mah
Status:reverted (Comments)
Tags:notmysql 
Comment:
Bug 16794 - $wgSharedDB PostgreSQL support

Updated fix from Luca Fulchir
Modified paths:
  • /trunk/phase3/CREDITS (modified) (history)
  • /trunk/phase3/includes/db/DatabasePostgres.php (modified) (history)

Diff [purge]

Index: trunk/phase3/CREDITS
@@ -120,6 +120,7 @@
121121 * Lejonel
122122 * liangent
123123 * Louperivois
 124+* Luca Fulchir
124125 * Lucas Garczewski
125126 * Luigi Corsaro
126127 * Lupo
Index: trunk/phase3/includes/db/DatabasePostgres.php
@@ -624,15 +624,69 @@
625625 }
626626
627627 function tableName( $name, $format = 'quoted' ) {
628 - # Replace reserved words with better ones
629 - switch( $name ) {
 628+ global $wgSharedDB, $wgSharedTables, $wgDBmwSchema;
 629+ # Skip quoted tablenames.
 630+ if ( $this->isQuotedIdentifier( $name ) ) {
 631+ return $name;
 632+ }
 633+ # Lets test for any bits of text that should never show up in a table
 634+ # name. Basically anything like JOIN or ON which are actually part of
 635+ # SQL queries, but may end up inside of the table value to combine
 636+ # sql. Such as how the API is doing.
 637+ # Note that we use a whitespace test rather than a \b test to avoid
 638+ # any remote case where a word like on may be inside of a table name
 639+ # surrounded by symbols which may be considered word breaks.
 640+ if ( preg_match( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i', $name ) !== 0 ) {
 641+ return $name;
 642+ }
 643+ # Split database and table into proper variables.
 644+ # We reverse the explode so that schema.table and table both output
 645+ # the correct table.
 646+ $dbDetails = array_reverse( explode( '.', $name, 2 ) );
 647+ if ( isset( $dbDetails[1] ) ) {
 648+ list( $table, $schema ) = $dbDetails;
 649+ } else {
 650+ list( $table ) = $dbDetails;
 651+ }
 652+ if ( $format != 'quoted' ) {
 653+ switch( $name ) {
 654+ case 'user':
 655+ return 'mwuser';
 656+ case 'text':
 657+ return 'pagecontent';
 658+ default:
 659+ return $table;
 660+ }
 661+ }
 662+ if ( !isset( $schema )) {
 663+ $schema = "\"{$wgDBmwSchema}\".";
 664+ } else {
 665+ # keep old schema, but quote it.
 666+ $schema = "\"{$schema}\".";
 667+ }
 668+ # during installation wgDBmwSchema is not set, so we would end up quering
 669+ # ""."table" => error. Erase the first part if wgDBmwSchema is empty
 670+ if ( $schema == "\"\"." ) {
 671+ $schema = "";
 672+ }
 673+ if ( isset( $wgSharedDB ) # We have a shared database (=> schema)
 674+ && isset( $wgSharedTables )
 675+ && is_array( $wgSharedTables )
 676+ && in_array( $table, $wgSharedTables ) ) { # A shared table is selected
 677+ $schema = "\"{$wgSharedDB}\".";
 678+ }
 679+ switch ( $table ) {
630680 case 'user':
631 - return 'mwuser';
 681+ $table = "{$schema}\"mwuser\"";
 682+ break;
632683 case 'text':
633 - return 'pagecontent';
 684+ $table = "{$schema}\"pagecontent\"";
 685+ break;
634686 default:
635 - return parent::tableName( $name, $format );
 687+ $table = "{$schema}\"$table\"";
 688+ break;
636689 }
 690+ return $table;
637691 }
638692
639693 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r106370Use the canonical name of the settingplatonides21:12, 15 December 2011
r106373Simplify a bit the code of r106025platonides21:21, 15 December 2011
r106419Foooollowup r106373 - update commentnikerabbit08:56, 16 December 2011
r108060re r106025 — apply follow up from Luca Fulchirmah18:01, 4 January 2012
r108337No need of $wgDBmwschema after r108060platonides23:29, 7 January 2012
r110690Reverted r106025 and friends (r106370, r106373, r108060, r108337, r106419). T...aaron23:37, 3 February 2012
r113487Handle PostgreSQL transaction errors and improve schema detection...saper17:24, 9 March 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89393Apply a patch adapted from the one on Bug #16794...mah04:10, 3 June 2011

Comments

#Comment by Platonides (talk | contribs)   21:15, 15 December 2011

"during installation wgDBmwschema is not set"... This looks like it would be using an unitialized variable, which we shouldn't do.

#Comment by Platonides (talk | contribs)   21:22, 15 December 2011

Are you sure doing $schema = "\"{$schema}\"."; is the right way of quoting in Postgres?

#Comment by OverlordQ (talk | contribs)   21:20, 19 December 2011

In Postgres temporary tables are put in to their own special schema, explicitly prefixing all table names with mediawiki's default schema breaks any usage of temporary tables.

Either this needs reverted, or have to do some ugly hacks to the testing framework.

#Comment by Aaron Schulz (talk | contribs)   18:14, 24 January 2012

Can you just revert this if it seems needed?

#Comment by Reedy (talk | contribs)   16:27, 3 February 2012

I'm thinking that this seems the easiest way forward, for now/1.19 at least

Status & tagging log