Permalink
Browse files

Fix UUID issue in SQLite

Only varchar(36) was interpreted as a uuid.  char(36)
should also be treated this way.  Most documentation refers
to this type.  Also char(x) fields should be treated as strings,
not text.

Fixes #2184
  • Loading branch information...
markstory committed Nov 1, 2011
1 parent 550076d commit f531e7f24b1fbff1d7c8c265eb295e1aa506d888
@@ -250,7 +250,7 @@ public function column($real) {
if (in_array($col, array('text', 'integer', 'float', 'boolean', 'timestamp', 'date', 'datetime', 'time'))) {
return $col;
}
if (strpos($col, 'varchar') !== false) {
if (strpos($col, 'varchar') !== false || strpos($col, 'char') !== false) {

This comment has been minimized.

Show comment
Hide comment
@mdunham

mdunham Nov 3, 2011

Why not just:

if (strpos($col, 'char') !== false) {
@mdunham

mdunham Nov 3, 2011

Why not just:

if (strpos($col, 'char') !== false) {

This comment has been minimized.

Show comment
Hide comment
@markstory

markstory Nov 3, 2011

Member

Fair point.

@markstory

markstory Nov 3, 2011

Member

Fair point.

This comment has been minimized.

Show comment
Hide comment
@markstory

markstory Nov 8, 2011

Member

Fixed in [2c91f11]

@markstory

markstory Nov 8, 2011

Member

Fixed in [2c91f11]

return 'string';
}
if (in_array($col, array('blob', 'clob'))) {
@@ -76,7 +76,7 @@ class SqliteTest extends CakeTestCase {
*
* @var object
*/
public $fixtures = array('core.user');
public $fixtures = array('core.user', 'core.uuid');
/**
* Actual DB connection used in testing
@@ -321,6 +321,20 @@ public function testDescribeWithUuidPrimaryKey() {
);
$this->assertEqual($result['id'], $expected);
$this->Dbo->query('DROP TABLE ' . $tableName);
$tableName = 'uuid_tests';
$this->Dbo->query("CREATE TABLE {$tableName} (id CHAR(36) PRIMARY KEY, name VARCHAR, created DATETIME, modified DATETIME)");
$Model = new Model(array('name' => 'UuidTest', 'ds' => 'test', 'table' => 'uuid_tests'));
$result = $this->Dbo->describe($Model);
$expected = array(
'type' => 'string',
'length' => 36,
'null' => false,
'default' => null,
'key' => 'primary',
);
$this->assertEqual($result['id'], $expected);
$this->Dbo->query('DROP TABLE ' . $tableName);
}
/**
@@ -338,4 +352,27 @@ public function testVirtualFieldWithFunction() {
));
$this->assertEquals('ett', $result['User']['name']);
}
/**
* Test that records can be inserted with uuid primary keys, and
* that the primary key is not blank
*
* @return void
*/
public function testUuidPrimaryKeyInsertion() {
$this->loadFixtures('Uuid');
$Model = ClassRegistry::init('Uuid');
$data = array(
'title' => 'A uuid should work',
'count' => 10
);
$Model->create($data);
$this->assertTrue((bool)$Model->save());
$result = $Model->read();
$this->assertEquals($data['title'], $result['Uuid']['title']);
$this->assertTrue(Validation::uuid($result['Uuid']['id']), 'Not a uuid');
}
}

0 comments on commit f531e7f

Please sign in to comment.