Adding support for Unicode characters. Refs #1321

This commit is contained in:
Mark Story 2011-06-23 15:46:03 -07:00
parent 623466dcf8
commit 9ab2ec7d49
2 changed files with 30 additions and 6 deletions

View file

@ -548,6 +548,30 @@ class Sqlserver extends DboSource {
}
}
/**
* 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
* @return string Quoted and escaped data
*/
public function value($data, $column = null) {
if (is_array($data) || is_object($data)) {
return parent::value($data, $column);
}
if (empty($column)) {
$column = $this->introspectType($data);
}
switch ($column) {
case 'string':
case 'text':
return 'N' . $this->_connection->quote($data, PDO::PARAM_STR);
default:
return parent::value($data, $column);
}
}
/**
* Returns an array of all result rows for a given SQL query.
* Returns false if no rows matched.

View file

@ -491,7 +491,7 @@ class SqlserverTest extends CakeTestCase {
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'default' => '', 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] varchar(255) DEFAULT \'\' NOT NULL';
$expected = '[name] varchar(255) DEFAULT N\'\' NOT NULL';
$this->assertEqual($expected, $result);
$column = array('name' => 'name', 'type' => 'string', 'null' => false, 'length' => '255');
@ -511,7 +511,7 @@ class SqlserverTest extends CakeTestCase {
$column = array('name' => 'name', 'type' => 'string', 'null' => true, 'default' => '', 'length' => '255');
$result = $this->db->buildColumn($column);
$expected = '[name] varchar(255) DEFAULT \'\'';
$expected = '[name] varchar(255) DEFAULT N\'\'';
$this->assertEqual($expected, $result);
}
/**
@ -591,8 +591,8 @@ class SqlserverTest extends CakeTestCase {
$result = $this->db->simulated;
$expected = array(
'SET IDENTITY_INSERT [sqlserver_test_models] ON',
"INSERT INTO [sqlserver_test_models] ([id], [name], [login]) VALUES (1, 'Larry', 'PhpNut')",
"INSERT INTO [sqlserver_test_models] ([id], [name], [login]) VALUES (2, 'Renan', 'renan.saddam')",
"INSERT INTO [sqlserver_test_models] ([id], [name], [login]) VALUES (1, N'Larry', N'PhpNut')",
"INSERT INTO [sqlserver_test_models] ([id], [name], [login]) VALUES (2, N'Renan', N'renan.saddam')",
'SET IDENTITY_INSERT [sqlserver_test_models] OFF'
);
$this->assertEqual($expected, $result);
@ -605,8 +605,8 @@ class SqlserverTest extends CakeTestCase {
$this->db->insertMulti($this->model, $fields, $values);
$result = $this->db->simulated;
$expected = array(
"INSERT INTO [sqlserver_test_models] ([name], [login]) VALUES ('Larry', 'PhpNut')",
"INSERT INTO [sqlserver_test_models] ([name], [login]) VALUES ('Renan', 'renan.saddam')",
"INSERT INTO [sqlserver_test_models] ([name], [login]) VALUES (N'Larry', N'PhpNut')",
"INSERT INTO [sqlserver_test_models] ([name], [login]) VALUES (N'Renan', N'renan.saddam')",
);
$this->assertEqual($expected, $result);
}