From 8e5898a11b8c35e8af91230719b9761a5ec6a54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20H=C5=AFla?= Date: Wed, 10 Apr 2013 11:08:31 +0200 Subject: [PATCH 1/4] DibiMsSql2005Driver: default charset set to UTF-8 If charset is not specified in config, NULL is passed as connection option and 'Invalid value type for option CharacterSet was specified. String type was expected.' is thrown. --- dibi/drivers/mssql2005.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dibi/drivers/mssql2005.php b/dibi/drivers/mssql2005.php index 999c5fd4..d661a8c0 100644 --- a/dibi/drivers/mssql2005.php +++ b/dibi/drivers/mssql2005.php @@ -73,6 +73,9 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult $this->connection = $config['resource']; } else { + // Default values + if (!isset($config['options']['CharacterSet'])) $config['options']['CharacterSet'] = 'UTF-8'; + $this->connection = sqlsrv_connect($config['host'], (array) $config['options']); } From 3634673ffabb88ddd07acc73ce6a88fa049fb8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20H=C5=AFla?= Date: Wed, 10 Apr 2013 11:24:55 +0200 Subject: [PATCH 2/4] DibiPdoDriver: applyLimit() for sqlsrv driver Added table alias has been tested with MS SQL Server 2012 directly and over ODBC. --- dibi/drivers/pdo.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index a88ccc8d..aa9c0089 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -372,8 +372,9 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver case 'odbc': case 'mssql': + case 'sqlsrv': if ($offset < 1) { - $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ')'; + $sql = 'SELECT TOP ' . (int) $limit . ' * FROM (' . $sql . ') t'; break; } // intentionally break omitted From 4ea885f2b98fe9c956eea446fc3c8e9ecb6efa84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20H=C5=AFla?= Date: Wed, 10 Apr 2013 11:36:01 +0200 Subject: [PATCH 3/4] DibiPdoDriver: added identifier escaping for sqlsrv --- dibi/drivers/pdo.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dibi/drivers/pdo.php b/dibi/drivers/pdo.php index aa9c0089..e2eab25b 100644 --- a/dibi/drivers/pdo.php +++ b/dibi/drivers/pdo.php @@ -285,6 +285,9 @@ class DibiPdoDriver extends DibiObject implements IDibiDriver, IDibiResultDriver case 'mssql': return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']'; + case 'sqlsrv': + return '[' . str_replace(']', ']]', $value) . ']'; + default: return $value; } From 0ebe7ad84f528b5373166ff2b68896930a23a0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20H=C5=AFla?= Date: Wed, 10 Apr 2013 12:06:27 +0200 Subject: [PATCH 4/4] DibiMsSql2005Driver: fixed identifier escaping Annoted link to MS SQL doc does not talk about open bracket '[' escaping, only closing bracket ']'. dibi::query('CREATE TABLE %n (id INT)', 'abc[]def'); - old: creates table 'abc[[]def' - new: creates table 'abc[]def' --- dibi/drivers/mssql2005.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dibi/drivers/mssql2005.php b/dibi/drivers/mssql2005.php index d661a8c0..de888801 100644 --- a/dibi/drivers/mssql2005.php +++ b/dibi/drivers/mssql2005.php @@ -243,7 +243,7 @@ class DibiMsSql2005Driver extends DibiObject implements IDibiDriver, IDibiResult case dibi::IDENTIFIER: // @see http://msdn.microsoft.com/en-us/library/ms176027.aspx - return '[' . str_replace(array('[', ']'), array('[[', ']]'), $value) . ']'; + return '[' . str_replace(']', ']]', $value) . ']'; case dibi::BOOL: return $value ? 1 : 0;