From 30fd9fff145c9126c0d01cc2566b181aa9f4782c Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Tue, 26 Apr 2011 09:17:51 -0400 Subject: [PATCH 01/13] Changed the import files and Mssql class name to the new structure. --- lib/Cake/Model/Datasource/Database/Mssql.php | 4 +++- .../Model/Datasource/Database/MssqlTest.php | 18 ++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index b09e58a77..11e2f6caa 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -17,6 +17,8 @@ * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ +App::uses('DboSource', 'Model/Datasource'); + /** * MS SQL layer for DBO * @@ -24,7 +26,7 @@ * * @package cake.libs.model.datasources.dbo */ -class DboMssql extends DboSource { +class Mssql extends DboSource { /** * Driver description diff --git a/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php b/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php index d4d1de10e..bc7d852c0 100644 --- a/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php +++ b/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php @@ -1,6 +1,6 @@ db = new DboMssqlTestDb($db->config); + $this->db = new MssqlTestDb($db->config); $this->model = new MssqlTestModel(); } From 4e8b8639100c67b8c89edafc7eef42aa4f4afc91 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 27 Apr 2011 20:41:29 -0400 Subject: [PATCH 02/13] Initial changes for init the connection with MSSQL. --- lib/Cake/Model/Datasource/Database/Mssql.php | 78 ++++++-------------- 1 file changed, 21 insertions(+), 57 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 11e2f6caa..77213e3e7 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -64,11 +64,10 @@ class Mssql extends DboSource { */ protected $_baseConfig = array( 'persistent' => true, - 'host' => 'localhost', - 'login' => 'root', + 'host' => '(local)\sqlexpress', + 'login' => '', 'password' => '', - 'database' => 'cake', - 'port' => '1433', + 'database' => 'cake' ); /** @@ -109,22 +108,6 @@ class Mssql extends DboSource { * @access private */ private $__lastQueryHadError = false; -/** - * MS SQL DBO driver constructor; sets SQL Server error reporting defaults - * - * @param array $config Configuration data from app/config/databases.php - * @return boolean True if connected successfully, false on error - */ - function __construct($config, $autoConnect = true) { - if ($autoConnect) { - if (!function_exists('mssql_min_message_severity')) { - trigger_error(__d('cake_dev', "PHP SQL Server interface is not installed, cannot continue. For troubleshooting information, see http://php.net/mssql/"), E_USER_WARNING); - } - mssql_min_message_severity(15); - mssql_min_error_severity(2); - } - return parent::__construct($config, $autoConnect); - } /** * Connects to the database using options in the given configuration array. @@ -133,53 +116,34 @@ class Mssql extends DboSource { */ function connect() { $config = $this->config; - - $os = env('OS'); - if (!empty($os) && strpos($os, 'Windows') !== false) { - $sep = ','; - } else { - $sep = ':'; - } $this->connected = false; - - if (is_numeric($config['port'])) { - $port = $sep . $config['port']; // Port number - } elseif ($config['port'] === null) { - $port = ''; // No port - SQL Server 2005 - } else { - $port = '\\' . $config['port']; // Named pipe - } - - if (!$config['persistent']) { - $this->connection = mssql_connect($config['host'] . $port, $config['login'], $config['password'], true); - } else { - $this->connection = mssql_pconnect($config['host'] . $port, $config['login'], $config['password']); - } - - if (mssql_select_db($config['database'], $this->connection)) { - $this->_execute("SET DATEFORMAT ymd"); + try { + $flags = array(PDO::ATTR_PERSISTENT => $config['persistent']); + if (!empty($config['encoding'])) { + $flags[PDO::SQLSRV_ATTR_ENCODING] = $config['encoding']; + } + $this->_connection = new PDO( + "sqlsrv:server={$config['host']};Database={$config['database']}", + $config['login'], + $config['password'], + $flags + ); $this->connected = true; + } catch (PDOException $e) { + throw new MissingConnectionException(array('class' => $e->getMessage())); } + +// $this->_execute("SET DATEFORMAT ymd"); return $this->connected; } /** - * Check that MsSQL is installed/loaded + * Check that PDO SQL Server is installed/loaded * * @return boolean */ - function enabled() { - return extension_loaded('mssql'); - } -/** - * Disconnects from database. - * - * @return boolean True if the database could be disconnected, else false - */ - function disconnect() { - @mssql_free_result($this->results); - $this->connected = !@mssql_close($this->connection); - return !$this->connected; + public function enabled() { + return in_array('sqlsrv', PDO::getAvailableDrivers()); } /** From 244bc1369a69d7c311ae9dd89ccba8e35521c68f Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 27 Apr 2011 20:42:47 -0400 Subject: [PATCH 03/13] Removed the execute method from MSSQL. It is provided by DboDatasource now. --- lib/Cake/Model/Datasource/Database/Mssql.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 77213e3e7..603b22b57 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -146,18 +146,6 @@ class Mssql extends DboSource { return in_array('sqlsrv', PDO::getAvailableDrivers()); } -/** - * Executes given SQL statement. - * - * @param string $sql SQL statement - * @return resource Result resource identifier - */ - protected function _execute($sql) { - $result = @mssql_query($sql, $this->connection); - $this->__lastQueryHadError = ($result === false); - return $result; - } - /** * Returns an array of sources (tables) in the database. * From 3f984b68facd9ba3c1eaa49d87d2bd115a87ce61 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 27 Apr 2011 20:53:42 -0400 Subject: [PATCH 04/13] Update the listSources. --- lib/Cake/Model/Datasource/Database/Mssql.php | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 603b22b57..173ca8994 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -151,26 +151,26 @@ class Mssql extends DboSource { * * @return array Array of tablenames in the database */ - function listSources() { + public function listSources() { $cache = parent::listSources(); - - if ($cache != null) { + if ($cache !== null) { return $cache; } - $result = $this->fetchAll('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES', false); + $result = $this->_execute("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'")); - if (!$result || empty($result)) { + if (!$result) { + $result->closeCursor(); return array(); - } else { - $tables = array(); - - foreach ($result as $table) { - $tables[] = $table[0]['TABLE_NAME']; - } - - parent::listSources($tables); - return $tables; } + + $tables = array(); + while ($line = $result->fetch(PDO::FETCH_ASSOC)) { + $tables[] = $line['TABLE_NAME']; + } + + $result->closeCursor(); + parent::listSources($tables); + return $tables; } /** From 37d26f29234978c59efcd11189aa6e1c1462e502 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 27 Apr 2011 21:27:53 -0400 Subject: [PATCH 05/13] Update the describe. --- lib/Cake/Model/Datasource/Database/Mssql.php | 31 +++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 173ca8994..0f2fa9d05 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -181,40 +181,43 @@ class Mssql extends DboSource { */ function describe($model) { $cache = parent::describe($model); - if ($cache != null) { return $cache; } - - $table = $this->fullTableName($model, false); - $cols = $this->fetchAll("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $table . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $table . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $table . "'", false); - $fields = false; + $table = $this->fullTableName($model, false); + $cols = $this->_execute("SELECT COLUMN_NAME as Field, DATA_TYPE as Type, COL_LENGTH('" . $table . "', COLUMN_NAME) as Length, IS_NULLABLE As [Null], COLUMN_DEFAULT as [Default], COLUMNPROPERTY(OBJECT_ID('" . $table . "'), COLUMN_NAME, 'IsIdentity') as [Key], NUMERIC_SCALE as Size FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $table . "'"); + if (!$cols) { + throw new CakeException(__d('cake_dev', 'Could not describe table for %s', $model->name)); + } + foreach ($cols as $column) { - $field = $column[0]['Field']; + $field = $column->Field; $fields[$field] = array( - 'type' => $this->column($column[0]['Type']), - 'null' => (strtoupper($column[0]['Null']) == 'YES'), - 'default' => preg_replace("/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", "$1", $column[0]['Default']), - 'length' => intval($column[0]['Length']), - 'key' => ($column[0]['Key'] == '1') ? 'primary' : false + 'type' => $this->column($column->Type), + 'null' => ($column->Null === 'YES' ? true : false), + 'default' => preg_replace("/^[(]{1,2}'?([^')]*)?'?[)]{1,2}$/", "$1", $column->Default), + 'length' => intval($column->Type), + 'key' => ($column->Key == '1') ? 'primary' : false ); + if ($fields[$field]['default'] === 'null') { $fields[$field]['default'] = null; } else { $this->value($fields[$field]['default'], $fields[$field]['type']); } - if ($fields[$field]['key'] && $fields[$field]['type'] == 'integer') { + if ($fields[$field]['key'] !== false && $fields[$field]['type'] == 'integer') { $fields[$field]['length'] = 11; - } elseif (!$fields[$field]['key']) { + } elseif ($fields[$field]['key'] === false) { unset($fields[$field]['key']); } if (in_array($fields[$field]['type'], array('date', 'time', 'datetime', 'timestamp'))) { $fields[$field]['length'] = null; } } - $this->__cacheDescription($this->fullTableName($model, false), $fields); + $this->__cacheDescription($table, $fields); + $cols->closeCursor(); return $fields; } From f11b153d80c284853d18df6b1946e600f91f29dc Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Wed, 27 Apr 2011 23:10:44 -0400 Subject: [PATCH 06/13] Removed the value method from MSSQL. It is provided by DboDatasource now. --- lib/Cake/Model/Datasource/Database/Mssql.php | 43 -------------------- 1 file changed, 43 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 0f2fa9d05..0d5b4fc93 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -221,49 +221,6 @@ class Mssql extends DboSource { return $fields; } -/** - * Returns a quoted and escaped string of $data for use in an SQL statement. - * - * @param string $data String to be prepared for use in an SQL statement - * @param string $column The column into which this data will be inserted - * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided - * @return string Quoted and escaped data - */ - function value($data, $column = null, $safe = false) { - $parent = parent::value($data, $column, $safe); - - if ($parent != null) { - return $parent; - } - if ($data === null) { - return 'NULL'; - } - if (in_array($column, array('integer', 'float', 'binary')) && $data === '') { - return 'NULL'; - } - if ($data === '') { - return "''"; - } - - switch ($column) { - case 'boolean': - $data = $this->boolean((bool)$data); - break; - default: - if (get_magic_quotes_gpc()) { - $data = stripslashes(str_replace("'", "''", $data)); - } else { - $data = str_replace("'", "''", $data); - } - break; - } - - if (in_array($column, array('integer', 'float', 'binary')) && is_numeric($data)) { - return $data; - } - return "'" . $data . "'"; - } - /** * Generates the fields list of an SQL query. * From 83b81ffd87d3f8efc0ba1dff783f38caf4b56cb9 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 28 Apr 2011 21:37:34 -0400 Subject: [PATCH 07/13] Removed more methods that is implemented by DboSource. --- lib/Cake/Model/Datasource/Database/Mssql.php | 52 -------------------- 1 file changed, 52 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 0d5b4fc93..7bcefc203 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -338,58 +338,6 @@ class Mssql extends DboSource { return parent::update($model, array_keys($fields), array_values($fields), $conditions); } -/** - * Returns a formatted error message from previous database operation. - * - * @return string Error message with error number - */ - function lastError() { - if ($this->__lastQueryHadError) { - $error = mssql_get_last_message(); - if ($error && !preg_match('/contexto de la base de datos a|contesto di database|changed database|contexte de la base de don|datenbankkontext/i', $error)) { - return $error; - } - } - return null; - } - -/** - * Returns number of affected rows in previous database operation. If no previous operation exists, - * this returns false. - * - * @return integer Number of affected rows - */ - function lastAffected() { - if ($this->_result) { - return mssql_rows_affected($this->connection); - } - return null; - } - -/** - * Returns number of rows in previous resultset. If no previous resultset exists, - * this returns false. - * - * @return integer Number of rows in resultset - */ - function lastNumRows() { - if ($this->_result) { - return @mssql_num_rows($this->_result); - } - return null; - } - -/** - * Returns the ID generated from the previous INSERT operation. - * - * @param unknown_type $source - * @return in - */ - function lastInsertId($source = null) { - $id = $this->fetchRow('SELECT SCOPE_IDENTITY() AS insertID', false); - return $id[0]['insertID']; - } - /** * Returns a limit statement in the correct format for the particular database. * From a7a86e42a310bfe4371eb7229965aaf9c79fbb7e Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 28 Apr 2011 21:46:56 -0400 Subject: [PATCH 08/13] Changes for fetch results. --- lib/Cake/Model/Datasource/Database/Mssql.php | 33 ++++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 7bcefc203..2eb8b6c21 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -406,19 +406,18 @@ class Mssql extends DboSource { } /** - * Enter description here... + * Builds a map of the columns contained in a result * - * @param unknown_type $results + * @param PDOStatement $results */ - function resultSet(&$results) { - $this->results =& $results; + function resultSet($results) { $this->map = array(); - $numFields = mssql_num_fields($results); + $numFields = $results->columnCount(); $index = 0; $j = 0; - while ($j < $numFields) { - $column = mssql_field_name($results, $j); + while ($numFields-- > 0) { + $column = $results->getColumnMeta($index); if (strpos($column, '__')) { if (isset($this->__fieldMappings[$column]) && strpos($this->__fieldMappings[$column], '.')) { @@ -536,22 +535,22 @@ class Mssql extends DboSource { /** * Fetches the next row from the current result set * - * @return unknown + * @return mixed */ function fetchResult() { - if ($row = mssql_fetch_row($this->results)) { + if ($row = $this->_result->fetch()) { $resultRow = array(); - $i = 0; - - foreach ($row as $index => $field) { - list($table, $column) = $this->map[$index]; - $resultRow[$table][$column] = $row[$index]; - $i++; + foreach ($this->map as $col => $meta) { + list($table, $column, $type) = $meta; + $resultRow[$table][$column] = $row[$col]; + if ($type === 'boolean' && !is_null($row[$col])) { + $resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]); + } } return $resultRow; - } else { - return false; } + $this->_result->closeCursor(); + return false; } /** From b91f6eb991758957a66750b753dc467b4defd15d Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 28 Apr 2011 21:52:22 -0400 Subject: [PATCH 09/13] Fixed error in change. --- lib/Cake/Model/Datasource/Database/Mssql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 2eb8b6c21..c6d3db238 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -156,7 +156,7 @@ class Mssql extends DboSource { if ($cache !== null) { return $cache; } - $result = $this->_execute("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'")); + $result = $this->_execute("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'"); if (!$result) { $result->closeCursor(); From 24bf56b44e056cc525585ead4b920d4adb7a8902 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 28 Apr 2011 22:02:54 -0400 Subject: [PATCH 10/13] Revert "Removed the value method from MSSQL. It is provided by DboDatasource now." This reverts commit bf0fb8302385d384239939df2ea6bc6f1a8dbaa0. --- lib/Cake/Model/Datasource/Database/Mssql.php | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index c6d3db238..940344845 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -221,6 +221,49 @@ class Mssql extends DboSource { return $fields; } +/** + * Returns a quoted and escaped string of $data for use in an SQL statement. + * + * @param string $data String to be prepared for use in an SQL statement + * @param string $column The column into which this data will be inserted + * @param boolean $safe Whether or not numeric data should be handled automagically if no column data is provided + * @return string Quoted and escaped data + */ + function value($data, $column = null, $safe = false) { + $parent = parent::value($data, $column, $safe); + + if ($parent != null) { + return $parent; + } + if ($data === null) { + return 'NULL'; + } + if (in_array($column, array('integer', 'float', 'binary')) && $data === '') { + return 'NULL'; + } + if ($data === '') { + return "''"; + } + + switch ($column) { + case 'boolean': + $data = $this->boolean((bool)$data); + break; + default: + if (get_magic_quotes_gpc()) { + $data = stripslashes(str_replace("'", "''", $data)); + } else { + $data = str_replace("'", "''", $data); + } + break; + } + + if (in_array($column, array('integer', 'float', 'binary')) && is_numeric($data)) { + return $data; + } + return "'" . $data . "'"; + } + /** * Generates the fields list of an SQL query. * From 3231755d63aec0ce841ed24c4eb158b5415b70ce Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 28 Apr 2011 22:12:07 -0400 Subject: [PATCH 11/13] Fixed the tests for value. --- lib/Cake/Model/Datasource/Database/Mssql.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index 940344845..f6de416f2 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -232,6 +232,12 @@ class Mssql extends DboSource { function value($data, $column = null, $safe = false) { $parent = parent::value($data, $column, $safe); + if ($column === 'float' && strpos($data, '.') !== false) { + return rtrim($data, '0'); + } + if ($parent === "''") { + return 'NULL'; + } if ($parent != null) { return $parent; } From 9dfc7d65939001392a7aa4f70aa1980ad14a452f Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Thu, 28 Apr 2011 22:20:11 -0400 Subject: [PATCH 12/13] Changed the field map to protected to run the tests. It is not requeried to be private. --- lib/Cake/Model/Datasource/Database/Mssql.php | 22 +++++++++---------- .../Model/Datasource/Database/MssqlTest.php | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/Cake/Model/Datasource/Database/Mssql.php b/lib/Cake/Model/Datasource/Database/Mssql.php index f6de416f2..1383ca138 100644 --- a/lib/Cake/Model/Datasource/Database/Mssql.php +++ b/lib/Cake/Model/Datasource/Database/Mssql.php @@ -55,7 +55,7 @@ class Mssql extends DboSource { * * @var array */ - private $__fieldMappings = array(); + protected $_fieldMappings = array(); /** * Base configuration settings for MS SQL driver @@ -294,7 +294,7 @@ class Mssql extends DboSource { $prepend = 'DISTINCT '; $fields[$i] = trim(str_replace('DISTINCT', '', $fields[$i])); } - $fieldAlias = count($this->__fieldMappings); + $fieldAlias = count($this->_fieldMappings); if (!preg_match('/\s+AS\s+/i', $fields[$i])) { if (substr($fields[$i], -1) == '*') { @@ -311,12 +311,12 @@ class Mssql extends DboSource { } if (strpos($fields[$i], '.') === false) { - $this->__fieldMappings[$alias . '__' . $fieldAlias] = $alias . '.' . $fields[$i]; + $this->_fieldMappings[$alias . '__' . $fieldAlias] = $alias . '.' . $fields[$i]; $fieldName = $this->name($alias . '.' . $fields[$i]); $fieldAlias = $this->name($alias . '__' . $fieldAlias); } else { $build = explode('.', $fields[$i]); - $this->__fieldMappings[$build[0] . '__' . $fieldAlias] = $fields[$i]; + $this->_fieldMappings[$build[0] . '__' . $fieldAlias] = $fields[$i]; $fieldName = $this->name($build[0] . '.' . $build[1]); $fieldAlias = $this->name(preg_replace("/^\[(.+)\]$/", "$1", $build[0]) . '__' . $fieldAlias); } @@ -469,10 +469,10 @@ class Mssql extends DboSource { $column = $results->getColumnMeta($index); if (strpos($column, '__')) { - if (isset($this->__fieldMappings[$column]) && strpos($this->__fieldMappings[$column], '.')) { - $map = explode('.', $this->__fieldMappings[$column]); - } elseif (isset($this->__fieldMappings[$column])) { - $map = array(0, $this->__fieldMappings[$column]); + if (isset($this->_fieldMappings[$column]) && strpos($this->_fieldMappings[$column], '.')) { + $map = explode('.', $this->_fieldMappings[$column]); + } elseif (isset($this->_fieldMappings[$column])) { + $map = array(0, $this->_fieldMappings[$column]); } else { $map = array(0, $column); } @@ -557,10 +557,10 @@ class Mssql extends DboSource { * @access private */ function __mapFields($sql) { - if (empty($sql) || empty($this->__fieldMappings)) { + if (empty($sql) || empty($this->_fieldMappings)) { return $sql; } - foreach ($this->__fieldMappings as $key => $val) { + foreach ($this->_fieldMappings as $key => $val) { $sql = preg_replace('/' . preg_quote($val) . '/', $this->name($key), $sql); $sql = preg_replace('/' . preg_quote($this->name($val)) . '/', $this->name($key), $sql); } @@ -577,7 +577,7 @@ class Mssql extends DboSource { */ function read($model, $queryData = array(), $recursive = null) { $results = parent::read($model, $queryData, $recursive); - $this->__fieldMappings = array(); + $this->_fieldMappings = array(); return $results; } diff --git a/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php b/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php index bc7d852c0..f02242df5 100644 --- a/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php +++ b/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php @@ -119,7 +119,7 @@ class MssqlTestDb extends Mssql { * @return void */ function clearFieldMappings() { - $this->__fieldMappings = array(); + $this->_fieldMappings = array(); } } From 8b78507b3db17333e13501130b12a0a6b02bbb9b Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Fri, 29 Apr 2011 09:14:09 -0400 Subject: [PATCH 13/13] Changed the test setup to not run the test if test db config is not mssql. --- .../Case/Model/Datasource/Database/MssqlTest.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php b/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php index f02242df5..eead8d3c4 100644 --- a/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php +++ b/lib/Cake/tests/Case/Model/Datasource/Database/MssqlTest.php @@ -287,14 +287,6 @@ class MssqlTest extends CakeTestCase { * @access public */ public $fixtures = array('core.category'); -/** - * Skip if cannot connect to mssql - * - */ - public function skip() { - $this->_initDb(); - $this->skipUnless($this->db->config['driver'] == 'mssql', '%s SQL Server connection not available'); - } /** * Make sure all fixtures tables are being created @@ -319,8 +311,11 @@ class MssqlTest extends CakeTestCase { * */ public function setUp() { - $db = ConnectionManager::getDataSource('test'); - $this->db = new MssqlTestDb($db->config); + $this->Dbo = ConnectionManager::getDataSource('test'); + if (!($this->Dbo instanceof Mssql)) { + $this->markTestSkipped('Please configure the test datasource to use SQL Server.'); + } + $this->db = new MssqlTestDb($this->Dbo->config); $this->model = new MssqlTestModel(); }