Index: trunk/phase3/CREDITS |
— | — | @@ -108,7 +108,6 @@ |
109 | 109 | * Lejonel |
110 | 110 | * liangent |
111 | 111 | * Louperivois |
112 | | -* Luca Fulchir |
113 | 112 | * Lucas Garczewski |
114 | 113 | * Luigi Corsaro |
115 | 114 | * Manuel Menal |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -7,7 +7,7 @@ |
8 | 8 | */ |
9 | 9 | |
10 | 10 | class PostgresField implements Field { |
11 | | - private $name, $tablename, $type, $nullable, $max_length, $deferred, $deferrable, $conname, $sharedmConn = null; |
| 11 | + private $name, $tablename, $type, $nullable, $max_length, $deferred, $deferrable, $conname; |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param $db DatabaseBase |
— | — | @@ -152,7 +152,7 @@ |
153 | 153 | throw new DBConnectionError( $this, "Postgres functions missing, have you compiled PHP with the --with-pgsql option?\n (Note: if you recently installed PHP, you may need to restart your webserver and database)\n" ); |
154 | 154 | } |
155 | 155 | |
156 | | - global $wgDBport, $wgSharedDB; |
| 156 | + global $wgDBport; |
157 | 157 | |
158 | 158 | if ( !strlen( $user ) ) { # e.g. the class is being loaded |
159 | 159 | return; |
— | — | @@ -189,30 +189,6 @@ |
190 | 190 | throw new DBConnectionError( $this, $phpError ); |
191 | 191 | } |
192 | 192 | |
193 | | - if( $wgSharedDB ) { |
194 | | - $connectVars = array( |
195 | | - 'dbname' => $wgSharedDB, |
196 | | - 'user' => $user, |
197 | | - 'password' => $password ); |
198 | | - if ($server!=false && $server!="") { |
199 | | - $connectVars['host'] = $server; |
200 | | - } |
201 | | - if ($port!=false && $port!="") { |
202 | | - $connectVars['port'] = $port; |
203 | | - } |
204 | | - $connectString = $this->makeConnectionString( $connectVars, PGSQL_CONNECT_FORCE_NEW ); |
205 | | - |
206 | | - $this->installErrorHandler(); |
207 | | - $this->sharedmConn = pg_connect( $connectString ); |
208 | | - $phpError = $this->restoreErrorHandler(); |
209 | | - if ( $this->sharedmConn == false ) { |
210 | | - wfDebug( "SharedDB connection error\n" ); |
211 | | - wfDebug( "Server: $server, Database: $wgSharedDB, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" ); |
212 | | - wfDebug( $this->lastError()."\n" ); |
213 | | - $this->close(); |
214 | | - throw new DBConnectionError( $this, $phpError ); |
215 | | - } |
216 | | - } |
217 | 193 | $this->mOpened = true; |
218 | 194 | |
219 | 195 | global $wgCommandLineMode; |
— | — | @@ -258,56 +234,19 @@ |
259 | 235 | * Returns success, true if already closed |
260 | 236 | */ |
261 | 237 | function close() { |
262 | | - $mainConn = true; |
263 | | - $sharedConn = true; |
264 | | - if ( $this->mConn ) { |
265 | | - $mainConn = pg_close ( $this->mConn ); |
| 238 | + $this->mOpened = false; |
| 239 | + if ( $this->mConn ) { |
| 240 | + return pg_close( $this->mConn ); |
| 241 | + } else { |
| 242 | + return true; |
266 | 243 | } |
267 | | - if ( isset( $this->sharedmConn ) && $this->sharedmConn ) { |
268 | | - $sharedConn = pg_close ( $this->sharedmConn ); |
269 | | - } |
270 | | - $this->mOpened = !($mainConn && $sharedConn); |
271 | | - return !$this->mOpened; |
272 | 244 | } |
273 | 245 | |
274 | 246 | function doQuery( $sql ) { |
275 | | - global $wgSharedDB; |
276 | 247 | if ( function_exists( 'mb_convert_encoding' ) ) { |
277 | 248 | $sql = mb_convert_encoding( $sql, 'UTF-8' ); |
278 | 249 | } |
279 | | - # we can find the shared tables after FROM or UPDATE statements. |
280 | | - $FROMpos = strpos( $sql, 'FROM' ); |
281 | | - if ( $FROMpos === false ) { |
282 | | - $FROMpos = strpos( $sql, 'UPDATE' ); |
283 | | - if ( $FROMpos === false ) { |
284 | | - # does this query even exists? |
285 | | - $this->mLastResult = pg_query( $this->mConn, $sql ); |
286 | | - $this->mAffectedRows = null; // use pg_affected_rows(mLastResult) |
287 | | - return $this->mLastResult; |
288 | | - } |
289 | | - } |
290 | | - # check if we should connect to the shared database |
291 | | - # skip FROM/UPDATE statement |
292 | | - $FROMquery = substr( $sql, $FROMpos + ($sql[$FROMpos] == 'F' ? 4 : 6) ); |
293 | | - $trimmed = trim( $FROMquery ); |
294 | | - $FROMquery = $trimmed; |
295 | | - # skip eventual comment and spaces |
296 | | - if ( substr( $FROMquery, 0, 2 ) == '/*' ) { |
297 | | - $FROMquery = substr( $FROMquery, strpos( $FROMquery, '*/') + 2 ); |
298 | | - $trimmed = trim( $FROMquery ); |
299 | | - $FROMquery = $trimmed; |
300 | | - } |
301 | | - # select only dbname |
302 | | - $FROMquery = substr( $FROMquery, 0, strpos($FROMquery, ' ') ); |
303 | | - $FROMvalue = explode( '.', $FROMquery ); |
304 | | - # db is always quoted, compare it to wgSharedDB |
305 | | - if ( $FROMvalue[0] == "\"$wgSharedDB\"" ) { |
306 | | - # shared db requested. switch connection |
307 | | - $this->mLastResult = pg_query( $this->sharedmConn, $sql ); |
308 | | - } else { |
309 | | - # main db: basic query |
310 | | - $this->mLastResult = pg_query( $this->mConn, $sql ); |
311 | | - } |
| 250 | + $this->mLastResult = pg_query( $this->mConn, $sql ); |
312 | 251 | $this->mAffectedRows = null; // use pg_affected_rows(mLastResult) |
313 | 252 | return $this->mLastResult; |
314 | 253 | } |
— | — | @@ -671,81 +610,15 @@ |
672 | 611 | } |
673 | 612 | |
674 | 613 | function tableName( $name, $quoted = true ) { |
675 | | - global $wgSharedDB, $wgSharedPrefix, $wgSharedTables, $wgDBmwschema; |
676 | 614 | # Replace reserved words with better ones |
677 | 615 | switch( $name ) { |
678 | 616 | case 'user': |
679 | | - $name = 'mwuser'; |
680 | | - break; |
681 | | - case '"user"': |
682 | | - $name = '"mwuser"'; |
683 | | - break; |
684 | | - case 'text': |
685 | | - $name = 'pagecontent'; |
686 | | - break; |
687 | | - case 'text': |
688 | | - $name = 'pagecontent'; |
689 | | - break; |
| 617 | + return 'mwuser'; |
| 618 | + case 'text': |
| 619 | + return 'pagecontent'; |
| 620 | + default: |
| 621 | + return parent::tableName( $name, $quoted ); |
690 | 622 | } |
691 | | - # Skip the entire process when we have a string quoted on both ends. |
692 | | - # Note that we check the end so that we will still quote any use of |
693 | | - # use of `database`.table. But won't break things if someone wants |
694 | | - # to query a database table with a dot in the name. |
695 | | - if ( $name[0] == '"' && substr( $name, -1, 1 ) == '"' ) { |
696 | | - return $name; |
697 | | - } |
698 | | - |
699 | | - # Lets test for any bits of text that should never show up in a table |
700 | | - # name. Basically anything like JOIN or ON which are actually part of |
701 | | - # SQL queries, but may end up inside of the table value to combine |
702 | | - # sql. Such as how the API is doing. |
703 | | - # Note that we use a whitespace test rather than a \b test to avoid |
704 | | - # any remote case where a word like on may be inside of a table name |
705 | | - # surrounded by symbols which may be considered word breaks. |
706 | | - if( preg_match( '/(^|\s)(DISTINCT|JOIN|ON|AS)(\s|$)/i', $name ) !== 0 ) { |
707 | | - return $name; |
708 | | - } |
709 | | - |
710 | | - # Split database and table into proper variables. |
711 | | - # We reverse the explode so that database.table and table both output |
712 | | - # the correct table. |
713 | | - $dbDetails = array_reverse( explode( '.', $name, 2 ) ); |
714 | | - if ( isset( $dbDetails[1] ) ) { |
715 | | - @list( $table, $database ) = $dbDetails; |
716 | | - } else { |
717 | | - @list( $table ) = $dbDetails; |
718 | | - } |
719 | | - $prefix = $this->mTablePrefix; # Default prefix |
720 | | - |
721 | | - # A database name has been specified in input. Quote the table name |
722 | | - # because we don't want any prefixes added. |
723 | | - if( isset($database) ) { |
724 | | - $table = ( $table[0] == '"' ? $table : "\"{$table}\"" ); |
725 | | - } |
726 | | - |
727 | | - # Note that we use the long format because php will complain in in_array if |
728 | | - # the input is not an array, and will complain in is_array if it is not set. |
729 | | - if( !isset( $database ) # Don't use shared database if pre selected. |
730 | | - && isset( $wgSharedDB ) # We have a shared database |
731 | | - && $table[0] != '"' # Paranoia check to prevent shared tables listing '`table`' |
732 | | - && isset( $wgSharedTables ) |
733 | | - && is_array( $wgSharedTables ) |
734 | | - && in_array( $table, $wgSharedTables ) ) { # A shared table is selected |
735 | | - $database = $wgSharedDB; |
736 | | - $prefix = isset( $wgSharedPrefix ) ? $wgSharedPrefix : $prefix; |
737 | | - } |
738 | | - |
739 | | - # Quote the $database and $table and apply the prefix if not quoted. |
740 | | - if( isset($database) ) { |
741 | | - $database = ( $database[0] == '"' ? $database : "\"{$database}\"" ); |
742 | | - } |
743 | | - $table = ( $table[0] == '"' ? $table : "\"{$prefix}{$table}\"" ); |
744 | | - |
745 | | - # Merge our database and table into our final table name. |
746 | | - $tableName = ( isset($database) ? "{$database}.\"{$wgDBmwschema}\".{$table}" : "{$table}" ); |
747 | | - |
748 | | - # We're finished, return. |
749 | | - return $tableName; |
750 | 623 | } |
751 | 624 | |
752 | 625 | /** |