updating DboMysql, fixes #3269, fixes #3192, fixes #3266, adding tests for DboMysql, DboPostgres, DboMssql

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5701 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-09-30 18:13:46 +00:00
parent 4f8f7a7045
commit 66bfa5631a
4 changed files with 290 additions and 15 deletions

View file

@ -223,7 +223,7 @@ class DboMysql extends DboSource {
case 'integer' :
case 'float' :
case null :
if (is_numeric($data)) {
if (is_numeric($data) && strpos($data, ',') === false) {
break;
}
default:
@ -517,13 +517,8 @@ class DboMysql extends DboSource {
}
}
if (empty($index) && empty($primary)) {
$primary = 'id';
$col = array('type'=>'integer', 'key' => 'primary');
array_unshift($cols, $this->buildColumn($col));
}
if(empty($index) && !empty($primary)) {
$col = array('PRIMARY'=> array('column'=> $primary, 'unique' => 1));
$col = array('PRIMARY' => array('column'=> $primary, 'unique' => 1));
$index[] = $this->buildIndex($col);
}
$out .= "\t" . join(",\n\t", $cols) . ",\n\t". join(",\n\t", $index) . "\n);\n\n";
@ -566,7 +561,9 @@ class DboMysql extends DboSource {
break;
case 'change':
foreach($column as $field => $col) {
$col['name'] = $field;
if(!isset($col['name'])) {
$col['name'] = $field;
}
$colList[] = 'CHANGE '. $this->name($field).' '.$this->buildColumn($col);
}
break;
@ -660,18 +657,19 @@ class DboMysql extends DboSource {
function buildIndex($indexes) {
$join = array();
foreach ($indexes as $name => $value) {
$out = null;
$out = '';
if ($name == 'PRIMARY') {
$out .= 'PRIMARY KEY (' . $this->name($value['column']) . ')';
$out .= 'PRIMARY ';
$name = null;
} else {
if (!empty($value['unique'])) {
$out .= 'UNIQUE ';
}
if (is_array($value['column'])) {
$out .= 'KEY '. $name .' (' . join(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
} else {
$out .= 'KEY '. $name .' (' . $this->name($value['column']) . ')';
}
}
if (is_array($value['column'])) {
$out .= 'KEY '. $name .' (' . join(', ', array_map(array(&$this, 'name'), $value['column'])) . ')';
} else {
$out .= 'KEY '. $name .' (' . $this->name($value['column']) . ')';
}
$join[] = $out;
}

View file

@ -0,0 +1,92 @@
<?php
/* SVN FILE: $Id$ */
/**
* DboMssql test
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP(tm) v 1.2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
uses('model' . DS . 'datasources' . DS . 'dbo_source',
'model' . DS . 'datasources' . DS . 'dbo' . DS . 'dbo_mssql');
/**
* The test class for the DboMssql
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model.datasources.dbo
*/
class DboMssqlTest extends UnitTestCase {
/**
* The Dbo instance to be tested
*
* @var object
* @access public
*/
var $Db = null;
/**
* Skip if cannot connect to mysql
*
* @return void
* @access public
*/
function skip() {
$skip = true;
if(function_exists('mssql_connect')) {
$skip = false;
}
$this->skipif ($skip, 'Mssql not installed');
}
/**
* Sets up a Dbo class instance for testing
*
* @return void
* @access public
*/
function setUp() {
$this->Db =& new DboMssql(array());
$this->Db->fullDebug = 0;
}
/**
* Sets up a Dbo class instance for testing
*
* @return void
* @access public
*/
function tearDown() {
unset($this->Db);
}
/**
* Test Dbo value method
*
* @return void
* @access public
*/
function testValue() {
$expected = 1.2;
$result = $this->Db->value(1.2, 'float');
$this->assertIdentical($expected, $result);
$expected = "'1,2'";
$result = $this->Db->value('1,2', 'float');
$this->assertIdentical($expected, $result);
}
}
?>

View file

@ -0,0 +1,93 @@
<?php
/* SVN FILE: $Id$ */
/**
* DboMysql test
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP(tm) v 1.2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
uses('model' . DS . 'datasources' . DS . 'dbo_source',
'model' . DS . 'datasources' . DS . 'dbo' . DS . 'dbo_mysql');
/**
* The test class for the DboMysql
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model.datasources.dbo
*/
class DboMysqlTest extends UnitTestCase {
/**
* The Dbo instance to be tested
*
* @var object
* @access public
*/
var $Db = null;
/**
* Skip if cannot connect to mysql
*
* @return void
* @access public
*/
function skip() {
$skip = true;
if(function_exists('mysql_connect')) {
$skip = false;
}
$this->skipif ($skip, 'Mysql not installed');
}
/**
* Sets up a Dbo class instance for testing
*
* @return void
* @access public
*/
function setUp() {
$this->Db =& new DboMysql(array());
$this->Db->fullDebug = 0;
}
/**
* Sets up a Dbo class instance for testing
*
* @return void
* @access public
*/
function tearDown() {
unset($this->Db);
}
/**
* Test Dbo value method
*
* @return void
* @access public
*/
function testValue() {
$expected = 1.2;
$result = $this->Db->value(1.2, 'float');
$this->assertIdentical($expected, $result);
$expected = "'1,2'";
$result = $this->Db->value('1,2', 'float');
$this->assertIdentical($expected, $result);
}
}
?>

View file

@ -0,0 +1,92 @@
<?php
/* SVN FILE: $Id$ */
/**
* DboPostgres test
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework <http://www.cakephp.org/>
* Copyright 2005-2007, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2007, Cake Software Foundation, Inc.
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP(tm) v 1.2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
uses('model' . DS . 'datasources' . DS . 'dbo_source',
'model' . DS . 'datasources' . DS . 'dbo' . DS . 'dbo_postgres');
/**
* The test class for the DboPostgres
*
* @package cake.tests
* @subpackage cake.tests.cases.libs.model.datasources.dbo
*/
class DboPostgresTest extends UnitTestCase {
/**
* The Dbo instance to be tested
*
* @var object
* @access public
*/
var $Db = null;
/**
* Skip if cannot connect to mysql
*
* @return void
* @access public
*/
function skip() {
$skip = true;
if(function_exists('pg_connect')) {
$skip = false;
}
$this->skipif ($skip, 'Postgres not installed');
}
/**
* Sets up a Dbo class instance for testing
*
* @return void
* @access public
*/
function setUp() {
$this->Db =& new DboPostgres(array());
$this->Db->fullDebug = 0;
}
/**
* Sets up a Dbo class instance for testing
*
* @return void
* @access public
*/
function tearDown() {
unset($this->Db);
}
/**
* Test Dbo value method
*
* @return void
* @access public
*/
function testValue() {
$expected = 1.2;
$result = $this->Db->value(1.2, 'float');
$this->assertIdentical($expected, $result);
$expected = "'1,2'";
$result = $this->Db->value('1,2', 'float');
$this->assertIdentical($expected, $result);
}
}
?>