Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -317,7 +317,7 @@ |
318 | 318 | return false; |
319 | 319 | } |
320 | 320 | } |
321 | | - |
| 321 | + |
322 | 322 | wfRestoreWarnings(); |
323 | 323 | |
324 | 324 | if ( $explain_count > 0 ) { |
— | — | @@ -768,7 +768,7 @@ |
769 | 769 | $temporary = $temporary ? 'TRUE' : 'FALSE'; |
770 | 770 | $oldName = trim(strtoupper($oldName), '"'); |
771 | 771 | $oldParts = explode('_', $oldName); |
772 | | - |
| 772 | + |
773 | 773 | $newName = trim(strtoupper($newName), '"'); |
774 | 774 | $newParts = explode('_', $newName); |
775 | 775 | |
— | — | @@ -783,9 +783,9 @@ |
784 | 784 | unset($oldParts[$i]); |
785 | 785 | unset($newParts[$i]); |
786 | 786 | } |
787 | | - |
| 787 | + |
788 | 788 | $tabName = substr($oldName, strlen($oldPrefix)); |
789 | | - |
| 789 | + |
790 | 790 | return $this->query( 'BEGIN DUPLICATE_TABLE(\'' . $tabName . '\', \'' . $oldPrefix . '\', \''.$newPrefix.'\', ' . $temporary . '); END;', $fname ); |
791 | 791 | } |
792 | 792 | |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | global $wgDBmwschema; |
15 | 15 | |
16 | 16 | $q = <<<SQL |
17 | | -SELECT |
| 17 | +SELECT |
18 | 18 | attnotnull, attlen, COALESCE(conname, '') AS conname, |
19 | 19 | COALESCE(condeferred, 'f') AS deferred, |
20 | 20 | COALESCE(condeferrable, 'f') AS deferrable, |
— | — | @@ -321,17 +321,17 @@ |
322 | 322 | |
323 | 323 | if ($this->numeric_version < 8.3) { |
324 | 324 | // Tsearch2 checks |
325 | | - print "<li>Checking that tsearch2 is installed in the database \"" . |
| 325 | + print "<li>Checking that tsearch2 is installed in the database \"" . |
326 | 326 | htmlspecialchars( $wgDBname ) . "\"..."; |
327 | 327 | if (! $this->tableExists("pg_ts_cfg", $wgDBts2schema)) { |
328 | | - print "<b>FAILED</b>. tsearch2 must be installed in the database \"" . |
| 328 | + print "<b>FAILED</b>. tsearch2 must be installed in the database \"" . |
329 | 329 | htmlspecialchars( $wgDBname ) . "\"."; |
330 | 330 | print "Please see <a href='http://www.devx.com/opensource/Article/21674/0/page/2'>this article</a>"; |
331 | 331 | print " for instructions or ask on #postgresql on irc.freenode.net</li>\n"; |
332 | 332 | dieout("</ul>"); |
333 | 333 | } |
334 | 334 | print "OK</li>\n"; |
335 | | - print "<li>Ensuring that user \"" . htmlspecialchars( $wgDBuser ) . |
| 335 | + print "<li>Ensuring that user \"" . htmlspecialchars( $wgDBuser ) . |
336 | 336 | "\" has select rights on the tsearch2 tables..."; |
337 | 337 | foreach (array('cfg','cfgmap','dict','parser') as $table) { |
338 | 338 | $SQL = "GRANT SELECT ON pg_ts_$table TO $safeuser"; |
— | — | @@ -410,8 +410,8 @@ |
411 | 411 | $SQL = "SELECT count(*) FROM $safetsschema.pg_ts_$tname"; |
412 | 412 | $res = $this->doQuery($SQL); |
413 | 413 | if (!$res) { |
414 | | - print "<b>FAILED</b> to access " . htmlspecialchars( "pg_ts_$tname" ) . |
415 | | - ". Make sure that the user \"". htmlspecialchars( $wgDBuser ) . |
| 414 | + print "<b>FAILED</b> to access " . htmlspecialchars( "pg_ts_$tname" ) . |
| 415 | + ". Make sure that the user \"". htmlspecialchars( $wgDBuser ) . |
416 | 416 | "\" has SELECT access to all four tsearch2 tables</li>\n"; |
417 | 417 | dieout("</ul>"); |
418 | 418 | } |
— | — | @@ -439,7 +439,7 @@ |
440 | 440 | $tsname = pg_fetch_result($res, 0, 0); |
441 | 441 | if ($tsname != 'default') { |
442 | 442 | print "<b>not set to default (" . htmlspecialchars( $tsname ) . ")</b>"; |
443 | | - print "<li>Attempting to change tsearch2 default locale to \"" . |
| 443 | + print "<li>Attempting to change tsearch2 default locale to \"" . |
444 | 444 | htmlspecialchars( $ctype ) . "\"..."; |
445 | 445 | $resetlocale = 1; |
446 | 446 | } |
— | — | @@ -449,7 +449,7 @@ |
450 | 450 | $res = $this->doQuery($SQL); |
451 | 451 | if (!$res) { |
452 | 452 | print "<b>FAILED</b>. "; |
453 | | - print "Please make sure that the locale in pg_ts_cfg for \"default\" is set to \"" . |
| 453 | + print "Please make sure that the locale in pg_ts_cfg for \"default\" is set to \"" . |
454 | 454 | htmlspecialchars( $ctype ) . "\"</li>\n"; |
455 | 455 | dieout("</ul>"); |
456 | 456 | } |
— | — | @@ -478,21 +478,21 @@ |
479 | 479 | $result = $this->doQuery("CREATE SCHEMA $safeschema"); |
480 | 480 | error_reporting( E_ALL ); |
481 | 481 | if (!$result) { |
482 | | - print "<b>FAILED</b>. The user \"" . htmlspecialchars( $wgDBuser ) . |
| 482 | + print "<b>FAILED</b>. The user \"" . htmlspecialchars( $wgDBuser ) . |
483 | 483 | "\" must be able to access the schema. ". |
484 | 484 | "You can try making them the owner of the database, or try creating the schema with a ". |
485 | | - "different user, and then grant access to the \"" . |
| 485 | + "different user, and then grant access to the \"" . |
486 | 486 | htmlspecialchars( $wgDBuser ) . "\" user.</li>\n"; |
487 | 487 | dieout("</ul>"); |
488 | 488 | } |
489 | 489 | print "OK</li>\n"; |
490 | 490 | } |
491 | 491 | else if ($result != $wgDBuser) { |
492 | | - print "<li>Schema \"" . htmlspecialchars( $wgDBmwschema ) . "\" exists but is not owned by \"" . |
| 492 | + print "<li>Schema \"" . htmlspecialchars( $wgDBmwschema ) . "\" exists but is not owned by \"" . |
493 | 493 | htmlspecialchars( $wgDBuser ) . "\". Not ideal.</li>\n"; |
494 | 494 | } |
495 | 495 | else { |
496 | | - print "<li>Schema \"" . htmlspecialchars( $wgDBmwschema ) . "\" exists and is owned by \"" . |
| 496 | + print "<li>Schema \"" . htmlspecialchars( $wgDBmwschema ) . "\" exists and is owned by \"" . |
497 | 497 | htmlspecialchars( $wgDBuser ) . "\". Excellent.</li>\n"; |
498 | 498 | } |
499 | 499 | |
— | — | @@ -572,13 +572,13 @@ |
573 | 573 | $result = $this->doQuery("CREATE LANGUAGE plpgsql"); |
574 | 574 | error_reporting($olde); |
575 | 575 | if (!$result) { |
576 | | - print "<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>" . |
| 576 | + print "<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>" . |
577 | 577 | htmlspecialchars( $wgDBname ) . "</tt></li>"; |
578 | 578 | dieout("</ul>"); |
579 | 579 | } |
580 | 580 | } |
581 | 581 | else { |
582 | | - print "<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>" . |
| 582 | + print "<b>FAILED</b>. You need to install the language PL/pgSQL in the database <tt>" . |
583 | 583 | htmlspecialchars( $wgDBname ) . "</tt></li>"; |
584 | 584 | dieout("</ul>"); |
585 | 585 | } |
— | — | @@ -751,7 +751,7 @@ |
752 | 752 | |
753 | 753 | function indexUnique ($table, $index, $fname = 'DatabasePostgres::indexUnique' ) { |
754 | 754 | $sql = "SELECT indexname FROM pg_indexes WHERE tablename='{$table}'". |
755 | | - " AND indexdef LIKE 'CREATE UNIQUE%(" . |
| 755 | + " AND indexdef LIKE 'CREATE UNIQUE%(" . |
756 | 756 | $this->strencode( $this->indexName( $index ) ) . |
757 | 757 | ")'"; |
758 | 758 | $res = $this->query( $sql, $fname ); |
— | — | @@ -971,7 +971,7 @@ |
972 | 972 | |
973 | 973 | return $res; |
974 | 974 | } |
975 | | - |
| 975 | + |
976 | 976 | function tableName( $name ) { |
977 | 977 | # Replace reserved words with better ones |
978 | 978 | switch( $name ) { |
— | — | @@ -1261,7 +1261,7 @@ |
1262 | 1262 | function fieldInfo( $table, $field ) { |
1263 | 1263 | return PostgresField::fromText($this, $table, $field); |
1264 | 1264 | } |
1265 | | - |
| 1265 | + |
1266 | 1266 | /** |
1267 | 1267 | * pg_field_type() wrapper |
1268 | 1268 | */ |
— | — | @@ -1292,7 +1292,7 @@ |
1293 | 1293 | $res = $this->doQuery($SQL); |
1294 | 1294 | error_reporting( $olde ); |
1295 | 1295 | if (!$res) { |
1296 | | - print "<b>FAILED</b>. Make sure that the user \"" . htmlspecialchars( $wgDBuser ) . |
| 1296 | + print "<b>FAILED</b>. Make sure that the user \"" . htmlspecialchars( $wgDBuser ) . |
1297 | 1297 | "\" can write to the schema \"" . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n"; |
1298 | 1298 | dieout(""); # Will close the main list <ul> and finish the page. |
1299 | 1299 | } |
Index: trunk/phase3/includes/db/DatabaseMssql.php |
— | — | @@ -80,11 +80,11 @@ |
81 | 81 | $this->mDBname = $dbName; |
82 | 82 | |
83 | 83 | $connectionInfo = array(); |
84 | | - |
| 84 | + |
85 | 85 | if( $dbName ) { |
86 | 86 | $connectionInfo['Database'] = $dbName; |
87 | 87 | } |
88 | | - |
| 88 | + |
89 | 89 | // Start NT Auth Hack |
90 | 90 | // Quick and dirty work around to provide NT Auth designation support. |
91 | 91 | // Current solution requires installer to know to input 'ntauth' for both username and password |
— | — | @@ -92,7 +92,7 @@ |
93 | 93 | // TO-DO: Make this better and add NT Auth choice to MW installer when SQL Server option is chosen. |
94 | 94 | $ntAuthUserTest = strtolower( $user ); |
95 | 95 | $ntAuthPassTest = strtolower( $password ); |
96 | | - |
| 96 | + |
97 | 97 | // Decide which auth scenerio to use |
98 | 98 | if( ( $ntAuthPassTest == 'ntauth' && $ntAuthUserTest == 'ntauth' ) ){ |
99 | 99 | // Don't add credentials to $connectionInfo |
— | — | @@ -103,7 +103,7 @@ |
104 | 104 | // End NT Auth Hack |
105 | 105 | |
106 | 106 | $this->mConn = @sqlsrv_connect( $server, $connectionInfo ); |
107 | | - |
| 107 | + |
108 | 108 | if ( $this->mConn === false ) { |
109 | 109 | wfDebug( "DB connection error\n" ); |
110 | 110 | wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" ); |
— | — | @@ -131,7 +131,7 @@ |
132 | 132 | function doQuery( $sql ) { |
133 | 133 | wfDebug( "SQL: [$sql]\n" ); |
134 | 134 | $this->offset = 0; |
135 | | - |
| 135 | + |
136 | 136 | // several extensions seem to think that all databases support limits via LIMIT N after the WHERE clause |
137 | 137 | // well, MSSQL uses SELECT TOP N, so to catch any of those extensions we'll do a quick check for a LIMIT |
138 | 138 | // clause and pass $sql through $this->LimitToTopN() which parses the limit clause and passes the result to |
— | — | @@ -140,13 +140,13 @@ |
141 | 141 | // massage LIMIT -> TopN |
142 | 142 | $sql = $this->LimitToTopN( $sql ) ; |
143 | 143 | } |
144 | | - |
145 | | - // MSSQL doesn't have EXTRACT(epoch FROM XXX) |
| 144 | + |
| 145 | + // MSSQL doesn't have EXTRACT(epoch FROM XXX) |
146 | 146 | if ( preg_match('#\bEXTRACT\s*?\(\s*?EPOCH\s+FROM\b#i', $sql, $matches ) ) { |
147 | 147 | // This is same as UNIX_TIMESTAMP, we need to calc # of seconds from 1970 |
148 | 148 | $sql = str_replace( $matches[0], "DATEDIFF(s,CONVERT(datetime,'1/1/1970'),", $sql ); |
149 | 149 | } |
150 | | - |
| 150 | + |
151 | 151 | // perform query |
152 | 152 | $stmt = sqlsrv_query( $this->mConn, $sql ); |
153 | 153 | if ( $stmt == false ) { |
— | — | @@ -157,16 +157,16 @@ |
158 | 158 | foreach ( sqlsrv_errors() as $error ) { |
159 | 159 | $message .= $message . "ERROR[" . $error['code'] . "] " . $error['message'] . "\n"; |
160 | 160 | } |
161 | | - |
| 161 | + |
162 | 162 | throw new DBUnexpectedError( $this, $message ); |
163 | 163 | } |
164 | 164 | // remember number of rows affected |
165 | 165 | $this->mAffectedRows = sqlsrv_rows_affected( $stmt ); |
166 | | - |
167 | | - // if it is a SELECT statement, or an insert with a request to output something we want to return a row. |
168 | | - if ( ( preg_match( '#\bSELECT\s#i', $sql ) ) || |
| 166 | + |
| 167 | + // if it is a SELECT statement, or an insert with a request to output something we want to return a row. |
| 168 | + if ( ( preg_match( '#\bSELECT\s#i', $sql ) ) || |
169 | 169 | ( preg_match( '#\bINSERT\s#i', $sql ) && preg_match( '#\bOUTPUT\s+INSERTED\b#i', $sql ) ) ) { |
170 | | - // this is essentially a rowset, but Mediawiki calls these 'result' |
| 170 | + // this is essentially a rowset, but Mediawiki calls these 'result' |
171 | 171 | // the rowset owns freeing the statement |
172 | 172 | $res = new MssqlResult( $stmt ); |
173 | 173 | } else { |
— | — | @@ -190,7 +190,7 @@ |
191 | 191 | $row = $res->fetch( 'OBJECT' ); |
192 | 192 | return $row; |
193 | 193 | } |
194 | | - |
| 194 | + |
195 | 195 | function getErrors() { |
196 | 196 | $strRet = ''; |
197 | 197 | $retErrors = sqlsrv_errors( SQLSRV_ERR_ALL ); |
— | — | @@ -220,14 +220,14 @@ |
221 | 221 | } |
222 | 222 | return ( $res ) ? $res->numrows() : 0; |
223 | 223 | } |
224 | | - |
| 224 | + |
225 | 225 | function numFields( $res ) { |
226 | 226 | if ( $res instanceof ResultWrapper ) { |
227 | 227 | $res = $res->result; |
228 | 228 | } |
229 | 229 | return ( $res ) ? $res->numfields() : 0; |
230 | 230 | } |
231 | | - |
| 231 | + |
232 | 232 | function fieldName( $res, $n ) { |
233 | 233 | if ( $res instanceof ResultWrapper ) { |
234 | 234 | $res = $res->result; |
— | — | @@ -257,7 +257,7 @@ |
258 | 258 | return "No database connection"; |
259 | 259 | } |
260 | 260 | } |
261 | | - |
| 261 | + |
262 | 262 | function lastErrno() { |
263 | 263 | $err = sqlsrv_errors( SQLSRV_ERR_ALL ); |
264 | 264 | if ( $err[0] ) return $err[0]['code']; |
— | — | @@ -267,7 +267,7 @@ |
268 | 268 | function affectedRows() { |
269 | 269 | return $this->mAffectedRows; |
270 | 270 | } |
271 | | - |
| 271 | + |
272 | 272 | /** |
273 | 273 | * SELECT wrapper |
274 | 274 | * |
— | — | @@ -292,7 +292,7 @@ |
293 | 293 | } |
294 | 294 | return $this->query( $sql, $fname ); |
295 | 295 | } |
296 | | - |
| 296 | + |
297 | 297 | /** |
298 | 298 | * SELECT wrapper |
299 | 299 | * |
— | — | @@ -312,7 +312,7 @@ |
313 | 313 | } |
314 | 314 | return parent::selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds ); |
315 | 315 | } |
316 | | - |
| 316 | + |
317 | 317 | /** |
318 | 318 | * Estimate rows in dataset |
319 | 319 | * Returns estimated count, based on SHOWPLAN_ALL output |
— | — | @@ -323,7 +323,7 @@ |
324 | 324 | function estimateRowCount( $table, $vars = '*', $conds = '', $fname = 'DatabaseMssql::estimateRowCount', $options = array() ) { |
325 | 325 | $options['EXPLAIN'] = true;// http://msdn2.microsoft.com/en-us/library/aa259203.aspx |
326 | 326 | $res = $this->select( $table, $vars, $conds, $fname, $options ); |
327 | | - |
| 327 | + |
328 | 328 | $rows = -1; |
329 | 329 | if ( $res ) { |
330 | 330 | $row = $this->fetchRow( $res ); |
— | — | @@ -381,20 +381,20 @@ |
382 | 382 | if ( !count( $arrToInsert ) ) { |
383 | 383 | return true; |
384 | 384 | } |
385 | | - |
| 385 | + |
386 | 386 | if ( !is_array( $options ) ) { |
387 | 387 | $options = array( $options ); |
388 | 388 | } |
389 | 389 | |
390 | 390 | $table = $this->tableName( $table ); |
391 | | - |
| 391 | + |
392 | 392 | if ( !( isset( $arrToInsert[0] ) && is_array( $arrToInsert[0] ) ) ) {// Not multi row |
393 | 393 | $arrToInsert = array( 0 => $arrToInsert );// make everything multi row compatible |
394 | 394 | } |
395 | | - |
| 395 | + |
396 | 396 | $allOk = true; |
397 | | - |
398 | | - |
| 397 | + |
| 398 | + |
399 | 399 | // We know the table we're inserting into, get its identity column |
400 | 400 | $identity = null; |
401 | 401 | $tableRaw = preg_replace( '#\[([^\]]*)\]#', '$1', $table ); // strip matching square brackets from table name |
— | — | @@ -404,23 +404,23 @@ |
405 | 405 | $identity = array_pop( $res->fetch( SQLSRV_FETCH_ASSOC ) ); |
406 | 406 | } |
407 | 407 | unset( $res ); |
408 | | - |
| 408 | + |
409 | 409 | foreach ( $arrToInsert as $blah => $a ) { |
410 | 410 | // start out with empty identity column, this is so we can return it as a result of the insert logic |
411 | 411 | $sqlPre = ''; |
412 | 412 | $sqlPost = ''; |
413 | 413 | $identityClause = ''; |
414 | | - |
| 414 | + |
415 | 415 | // if we have an identity column |
416 | 416 | if( $identity ) { |
417 | | - // iterate through |
| 417 | + // iterate through |
418 | 418 | foreach ($a as $k => $v ) { |
419 | 419 | if ( $k == $identity ) { |
420 | 420 | if( !is_null($v) ){ |
421 | 421 | // there is a value being passed to us, we need to turn on and off inserted identity |
422 | 422 | $sqlPre = "SET IDENTITY_INSERT $table ON;" ; |
423 | 423 | $sqlPost = ";SET IDENTITY_INSERT $table OFF;"; |
424 | | - |
| 424 | + |
425 | 425 | } else { |
426 | 426 | // we can't insert NULL into an identity column, so remove the column from the insert. |
427 | 427 | unset( $a[$k] ); |
— | — | @@ -429,10 +429,10 @@ |
430 | 430 | } |
431 | 431 | $identityClause = "OUTPUT INSERTED.$identity "; // we want to output an identity column as result |
432 | 432 | } |
433 | | - |
| 433 | + |
434 | 434 | $keys = array_keys( $a ); |
435 | | - |
436 | | - |
| 435 | + |
| 436 | + |
437 | 437 | // INSERT IGNORE is not supported by SQL Server |
438 | 438 | // remove IGNORE from options list and set ignore flag to true |
439 | 439 | $ignoreClause = false; |
— | — | @@ -442,20 +442,20 @@ |
443 | 443 | $ignoreClause = true; |
444 | 444 | } |
445 | 445 | } |
446 | | - |
| 446 | + |
447 | 447 | // translate MySQL INSERT IGNORE to something SQL Server can use |
448 | 448 | // example: |
449 | 449 | // MySQL: INSERT IGNORE INTO user_groups (ug_user,ug_group) VALUES ('1','sysop') |
450 | | - // MSSQL: IF NOT EXISTS (SELECT * FROM user_groups WHERE ug_user = '1') INSERT INTO user_groups (ug_user,ug_group) VALUES ('1','sysop') |
| 450 | + // MSSQL: IF NOT EXISTS (SELECT * FROM user_groups WHERE ug_user = '1') INSERT INTO user_groups (ug_user,ug_group) VALUES ('1','sysop') |
451 | 451 | if ( $ignoreClause == true ) { |
452 | 452 | $prival = $a[$keys[0]]; |
453 | 453 | $sqlPre .= "IF NOT EXISTS (SELECT * FROM $table WHERE $keys[0] = '$prival')"; |
454 | 454 | } |
455 | | - |
| 455 | + |
456 | 456 | // Build the actual query |
457 | 457 | $sql = $sqlPre . 'INSERT ' . implode( ' ', $options ) . |
458 | 458 | " INTO $table (" . implode( ',', $keys ) . ") $identityClause VALUES ("; |
459 | | - |
| 459 | + |
460 | 460 | $first = true; |
461 | 461 | foreach ( $a as $key => $value ) { |
462 | 462 | if ( $first ) { |
— | — | @@ -478,10 +478,10 @@ |
479 | 479 | } |
480 | 480 | } |
481 | 481 | $sql .= ')' . $sqlPost; |
482 | | - |
| 482 | + |
483 | 483 | // Run the query |
484 | 484 | $ret = sqlsrv_query( $this->mConn, $sql ); |
485 | | - |
| 485 | + |
486 | 486 | if ( $ret === false ) { |
487 | 487 | throw new DBQueryError( $this, $this->getErrors(), $this->lastErrno(), $sql, $fname ); |
488 | 488 | } elseif ( $ret != NULL ) { |
— | — | @@ -499,7 +499,7 @@ |
500 | 500 | } |
501 | 501 | return $allOk; |
502 | 502 | } |
503 | | - |
| 503 | + |
504 | 504 | /** |
505 | 505 | * INSERT SELECT wrapper |
506 | 506 | * $varMap must be an associative array of the form array( 'dest1' => 'source1', ...) |
— | — | @@ -511,7 +511,7 @@ |
512 | 512 | $insertOptions = array(), $selectOptions = array() ) |
513 | 513 | { |
514 | 514 | $ret = parent::insertSelect( $destTable, $srcTable, $varMap, $conds, $fname, $insertOptions, $selectOptions ); |
515 | | - |
| 515 | + |
516 | 516 | if ( $ret === false ) { |
517 | 517 | throw new DBQueryError( $this, $this->getErrors(), $this->lastErrno(), $sql, $fname ); |
518 | 518 | } elseif ( $ret != NULL ) { |
— | — | @@ -521,7 +521,7 @@ |
522 | 522 | } |
523 | 523 | return NULL; |
524 | 524 | } |
525 | | - |
| 525 | + |
526 | 526 | /** |
527 | 527 | * Format a table name ready for use in constructing an SQL query |
528 | 528 | * |
— | — | @@ -660,7 +660,7 @@ |
661 | 661 | # Returns the size of a text field, or -1 for "unlimited" |
662 | 662 | function textFieldSize( $table, $field ) { |
663 | 663 | $table = $this->tableName( $table ); |
664 | | - $sql = "SELECT CHARACTER_MAXIMUM_LENGTH,DATA_TYPE FROM INFORMATION_SCHEMA.Columns |
| 664 | + $sql = "SELECT CHARACTER_MAXIMUM_LENGTH,DATA_TYPE FROM INFORMATION_SCHEMA.Columns |
665 | 665 | WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'"; |
666 | 666 | $res = $this->query( $sql ); |
667 | 667 | $row = $this->fetchRow( $res ); |
— | — | @@ -689,7 +689,7 @@ |
690 | 690 | SELECT sub2.*, ROW_NUMBER() OVER(ORDER BY sub2.line2) AS line3 FROM ( |
691 | 691 | SELECT 1 AS line2, sub1.* FROM (' . $sql . ') AS sub1 |
692 | 692 | ) as sub2 |
693 | | - ) AS sub3 |
| 693 | + ) AS sub3 |
694 | 694 | WHERE line3 BETWEEN ' . ( $offset + 1 ) . ' AND ' . ( $offset + $limit ); |
695 | 695 | return $sql; |
696 | 696 | } |
— | — | @@ -708,14 +708,14 @@ |
709 | 709 | $offset = $matches[3] or |
710 | 710 | $offset = $matches[6] or |
711 | 711 | $offset = false; |
712 | | - |
| 712 | + |
713 | 713 | // strip the matching LIMIT clause out |
714 | 714 | $sql = str_replace( $matches[0], '', $sql ); |
715 | 715 | return $this->limitResult( $sql, $row_count, $offset ); |
716 | 716 | } |
717 | 717 | return $sql; |
718 | 718 | } |
719 | | - |
| 719 | + |
720 | 720 | // MSSQL does support this, but documentation is too thin to make a generalized |
721 | 721 | // function for this. Apparently UPDATE TOP (N) works, but the sort order |
722 | 722 | // may not be what we're expecting so the top n results may be a random selection. |
— | — | @@ -723,8 +723,8 @@ |
724 | 724 | function limitResultForUpdate( $sql, $num ) { |
725 | 725 | return $sql; |
726 | 726 | } |
727 | | - |
728 | | - |
| 727 | + |
| 728 | + |
729 | 729 | function timestamp( $ts = 0 ) { |
730 | 730 | return wfTimestamp( TS_ISO_8601, $ts ); |
731 | 731 | } |
— | — | @@ -747,7 +747,7 @@ |
748 | 748 | } |
749 | 749 | |
750 | 750 | function tableExists ( $table, $schema = false ) { |
751 | | - $res = sqlsrv_query( $this->mConn, "SELECT * FROM information_schema.tables |
| 751 | + $res = sqlsrv_query( $this->mConn, "SELECT * FROM information_schema.tables |
752 | 752 | WHERE table_type='BASE TABLE' AND table_name = '$table'" ); |
753 | 753 | if ( $res === false ) { |
754 | 754 | print( "Error in tableExists query: " . $this->getErrors() ); |
— | — | @@ -758,13 +758,13 @@ |
759 | 759 | else |
760 | 760 | return false; |
761 | 761 | } |
762 | | - |
| 762 | + |
763 | 763 | /** |
764 | 764 | * Query whether a given column exists in the mediawiki schema |
765 | 765 | */ |
766 | 766 | function fieldExists( $table, $field, $fname = 'DatabaseMssql::fieldExists' ) { |
767 | 767 | $table = $this->tableName( $table ); |
768 | | - $res = sqlsrv_query( $this->mConn, "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.Columns |
| 768 | + $res = sqlsrv_query( $this->mConn, "SELECT DATA_TYPE FROM INFORMATION_SCHEMA.Columns |
769 | 769 | WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" ); |
770 | 770 | if ( $res === false ) { |
771 | 771 | print( "Error in fieldExists query: " . $this->getErrors() ); |
— | — | @@ -778,7 +778,7 @@ |
779 | 779 | |
780 | 780 | function fieldInfo( $table, $field ) { |
781 | 781 | $table = $this->tableName( $table ); |
782 | | - $res = sqlsrv_query( $this->mConn, "SELECT * FROM INFORMATION_SCHEMA.Columns |
| 782 | + $res = sqlsrv_query( $this->mConn, "SELECT * FROM INFORMATION_SCHEMA.Columns |
783 | 783 | WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" ); |
784 | 784 | if ( $res === false ) { |
785 | 785 | print( "Error in fieldInfo query: " . $this->getErrors() ); |
— | — | @@ -796,7 +796,7 @@ |
797 | 797 | sqlsrv_begin_transaction( $this->mConn ); |
798 | 798 | $this->mTrxLevel = 1; |
799 | 799 | } |
800 | | - |
| 800 | + |
801 | 801 | /** |
802 | 802 | * End a transaction |
803 | 803 | */ |
— | — | @@ -813,7 +813,7 @@ |
814 | 814 | sqlsrv_rollback( $this->mConn ); |
815 | 815 | $this->mTrxLevel = 0; |
816 | 816 | } |
817 | | - |
| 817 | + |
818 | 818 | function setup_database() { |
819 | 819 | global $wgVersion, $wgDBport, $wgDBuser; |
820 | 820 | |
— | — | @@ -887,58 +887,58 @@ |
888 | 888 | $dbName = $this->escapeIdentifier( $dbName ); |
889 | 889 | |
890 | 890 | // It is not clear what can be used as a login, |
891 | | - // From http://msdn.microsoft.com/en-us/library/ms173463.aspx |
| 891 | + // From http://msdn.microsoft.com/en-us/library/ms173463.aspx |
892 | 892 | // a sysname may be the same as an identifier. |
893 | 893 | $newUser = $this->escapeIdentifier( $newUser ); |
894 | 894 | $loginPassword = $this->addQuotes( $loginPassword ); |
895 | | - |
| 895 | + |
896 | 896 | $this->doQuery("CREATE DATABASE $dbName;"); |
897 | 897 | $this->doQuery("USE $dbName;"); |
898 | 898 | $this->doQuery("CREATE SCHEMA $dbName;"); |
899 | 899 | $this->doQuery(" |
900 | | - CREATE |
901 | | - LOGIN $newUser |
902 | | - WITH |
| 900 | + CREATE |
| 901 | + LOGIN $newUser |
| 902 | + WITH |
903 | 903 | PASSWORD=$loginPassword |
904 | 904 | ; |
905 | 905 | "); |
906 | 906 | $this->doQuery(" |
907 | | - CREATE |
908 | | - USER $newUser |
909 | | - FOR |
910 | | - LOGIN $newUser |
911 | | - WITH |
| 907 | + CREATE |
| 908 | + USER $newUser |
| 909 | + FOR |
| 910 | + LOGIN $newUser |
| 911 | + WITH |
912 | 912 | DEFAULT_SCHEMA=$dbName |
913 | 913 | ; |
914 | 914 | "); |
915 | 915 | $this->doQuery(" |
916 | | - GRANT |
917 | | - BACKUP DATABASE, |
918 | | - BACKUP LOG, |
919 | | - CREATE DEFAULT, |
920 | | - CREATE FUNCTION, |
921 | | - CREATE PROCEDURE, |
922 | | - CREATE RULE, |
| 916 | + GRANT |
| 917 | + BACKUP DATABASE, |
| 918 | + BACKUP LOG, |
| 919 | + CREATE DEFAULT, |
| 920 | + CREATE FUNCTION, |
| 921 | + CREATE PROCEDURE, |
| 922 | + CREATE RULE, |
923 | 923 | CREATE TABLE, |
924 | | - CREATE VIEW, |
925 | | - CREATE FULLTEXT CATALOG |
926 | | - ON |
927 | | - DATABASE::$dbName |
| 924 | + CREATE VIEW, |
| 925 | + CREATE FULLTEXT CATALOG |
| 926 | + ON |
| 927 | + DATABASE::$dbName |
928 | 928 | TO $newUser |
929 | 929 | ; |
930 | 930 | "); |
931 | 931 | $this->doQuery(" |
932 | | - GRANT |
| 932 | + GRANT |
933 | 933 | CONTROL |
934 | | - ON |
935 | | - SCHEMA::$dbName |
| 934 | + ON |
| 935 | + SCHEMA::$dbName |
936 | 936 | TO $newUser |
937 | 937 | ; |
938 | 938 | "); |
939 | | - |
940 | | - |
| 939 | + |
| 940 | + |
941 | 941 | } |
942 | | - |
| 942 | + |
943 | 943 | function encodeBlob( $b ) { |
944 | 944 | // we can't have zero's and such, this is a simple encoding to make sure we don't barf |
945 | 945 | return base64_encode( $b ); |
— | — | @@ -1029,7 +1029,7 @@ |
1030 | 1030 | if ( isset( $options['ORDER BY'] ) ) $tailOpts .= " ORDER BY {$options['ORDER BY']}"; |
1031 | 1031 | |
1032 | 1032 | if ( isset( $noKeyOptions['DISTINCT'] ) && isset( $noKeyOptions['DISTINCTROW'] ) ) $startOpts .= 'DISTINCT'; |
1033 | | - |
| 1033 | + |
1034 | 1034 | // we want this to be compatible with the output of parent::makeSelectOptions() |
1035 | 1035 | return array( $startOpts, '' , $tailOpts, '' ); |
1036 | 1036 | } |
— | — | @@ -1044,7 +1044,7 @@ |
1045 | 1045 | function buildConcat( $stringList ) { |
1046 | 1046 | return implode( ' + ', $stringList ); |
1047 | 1047 | } |
1048 | | - |
| 1048 | + |
1049 | 1049 | public function getSearchEngine() { |
1050 | 1050 | return "SearchMssql"; |
1051 | 1051 | } |
— | — | @@ -1092,7 +1092,7 @@ |
1093 | 1093 | } |
1094 | 1094 | |
1095 | 1095 | /** |
1096 | | - * The MSSQL PHP driver doesn't support sqlsrv_num_rows, so we recall all rows into an array and maintain our |
| 1096 | + * The MSSQL PHP driver doesn't support sqlsrv_num_rows, so we recall all rows into an array and maintain our |
1097 | 1097 | * own cursor index into that array...This is similar to the way the Oracle driver handles this same issue |
1098 | 1098 | * |
1099 | 1099 | * @ingroup Database |
— | — | @@ -1131,7 +1131,7 @@ |
1132 | 1132 | } |
1133 | 1133 | return $obj; |
1134 | 1134 | } |
1135 | | - |
| 1135 | + |
1136 | 1136 | public function fetch( $mode = SQLSRV_FETCH_BOTH, $object_class = 'stdClass' ) { |
1137 | 1137 | if ( $this->mCursor >= $this->mRowCount || $this->mRowCount == 0 ) return false; |
1138 | 1138 | $ret = false; |
— | — | @@ -1157,7 +1157,7 @@ |
1158 | 1158 | $ret = $this->mRows[$this->mCursor] + $arrNum; |
1159 | 1159 | break; |
1160 | 1160 | } |
1161 | | - |
| 1161 | + |
1162 | 1162 | $this->mCursor++; |
1163 | 1163 | return $ret; |
1164 | 1164 | } |