r34610 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34609‎ | r34610 | r34611 >
Date:11:23, 11 May 2008
Author:nad
Status:old
Tags:
Comment:
pages can render, but many operations break it
Modified paths:
  • /trunk/phase3/includes/DatabaseMssql.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/DatabaseMssql.php
@@ -4,7 +4,7 @@
55 * - Licenced under LGPL (http://www.gnu.org/copyleft/lesser.html)
66 * - Author: [http://www.organicdesign.co.nz/nad User:Nad]
77 *
8 - * {{php}}{{category:Extensions|DatabaseMssql.php}}
 8+ * See maintenance/mssql/README for development notes and other specific information
99 */
1010
1111 /**
@@ -14,6 +14,8 @@
1515
1616 var $mAffectedRows;
1717 var $mLastResult;
 18+ var $mLastError;
 19+ var $mLastErrorNo;
1820 var $mDatabaseFile;
1921
2022 /**
@@ -135,11 +137,20 @@
136138 }
137139
138140 /**
139 - * MSSQL doesn't seem to do buffered results
 141+ * - MSSQL doesn't seem to do buffered results
 142+ * - the trasnaction syntax is modified here to avoid having to replicate
 143+ * Database::query which uses BEGIN, COMMIT, ROLLBACK
140144 */
141145 function doQuery($sql) {
142 - print "<pre>\n$sql\n</pre>";
 146+ if ($sql == 'BEGIN' || $sql == 'COMMIT' || $sql == 'ROLLBACK') return true; # $sql .= ' TRANSACTION';
 147+ $sql = preg_replace('|[^\x07-\x7e]|','?',$sql); # TODO: need to fix unicode - just removing it here while testing
143148 $ret = mssql_query($sql, $this->mConn);
 149+ if ($ret === false) {
 150+ $err = mssql_get_last_message();
 151+ if ($err) $this->mlastError = $err;
 152+ $row = mssql_fetch_row(mssql_query('select @@ERROR'));
 153+ if ($row[0]) $this->mlastErrorNo = $row[0];
 154+ } else $this->mlastErrorNo = false;
144155 return $ret;
145156 }
146157
@@ -172,7 +183,7 @@
173184 $res = $res->result;
174185 }
175186 @/**/$row = mssql_fetch_object( $res );
176 - if( $this->lastErrno() ) {
 187+ if ( $this->lastErrno() ) {
177188 throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) );
178189 }
179190 return $row;
@@ -205,7 +216,7 @@
206217 $res = $res->result;
207218 }
208219 @/**/$n = mssql_num_rows( $res );
209 - if( $this->lastErrno() ) {
 220+ if ( $this->lastErrno() ) {
210221 throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( $this->lastError() ) );
211222 }
212223 return $n;
@@ -264,16 +275,14 @@
265276 * Get the last error number
266277 */
267278 function lastErrno() {
268 - $row = mssql_fetch_row(mssql_query('select @@ERROR'));
269 - return $row[0];
 279+ return $this->mlastErrorNo;
270280 }
271281
272282 /**
273283 * Get a description of the last error
274284 */
275285 function lastError() {
276 - return mssql_get_last_message();
277 - return $error;
 286+ return $this->mlastError;
278287 }
279288
280289 /**
@@ -600,7 +609,7 @@
601610 # If multiple and ignore, then do each row as a separate conditional insert
602611 foreach ($a as $row) {
603612 $prival = $row[$keys[0]];
604 - $sql = "IF NOT EXISTS (SELECT * FROM $table WHERE $keys[0] = $prival) $sql";
 613+ $sql = "IF NOT EXISTS (SELECT * FROM $table WHERE $keys[0] = '$prival') $sql";
605614 if (!$this->query("$sql (".$this->makeListWithoutNulls($row).')', $fname)) return false;
606615 }
607616 return true;
@@ -614,7 +623,7 @@
615624 } else {
616625 if ($ignore) {
617626 $prival = $a[$keys[0]];
618 - $sql = "IF NOT EXISTS (SELECT * FROM $table WHERE $keys[0] = $prival) $sql";
 627+ $sql = "IF NOT EXISTS (SELECT * FROM $table WHERE $keys[0] = '$prival') $sql";
619628 }
620629 $sql .= '('.$this->makeListWithoutNulls($a).')';
621630 }
@@ -681,10 +690,10 @@
682691 }
683692
684693 /**
685 - * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
 694+ * MSSQL has a problem with the backtick quoting, so all this does is ensure the prefix is added exactly once
686695 */
687696 function tableName($name) {
688 - return str_replace('`','',parent::tableName($name));
 697+ return strpos($name, $this->mTablePrefix) === 0 ? $name : "{$this->mTablePrefix}$name";
689698 }
690699
691700 /**
@@ -867,31 +876,6 @@
868877
869878 /**
870879 * Begin a transaction, committing any previously open transaction
871 - */
872 - function begin( $fname = 'Database::begin' ) {
873 - $this->query( 'BEGIN TRANSACTION', $fname );
874 - $this->mTrxLevel = 1;
875 - }
876 -
877 - /**
878 - * End a transaction
879 - */
880 - function commit( $fname = 'Database::commit' ) {
881 - $this->query( 'COMMIT TRANSACTION', $fname );
882 - $this->mTrxLevel = 0;
883 - }
884 -
885 - /**
886 - * Rollback a transaction.
887 - * No-op on non-transactional databases.
888 - */
889 - function rollback( $fname = 'Database::rollback' ) {
890 - $this->query( 'ROLLBACK TRANSACTION', $fname, true );
891 - $this->mTrxLevel = 0;
892 - }
893 -
894 - /**
895 - * Begin a transaction, committing any previously open transaction
896880 * @deprecated use begin()
897881 */
898882 function immediateBegin( $fname = 'Database::immediateBegin' ) {
@@ -972,7 +956,7 @@
973957 $mssql_tmpl = "$IP/maintenance/mssql/tables.sql";
974958
975959 # Make an MSSQL template file if it doesn't exist (based on the same one MySQL uses to create a new wiki db)
976 - if (1 || !file_exists($mssql_tmpl)) { # todo: make this conditional again
 960+ if (!file_exists($mssql_tmpl)) { # todo: make this conditional again
977961 $sql = file_get_contents($mysql_tmpl);
978962 $sql = preg_replace('/^\s*--.*?$/m','',$sql); # strip comments
979963 $sql = preg_replace('/^\s*(UNIQUE )?(INDEX|KEY|FULLTEXT).+?$/m', '', $sql); # These indexes should be created with a CREATE INDEX query

Status & tagging log