From: U-REDMOND\emadelw Date: Thu, 18 Sep 2014 20:36:46 +0000 (-0700) Subject: Fix some issues with Microsoft SQL Server Driver X-Git-Tag: 1.31.0-rc.0~13930^2 X-Git-Url: https://git.cyclocoop.org/%28%28?a=commitdiff_plain;h=90e64c325abdf618438c084b7838fa77a4baeef8;p=lhc%2Fweb%2Fwiklou.git Fix some issues with Microsoft SQL Server Driver * INSERT IGNORE now works properly * Only return an inserted id if the INSERT was actually successful * Fix syntax error when doing LIMIT queries Bug: 71024 Change-Id: I4dddc5c9c234b17040a28937987406511ec6ea9f --- diff --git a/includes/db/DatabaseMssql.php b/includes/db/DatabaseMssql.php index 3a4bb27058..af3cc72d8c 100644 --- a/includes/db/DatabaseMssql.php +++ b/includes/db/DatabaseMssql.php @@ -228,7 +228,7 @@ class DatabaseMssql extends DatabaseBase { if ( $success ) { $this->mAffectedRows = 0; - return true; + return $stmt; } } } @@ -415,10 +415,8 @@ class DatabaseMssql extends DatabaseBase { } $this->mScrollableCursor = true; $this->mPrepareStatements = true; - return $ret; } - return $this->query( $sql, $fname ); } @@ -614,6 +612,13 @@ class DatabaseMssql extends DatabaseBase { // Determine binary/varbinary fields so we can encode data as a hex string like 0xABCDEF $binaryColumns = $this->getBinaryColumns( $table ); + // INSERT IGNORE is not supported by SQL Server + // remove IGNORE from options list and set ignore flag to true + if ( in_array( 'IGNORE', $options ) ) { + $options = array_diff( $options, array( 'IGNORE' ) ); + $this->mIgnoreDupKeyErrors = true; + } + foreach ( $arrToInsert as $a ) { // start out with empty identity column, this is so we can return // it as a result of the insert logic @@ -645,14 +650,6 @@ class DatabaseMssql extends DatabaseBase { $keys = array_keys( $a ); - // INSERT IGNORE is not supported by SQL Server - // remove IGNORE from options list and set ignore flag to true - $ignoreClause = false; - if ( in_array( 'IGNORE', $options ) ) { - $options = array_diff( $options, array( 'IGNORE' ) ); - $this->mIgnoreDupKeyErrors = true; - } - // Build the actual query $sql = $sqlPre . 'INSERT ' . implode( ' ', $options ) . " INTO $table (" . implode( ',', $keys ) . ") $identityClause VALUES ("; @@ -691,15 +688,16 @@ class DatabaseMssql extends DatabaseBase { throw $e; } $this->mScrollableCursor = true; - $this->mIgnoreDupKeyErrors = false; if ( !is_null( $identity ) ) { // then we want to get the identity column value we were assigned and save it off $row = $ret->fetchObject(); - $this->mInsertId = $row->$identity; + if( is_object( $row ) ){ + $this->mInsertId = $row->$identity; + } } } - + $this->mIgnoreDupKeyErrors = false; return $ret; } @@ -921,7 +919,7 @@ class DatabaseMssql extends DatabaseBase { } if ( !$s2 ) { // no ORDER BY - $overOrder = 'ORDER BY 1'; + $overOrder = 'ORDER BY (SELECT 1)'; } else { if ( !isset( $orderby[2] ) || !$orderby[2] ) { // don't need to strip it out if we're using a FOR XML clause