Skip to content
Permalink
Browse files

Fixes SQLServer throwing a 'string not uuid' type error if a query is…

… done with a empty value to a uuid field.
  • Loading branch information...
Walther Lalk
Walther Lalk committed Sep 12, 2014
1 parent ab24722 commit f60d099d77cac4f3dc4367edcfa456cb69117ce0
Showing with 20 additions and 1 deletion.
  1. +1 −1 src/Database/Type/UuidType.php
  2. +19 −0 tests/TestCase/ORM/TableUuidTest.php
@@ -45,7 +45,7 @@ public function toStatement($value, Driver $driver) {
* @return mixed
*/
public function toDatabase($value, Driver $driver) {
if ($value === null) {
if ($value === null || $value === '') {
return null;
}
return strval($value);
@@ -114,4 +114,23 @@ public function testDelete() {
$this->assertCount(0, $query->execute(), 'No rows left');
}
/**
* Tests that sql server does not error when an empty uuid is bound
*
* @return void
*/
public function testEmptyUuid() {
$this->skipIf(
!$this->connection->driver() instanceof \Cake\Database\Driver\Sqlserver,
'Empty UUIDs only affect SQLServer uniqueidentifier field types'
);
$id = '';
$table = TableRegistry::get('uuiditems');
$entity = $table->find('all')
->where(['id' => $id])
->first();
$this->assertNull($entity);
}
}

0 comments on commit f60d099

Please sign in to comment.
You can’t perform that action at this time.