Skip to content

Commit

Permalink
Removing length() from DboMysqli, fixes incorrect float length parsing.
Browse files Browse the repository at this point in the history
Test case added.
  • Loading branch information
markstory committed Oct 24, 2009
1 parent c6999ae commit 14bd478
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
19 changes: 0 additions & 19 deletions cake/libs/model/datasources/dbo/dbo_mysqli.php
Expand Up @@ -298,25 +298,6 @@ function column($real) {
}
return 'text';
}
/**
* Gets the length of a database-native column description, or null if no length
*
* @param string $real Real database-layer column type (i.e. "varchar(255)")
* @return integer An integer representing the length of the column
*/
function length($real) {
$col = str_replace(array(')', 'unsigned'), '', $real);
$limit = null;

if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col);
}

if ($limit != null) {
return intval($limit);
}
return null;
}
/**
* Enter description here...
*
Expand Down
22 changes: 17 additions & 5 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_mysqli.test.php
Expand Up @@ -154,6 +154,7 @@ function schema() {
* @subpackage cake.tests.cases.libs.model.datasources.dbo
*/
class DboMysqliTest extends CakeTestCase {
var $fixtures = array('core.datatype');
/**
* The Dbo instance to be tested
*
Expand All @@ -176,8 +177,6 @@ function skip() {
* @access public
*/
function setUp() {
$db = ConnectionManager::getDataSource('test_suite');
$this->db = new DboMysqliTestDb($db->config);
$this->model = new MysqliTestModel();
}
/**
Expand All @@ -186,7 +185,8 @@ function setUp() {
* @access public
*/
function tearDown() {
unset($this->db);
unset($this->model);
ClassRegistry::flush();
}
/**
* testIndexDetection method
Expand All @@ -195,7 +195,7 @@ function tearDown() {
* @access public
*/
function testIndexDetection() {
$this->db->cacheSources = $this->db->testing = false;
$this->db->cacheSources = false;

$name = $this->db->fullTableName('simple');
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
Expand Down Expand Up @@ -298,12 +298,14 @@ function testColumn() {
$this->assertEqual($result, $expected);
}
/**
* undocumented function
* test mysqli transactions
*
* @return void
* @access public
*/
function testTransactions() {
$this->db->cacheSources = false;

$this->db->begin($this->model);
$this->assertTrue($this->db->_transactionStarted);

Expand All @@ -313,5 +315,15 @@ function testTransactions() {
$this->db->commit($this->model);
$this->assertFalse($this->db->_transactionStarted);
}
/**
* test that float values are correctly identified
*
* @return void
**/
function testFloatParsing() {
$model =& new Model(array('ds' => 'test_suite', 'table' => 'datatypes', 'name' => 'Datatype'));
$result = $this->db->describe($model);
$this->assertEqual((string)$result['float_field']['length'], '5,2');
}
}
?>

0 comments on commit 14bd478

Please sign in to comment.