1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-11 00:24:19 +02:00

DibiPdoDriver: added support for MsSql2012 Offset

Since MsSql2012 allow using of OFFSET, I added this option to the driver for PDO. Driver will automaticly recognize this is proper version and use the new offset.
This commit is contained in:
Radovan Kepák
2015-02-19 10:23:50 +01:00
parent 020b15c0e2
commit 3779a5034a
2 changed files with 95 additions and 2 deletions

View File

@@ -38,6 +38,9 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
/** @var string */
private $driverName;
/** @var string */
private $serverVersion;
/**
* @throws DibiNotSupportedException
@@ -75,6 +78,7 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
$this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
$this->serverVersion = $this->connection->getAttribute(PDO::ATTR_SERVER_VERSION);
}
@@ -396,10 +400,19 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver
}
break;
case 'odbc':
case 'dblib':
case 'mssql':
case 'sqlsrv':
case 'dblib':
if (version_compare($this->serverVersion, '11.0') >= 0) {
if ($offset >= 0 || $limit >= 0) {
$sql .= ' OFFSET ' . (int) $offset . ' ROWS'
. ($limit > 0 ? ' FETCH NEXT ' . (int) $limit . ' ROWS ONLY' : '');
}
break;
}
// intentionally break omitted
case 'odbc':
if ($offset < 1) {
$sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t';
break;