Permalink
Browse files

Adding support for Unicode characters. Refs #1321

  • Loading branch information...
1 parent 623466d commit 9ab2ec7d49edae596f44c1ac8b85cd8d60b625f5 @markstory markstory committed Jun 23, 2011
View
24 lib/Cake/Model/Datasource/Database/Sqlserver.php
@@ -549,6 +549,30 @@ public function renderStatement($type, $data) {
}
/**
+ * 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
12 lib/Cake/Test/Case/Model/Datasource/Database/SqlserverTest.php
@@ -491,7 +491,7 @@ public function testBuildColumn() {
$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 @@ public function testBuildColumn() {
$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 @@ public function testInsertMulti() {
$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 @@ public function testInsertMulti() {
$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);
}

0 comments on commit 9ab2ec7

Please sign in to comment.