Proposed new sqlsrv drivers.
Is it possible to include the fixes and modifications done at the following links which seem to fix most of the MSSQL related issue?
http://codeigniter.com/forums/viewthread/160626/P10/ https://bitbucket.org/ellislab/codeigniter-reactor/pull-request/11/revising-the-sqlsrv-driver-for-windows
https://bitbucket.org/ellislab/codeigniter-reactor/pull-request/11/revising-the-sqlsrv-driver-for-windows The changes in the forge part are a total mess? I'm having problems with the DBForge and SQLSRV driver so though I'd try yours out, however your forge class is unusable :( can you check what you uploaded.
I don't really like how the rownum column is forced into the result set. Is there a way around this?
Did not see the earlier update on this change. Tsk tsk for not reading my email. I will find my code and post the changes or the entire classes that I have been using.
Here it is for SQL Server 2012: https://github.com/EllisLab/CodeIgniter/commit/d25c589dc3bbfc83fb59bbeb1a3046b99bf694f8
Here is my code for the _limit method. I was able to break out the original columns and everything. I'm not sure about the sqlsrv_forge being broken...
/**
* Limit string
*
* Generates a platform-specific LIMIT clause
*
* @param string the sql query string
* @param integer the number of rows to limit the query to
* @param integer the offset value
* @return string
*/
protected function _limit($sql, $limit, $offset)
{
//return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.($limit + $offset).' ', $sql); //original
if($offset === FALSE) {
// do simple limit if no offset
$i = $limit + $offset;
return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$i.' ', $sql);
} else {
// As of SQL Server 2012 (11.0.*) OFFSET is supported
if(version_compare($this->version(), '11', '>=')) {
return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY';
} else {
$orderBy = "ORDER BY ";
if(empty($this->ar_orderby))
{
$message = "MSSQL must have an ORDER BY when limiting by offset.";
show_error($message);
log_message('error',$message);
}
$orderBy .= implode(', ', $this->ar_orderby);
if ($this->ar_order !== FALSE)
{
$orderBy .= ($this->ar_order == 'desc') ? ' DESC' : ' ASC';
}
// need to escape regex special characters in $orderBy by using preg_quote()
$sql = preg_replace('/(\\'. preg_quote($orderBy) .'\n?)/i','', $sql); // remove orderBy from original SQL as the OVER statement uses it
$sql = preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 row_number() OVER ('.$orderBy.') AS CI_offset_row_number, ', $sql);
$columns = implode(',',$this->ar_select);
$newSQL = "SELECT " . $columns . " \nFROM (\n" . $sql . ") AS A \nWHERE A.CI_offset_row_number BETWEEN (" .($offset + 1) . ") AND (".($offset + $limit).")";
return $newSQL;
}
}
}
I guess there's no other way around it ... https://github.com/EllisLab/CodeIgniter/commit/71379ca89226fe8af0314a8b70e5dc0f57367255
Yeah, it's really messy until they decided to add the support for it in 2012... :(