2008-05-30 11:40:08 +00:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
|
* DboMysqlTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*
|
2009-11-06 06:46:59 +00:00
|
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2010-01-26 19:18:20 +00:00
|
|
|
|
* Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*
|
|
|
|
|
* Licensed under The MIT License
|
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
|
|
|
|
*
|
2010-01-26 19:18:20 +00:00
|
|
|
|
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2009-11-06 06:00:11 +00:00
|
|
|
|
* @link http://cakephp.org CakePHP(tm) Project
|
2008-10-30 17:30:26 +00:00
|
|
|
|
* @package cake
|
|
|
|
|
* @subpackage cake.cake.libs
|
|
|
|
|
* @since CakePHP(tm) v 1.2.0
|
2009-11-06 06:51:51 +00:00
|
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*/
|
2008-07-27 03:36:30 +00:00
|
|
|
|
App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboMysql'));
|
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
|
* DboMysqlTestDb class
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
|
* @subpackage cake.tests.cases.libs.model.datasources
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*/
|
|
|
|
|
class DboMysqlTestDb extends DboMysql {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* simulated property
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @var array
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
|
public $simulated = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* testing property
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @var bool true
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
|
public $testing = true;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* execute method
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
|
|
|
|
* @param mixed $sql
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @access protected
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
|
function _execute($sql) {
|
|
|
|
|
if ($this->testing) {
|
|
|
|
|
$this->simulated[] = $sql;
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return parent::_execute($sql);
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* getLastQuery method
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @access public
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
|
function getLastQuery() {
|
|
|
|
|
return $this->simulated[count($this->simulated) - 1];
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
|
* MysqlTestModel class
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
|
* @subpackage cake.tests.cases.libs.model.datasources
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*/
|
|
|
|
|
class MysqlTestModel extends Model {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* name property
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @var string 'MysqlTestModel'
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
|
public $name = 'MysqlTestModel';
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* useTable property
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @var bool false
|
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
|
public $useTable = false;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* find method
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
|
|
|
|
* @param mixed $conditions
|
|
|
|
|
* @param mixed $fields
|
|
|
|
|
* @param mixed $order
|
|
|
|
|
* @param mixed $recursive
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @access public
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
|
function find($conditions = null, $fields = null, $order = null, $recursive = null) {
|
|
|
|
|
return $conditions;
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* findAll method
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
|
|
|
|
* @param mixed $conditions
|
|
|
|
|
* @param mixed $fields
|
|
|
|
|
* @param mixed $order
|
|
|
|
|
* @param mixed $recursive
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @access public
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
|
function findAll($conditions = null, $fields = null, $order = null, $recursive = null) {
|
|
|
|
|
return $conditions;
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* schema method
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
|
* @access public
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
|
function schema() {
|
|
|
|
|
return array(
|
|
|
|
|
'id' => array('type' => 'integer', 'null' => '', 'default' => '', 'length' => '8'),
|
|
|
|
|
'client_id' => array('type' => 'integer', 'null' => '', 'default' => '0', 'length' => '11'),
|
|
|
|
|
'name' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
|
'login' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
|
|
|
|
|
'passwd' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
|
|
|
|
|
'addr_1' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
|
|
|
|
|
'addr_2' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '25'),
|
|
|
|
|
'zip_code' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
|
|
|
|
'city' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
|
|
|
|
'country' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
|
|
|
|
'phone' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
|
|
|
|
'fax' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
|
|
|
|
'url' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '255'),
|
|
|
|
|
'email' => array('type' => 'string', 'null' => '1', 'default' => '', 'length' => '155'),
|
|
|
|
|
'comments' => array('type' => 'text', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
|
|
'last_login'=> array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
|
|
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
|
|
|
|
|
'updated' => array('type' => 'datetime', 'null' => '1', 'default' => '', 'length' => null)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
|
* DboMysqlTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*
|
2009-03-18 17:55:58 +00:00
|
|
|
|
* @package cake
|
2008-10-30 17:30:26 +00:00
|
|
|
|
* @subpackage cake.tests.cases.libs.model.datasources.dbo
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*/
|
|
|
|
|
class DboMysqlTest extends CakeTestCase {
|
2010-10-16 14:53:13 +00:00
|
|
|
|
public $fixtures = array('core.binary_test');
|
|
|
|
|
public $autoFixtures = false;
|
2008-05-30 11:40:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* The Dbo instance to be tested
|
|
|
|
|
*
|
2009-03-17 21:10:28 +00:00
|
|
|
|
* @var DboSource
|
2008-05-30 11:40:08 +00:00
|
|
|
|
* @access public
|
|
|
|
|
*/
|
2010-06-10 01:33:46 +00:00
|
|
|
|
public $Dbo = null;
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets up a Dbo class instance for testing
|
|
|
|
|
*
|
|
|
|
|
*/
|
2010-06-10 01:49:25 +00:00
|
|
|
|
public function setUp() {
|
2010-09-20 02:58:30 +00:00
|
|
|
|
$this->Dbo = ConnectionManager::getDataSource('test');
|
2010-06-10 01:49:25 +00:00
|
|
|
|
if ($this->Dbo->config['driver'] !== 'mysql') {
|
|
|
|
|
$this->markTestSkipped('The MySQL extension is not available.');
|
|
|
|
|
}
|
|
|
|
|
$this->_debug = Configure::read('debug');
|
|
|
|
|
Configure::write('debug', 1);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$this->model = new MysqlTestModel();
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Sets up a Dbo class instance for testing
|
|
|
|
|
*
|
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
|
public function tearDown() {
|
2009-10-24 16:53:22 +00:00
|
|
|
|
unset($this->model);
|
|
|
|
|
ClassRegistry::flush();
|
2008-12-09 04:54:58 +00:00
|
|
|
|
Configure::write('debug', $this->_debug);
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* Test Dbo value method
|
|
|
|
|
*
|
2010-10-15 21:32:37 +00:00
|
|
|
|
* @group quoting
|
2008-05-30 11:40:08 +00:00
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
|
public function testQuoting() {
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->fields($this->model);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$expected = array(
|
|
|
|
|
'`MysqlTestModel`.`id`',
|
|
|
|
|
'`MysqlTestModel`.`client_id`',
|
|
|
|
|
'`MysqlTestModel`.`name`',
|
|
|
|
|
'`MysqlTestModel`.`login`',
|
|
|
|
|
'`MysqlTestModel`.`passwd`',
|
|
|
|
|
'`MysqlTestModel`.`addr_1`',
|
|
|
|
|
'`MysqlTestModel`.`addr_2`',
|
|
|
|
|
'`MysqlTestModel`.`zip_code`',
|
|
|
|
|
'`MysqlTestModel`.`city`',
|
|
|
|
|
'`MysqlTestModel`.`country`',
|
|
|
|
|
'`MysqlTestModel`.`phone`',
|
|
|
|
|
'`MysqlTestModel`.`fax`',
|
|
|
|
|
'`MysqlTestModel`.`url`',
|
|
|
|
|
'`MysqlTestModel`.`email`',
|
|
|
|
|
'`MysqlTestModel`.`comments`',
|
|
|
|
|
'`MysqlTestModel`.`last_login`',
|
|
|
|
|
'`MysqlTestModel`.`created`',
|
|
|
|
|
'`MysqlTestModel`.`updated`'
|
|
|
|
|
);
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
|
|
$expected = 1.2;
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->value(1.2, 'float');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
|
|
|
|
$expected = "'1,2'";
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->value('1,2', 'float');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
|
|
|
|
$expected = "'4713e29446'";
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->value('4713e29446');
|
2008-07-27 02:49:02 +00:00
|
|
|
|
|
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
|
|
|
|
$expected = 'NULL';
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->value('', 'integer');
|
2008-07-27 02:49:02 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
2008-11-05 13:44:05 +00:00
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$expected = 0;
|
|
|
|
|
$result = $this->Dbo->value('', 'boolean');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
|
|
|
|
$expected = 10010001;
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->value(10010001);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
|
|
|
|
$expected = "'00010010001'";
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->value('00010010001');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2010-08-21 04:19:30 +00:00
|
|
|
|
/**
|
|
|
|
|
* test that localized floats don't cause trouble.
|
|
|
|
|
*
|
2010-10-15 21:32:37 +00:00
|
|
|
|
* @group quoting
|
2010-08-21 04:19:30 +00:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
function testLocalizedFloats() {
|
|
|
|
|
$restore = setlocale(LC_ALL, null);
|
|
|
|
|
setlocale(LC_ALL, 'de_DE');
|
|
|
|
|
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$result = $this->Dbo->value(3.141593, 'float');
|
2010-08-21 04:19:30 +00:00
|
|
|
|
$this->assertEqual((string)$result, '3.141593');
|
2010-10-15 23:11:17 +00:00
|
|
|
|
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$result = $this->Dbo->value(3.141593);
|
2010-08-21 04:19:30 +00:00
|
|
|
|
$this->assertEqual((string)$result, '3.141593');
|
|
|
|
|
|
|
|
|
|
setlocale(LC_ALL, $restore);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
|
/**
|
|
|
|
|
* testTinyintCasting method
|
2008-11-05 13:44:05 +00:00
|
|
|
|
*
|
2010-10-15 21:32:37 +00:00
|
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2008-05-30 11:40:08 +00:00
|
|
|
|
function testTinyintCasting() {
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$this->Dbo->cacheSources = false;
|
|
|
|
|
$tableName = 'tinyint_' . uniqid();
|
2010-10-16 18:31:01 +00:00
|
|
|
|
$this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
|
|
$this->model = new CakeTestModel(array(
|
2010-09-20 02:58:30 +00:00
|
|
|
|
'name' => 'Tinyint', 'table' => $tableName, 'ds' => 'test'
|
2008-05-30 11:40:08 +00:00
|
|
|
|
));
|
2008-08-27 08:01:00 +00:00
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$result = $this->model->schema();
|
|
|
|
|
$this->assertEqual($result['bool']['type'], 'boolean');
|
|
|
|
|
$this->assertEqual($result['small_int']['type'], 'integer');
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$this->assertTrue((bool)$this->model->save(array('bool' => 5, 'small_int' => 5)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$result = $this->model->find('first');
|
|
|
|
|
$this->assertIdentical($result['Tinyint']['bool'], '1');
|
|
|
|
|
$this->assertIdentical($result['Tinyint']['small_int'], '5');
|
|
|
|
|
$this->model->deleteAll(true);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$this->assertTrue((bool)$this->model->save(array('bool' => 0, 'small_int' => 100)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$result = $this->model->find('first');
|
|
|
|
|
$this->assertIdentical($result['Tinyint']['bool'], '0');
|
|
|
|
|
$this->assertIdentical($result['Tinyint']['small_int'], '100');
|
|
|
|
|
$this->model->deleteAll(true);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$this->assertTrue((bool)$this->model->save(array('bool' => true, 'small_int' => 0)));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
$result = $this->model->find('first');
|
|
|
|
|
$this->assertIdentical($result['Tinyint']['bool'], '1');
|
|
|
|
|
$this->assertIdentical($result['Tinyint']['small_int'], '0');
|
|
|
|
|
$this->model->deleteAll(true);
|
|
|
|
|
|
2010-10-16 18:31:01 +00:00
|
|
|
|
$this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-11-05 13:44:05 +00:00
|
|
|
|
/**
|
|
|
|
|
* testIndexDetection method
|
|
|
|
|
*
|
2010-10-15 21:57:36 +00:00
|
|
|
|
* @group indices
|
2008-11-05 13:44:05 +00:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
|
public function testIndexDetection() {
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$this->Dbo->cacheSources = false;
|
2008-11-05 13:44:05 +00:00
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$name = $this->Dbo->fullTableName('simple');
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1));
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->index('simple', false);
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('DROP TABLE ' . $name);
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
2010-10-15 23:11:17 +00:00
|
|
|
|
|
2008-11-05 13:44:05 +00:00
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$name = $this->Dbo->fullTableName('with_a_key');
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ));');
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$expected = array(
|
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
|
|
|
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
|
|
|
|
);
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->index('with_a_key', false);
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('DROP TABLE ' . $name);
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$name = $this->Dbo->fullTableName('with_two_keys');
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ));');
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$expected = array(
|
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
|
|
|
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
|
|
|
|
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
|
|
|
|
);
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->index('with_two_keys', false);
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('DROP TABLE ' . $name);
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$name = $this->Dbo->fullTableName('with_compound_keys');
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ));');
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$expected = array(
|
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
|
|
|
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
|
|
|
|
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
|
|
|
|
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
|
|
|
|
|
);
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->index('with_compound_keys', false);
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('DROP TABLE ' . $name);
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$name = $this->Dbo->fullTableName('with_multiple_compound_keys');
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ), KEY `other_way` ( `small_int`, `bool` ));');
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$expected = array(
|
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
|
|
|
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
|
|
|
|
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
|
|
|
|
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
|
|
|
|
|
'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0),
|
|
|
|
|
);
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->index('with_multiple_compound_keys', false);
|
2010-10-15 21:32:37 +00:00
|
|
|
|
$this->Dbo->rawQuery('DROP TABLE ' . $name);
|
2008-11-05 13:44:05 +00:00
|
|
|
|
$this->assertEqual($expected, $result);
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2009-09-29 15:25:42 +00:00
|
|
|
|
/**
|
|
|
|
|
* testBuildColumn method
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
function testBuildColumn() {
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$restore = $this->Dbo->columns;
|
|
|
|
|
$this->Dbo->columns = array('varchar(255)' => 1);
|
2009-09-29 15:25:42 +00:00
|
|
|
|
$data = array(
|
|
|
|
|
'name' => 'testName',
|
|
|
|
|
'type' => 'varchar(255)',
|
|
|
|
|
'default',
|
|
|
|
|
'null' => true,
|
|
|
|
|
'key',
|
|
|
|
|
'comment' => 'test'
|
|
|
|
|
);
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->buildColumn($data);
|
2009-09-29 15:25:42 +00:00
|
|
|
|
$expected = '`testName` DEFAULT NULL COMMENT \'test\'';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
|
'name' => 'testName',
|
|
|
|
|
'type' => 'varchar(255)',
|
|
|
|
|
'default',
|
|
|
|
|
'null' => true,
|
|
|
|
|
'key',
|
|
|
|
|
'charset' => 'utf8',
|
|
|
|
|
'collate' => 'utf8_unicode_ci'
|
|
|
|
|
);
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->buildColumn($data);
|
2009-09-29 15:25:42 +00:00
|
|
|
|
$expected = '`testName` CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$this->Dbo->columns = $restore;
|
2009-09-29 15:25:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-08 23:09:08 +00:00
|
|
|
|
/**
|
|
|
|
|
* MySQL 4.x returns index data in a different format,
|
|
|
|
|
* Using a mock ensure that MySQL 4.x output is properly parsed.
|
|
|
|
|
*
|
2010-10-15 21:57:36 +00:00
|
|
|
|
* @group indices
|
2009-02-08 23:09:08 +00:00
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
|
*/
|
2009-02-08 23:09:08 +00:00
|
|
|
|
function testIndexOnMySQL4Output() {
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$name = $this->Dbo->fullTableName('simple');
|
2009-02-08 23:09:08 +00:00
|
|
|
|
|
2010-10-15 21:57:36 +00:00
|
|
|
|
$mockDbo = $this->getMock('DboMysql', array('connect', '_execute', 'getVersion'));
|
2009-03-17 21:10:28 +00:00
|
|
|
|
$columnData = array(
|
2009-02-08 23:09:08 +00:00
|
|
|
|
array('0' => array(
|
2009-03-17 21:10:28 +00:00
|
|
|
|
'Table' => 'with_compound_keys',
|
|
|
|
|
'Non_unique' => '0',
|
|
|
|
|
'Key_name' => 'PRIMARY',
|
|
|
|
|
'Seq_in_index' => '1',
|
|
|
|
|
'Column_name' => 'id',
|
|
|
|
|
'Collation' => 'A',
|
|
|
|
|
'Cardinality' => '0',
|
|
|
|
|
'Sub_part' => NULL,
|
|
|
|
|
'Packed' => NULL,
|
|
|
|
|
'Null' => '',
|
|
|
|
|
'Index_type' => 'BTREE',
|
2009-02-08 23:09:08 +00:00
|
|
|
|
'Comment' => ''
|
2009-03-17 21:10:28 +00:00
|
|
|
|
)),
|
2009-02-08 23:09:08 +00:00
|
|
|
|
array('0' => array(
|
2009-03-17 21:10:28 +00:00
|
|
|
|
'Table' => 'with_compound_keys',
|
|
|
|
|
'Non_unique' => '1',
|
|
|
|
|
'Key_name' => 'pointless_bool',
|
|
|
|
|
'Seq_in_index' => '1',
|
|
|
|
|
'Column_name' => 'bool',
|
|
|
|
|
'Collation' => 'A',
|
|
|
|
|
'Cardinality' => NULL,
|
|
|
|
|
'Sub_part' => NULL,
|
|
|
|
|
'Packed' => NULL,
|
|
|
|
|
'Null' => 'YES',
|
|
|
|
|
'Index_type' => 'BTREE',
|
2009-02-08 23:09:08 +00:00
|
|
|
|
'Comment' => ''
|
|
|
|
|
)),
|
|
|
|
|
array('0' => array(
|
2009-03-17 21:10:28 +00:00
|
|
|
|
'Table' => 'with_compound_keys',
|
|
|
|
|
'Non_unique' => '1',
|
|
|
|
|
'Key_name' => 'pointless_small_int',
|
|
|
|
|
'Seq_in_index' => '1',
|
|
|
|
|
'Column_name' => 'small_int',
|
|
|
|
|
'Collation' => 'A',
|
|
|
|
|
'Cardinality' => NULL,
|
|
|
|
|
'Sub_part' => NULL,
|
|
|
|
|
'Packed' => NULL,
|
|
|
|
|
'Null' => 'YES',
|
|
|
|
|
'Index_type' => 'BTREE',
|
2009-02-08 23:09:08 +00:00
|
|
|
|
'Comment' => ''
|
2009-03-17 21:10:28 +00:00
|
|
|
|
)),
|
2009-02-08 23:09:08 +00:00
|
|
|
|
array('0' => array(
|
2009-03-17 21:10:28 +00:00
|
|
|
|
'Table' => 'with_compound_keys',
|
|
|
|
|
'Non_unique' => '1',
|
|
|
|
|
'Key_name' => 'one_way',
|
|
|
|
|
'Seq_in_index' => '1',
|
|
|
|
|
'Column_name' => 'bool',
|
|
|
|
|
'Collation' => 'A',
|
|
|
|
|
'Cardinality' => NULL,
|
|
|
|
|
'Sub_part' => NULL,
|
|
|
|
|
'Packed' => NULL,
|
|
|
|
|
'Null' => 'YES',
|
|
|
|
|
'Index_type' => 'BTREE',
|
2009-02-08 23:09:08 +00:00
|
|
|
|
'Comment' => ''
|
2009-03-17 21:10:28 +00:00
|
|
|
|
)),
|
2009-02-08 23:09:08 +00:00
|
|
|
|
array('0' => array(
|
2009-03-17 21:10:28 +00:00
|
|
|
|
'Table' => 'with_compound_keys',
|
|
|
|
|
'Non_unique' => '1',
|
|
|
|
|
'Key_name' => 'one_way',
|
|
|
|
|
'Seq_in_index' => '2',
|
|
|
|
|
'Column_name' => 'small_int',
|
|
|
|
|
'Collation' => 'A',
|
|
|
|
|
'Cardinality' => NULL,
|
|
|
|
|
'Sub_part' => NULL,
|
|
|
|
|
'Packed' => NULL,
|
|
|
|
|
'Null' => 'YES',
|
|
|
|
|
'Index_type' => 'BTREE',
|
|
|
|
|
'Comment' => ''
|
2009-02-08 23:09:08 +00:00
|
|
|
|
))
|
|
|
|
|
);
|
2010-10-15 21:57:36 +00:00
|
|
|
|
|
|
|
|
|
$mockDbo->expects($this->once())->method('getVersion')->will($this->returnValue('4.1'));
|
|
|
|
|
$resultMock = $this->getMock('PDOStatement', array('fetch'));
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$mockDbo->expects($this->once())
|
2010-10-15 21:57:36 +00:00
|
|
|
|
->method('_execute')
|
2010-06-10 01:33:46 +00:00
|
|
|
|
->with('SHOW INDEX FROM ' . $name)
|
2010-10-15 21:57:36 +00:00
|
|
|
|
->will($this->returnValue($resultMock));
|
2010-10-15 23:11:17 +00:00
|
|
|
|
|
2010-10-15 21:57:36 +00:00
|
|
|
|
foreach ($columnData as $i => $data) {
|
|
|
|
|
$resultMock->expects($this->at($i))->method('fetch')->will($this->returnValue((object) $data));
|
|
|
|
|
}
|
2009-02-08 23:09:08 +00:00
|
|
|
|
|
|
|
|
|
$result = $mockDbo->index($name, false);
|
|
|
|
|
$expected = array(
|
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
|
|
|
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
|
|
|
|
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
|
|
|
|
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
|
|
|
|
|
);
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-11-06 02:15:12 +00:00
|
|
|
|
/**
|
|
|
|
|
* testColumn method
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2010-04-05 03:19:38 +00:00
|
|
|
|
public function testColumn() {
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('varchar(50)');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'string';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('text');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'text';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('int(11)');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'integer';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('int(11) unsigned');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'integer';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('tinyint(1)');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'boolean';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('boolean');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'boolean';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('float');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'float';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('float unsigned');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'float';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('double unsigned');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'float';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$result = $this->Dbo->column('decimal(14,7) unsigned');
|
2008-11-06 02:15:12 +00:00
|
|
|
|
$expected = 'float';
|
|
|
|
|
$this->assertEqual($result, $expected);
|
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
|
2008-12-09 04:54:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* testAlterSchemaIndexes method
|
2009-03-17 21:10:28 +00:00
|
|
|
|
*
|
2010-10-15 21:57:36 +00:00
|
|
|
|
* @group indices
|
2008-12-09 04:54:58 +00:00
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
function testAlterSchemaIndexes() {
|
2009-10-05 01:48:20 +00:00
|
|
|
|
App::import('Model', 'CakeSchema');
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$this->Dbo->cacheSources = $this->Dbo->testing = false;
|
2008-12-09 04:54:58 +00:00
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$schema1 = new CakeSchema(array(
|
2008-12-09 04:54:58 +00:00
|
|
|
|
'name' => 'AlterTest1',
|
2010-09-20 02:58:30 +00:00
|
|
|
|
'connection' => 'test',
|
2008-12-09 04:54:58 +00:00
|
|
|
|
'altertest' => array(
|
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
|
|
|
|
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
|
|
|
|
|
'group1' => array('type' => 'integer', 'null' => true),
|
|
|
|
|
'group2' => array('type' => 'integer', 'null' => true)
|
|
|
|
|
)));
|
2010-10-15 23:11:17 +00:00
|
|
|
|
$result = $this->Dbo->createSchema($schema1);
|
|
|
|
|
$this->assertContains('`id` int(11) DEFAULT 0 NOT NULL,', $result);
|
|
|
|
|
$this->assertContains('`name` varchar(50) NOT NULL,', $result);
|
|
|
|
|
$this->assertContains('`group1` int(11) DEFAULT NULL', $result);
|
|
|
|
|
$this->assertContains('`group2` int(11) DEFAULT NULL', $result);
|
|
|
|
|
|
|
|
|
|
//Test that the string is syntactically correct
|
|
|
|
|
$query = $this->Dbo->getConnection()->prepare($result);
|
|
|
|
|
$this->assertEquals($result, $query->queryString);
|
2008-12-09 04:54:58 +00:00
|
|
|
|
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$schema2 = new CakeSchema(array(
|
2008-12-09 04:54:58 +00:00
|
|
|
|
'name' => 'AlterTest2',
|
2010-09-20 02:58:30 +00:00
|
|
|
|
'connection' => 'test',
|
2008-12-09 04:54:58 +00:00
|
|
|
|
'altertest' => array(
|
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
|
|
|
|
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
|
|
|
|
|
'group1' => array('type' => 'integer', 'null' => true),
|
|
|
|
|
'group2' => array('type' => 'integer', 'null' => true),
|
|
|
|
|
'indexes' => array(
|
|
|
|
|
'name_idx' => array('column' => 'name', 'unique' => 0),
|
|
|
|
|
'group_idx' => array('column' => 'group1', 'unique' => 0),
|
|
|
|
|
'compound_idx' => array('column' => array('group1', 'group2'), 'unique' => 0),
|
|
|
|
|
'PRIMARY' => array('column' => 'id', 'unique' => 1))
|
|
|
|
|
)));
|
2009-03-17 21:10:28 +00:00
|
|
|
|
|
2010-10-15 23:11:17 +00:00
|
|
|
|
$result = $this->Dbo->alterSchema($schema2->compare($schema1));
|
|
|
|
|
$this->assertContains('ALTER TABLE `altertest`', $result);
|
|
|
|
|
$this->assertContains('ADD KEY name_idx (`name`),', $result);
|
|
|
|
|
$this->assertContains('ADD KEY group_idx (`group1`),', $result);
|
|
|
|
|
$this->assertContains('ADD KEY compound_idx (`group1`, `group2`),', $result);
|
|
|
|
|
$this->assertContains('ADD PRIMARY KEY (`id`);', $result);
|
|
|
|
|
|
|
|
|
|
//Test that the string is syntactically correct
|
|
|
|
|
$query = $this->Dbo->getConnection()->prepare($result);
|
|
|
|
|
$this->assertEquals($result, $query->queryString);
|
2009-03-17 21:10:28 +00:00
|
|
|
|
|
2008-12-09 04:54:58 +00:00
|
|
|
|
// Change three indexes, delete one and add another one
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$schema3 = new CakeSchema(array(
|
2008-12-09 04:54:58 +00:00
|
|
|
|
'name' => 'AlterTest3',
|
2010-09-20 02:58:30 +00:00
|
|
|
|
'connection' => 'test',
|
2008-12-09 04:54:58 +00:00
|
|
|
|
'altertest' => array(
|
|
|
|
|
'id' => array('type' => 'integer', 'null' => false, 'default' => 0),
|
|
|
|
|
'name' => array('type' => 'string', 'null' => false, 'length' => 50),
|
|
|
|
|
'group1' => array('type' => 'integer', 'null' => true),
|
|
|
|
|
'group2' => array('type' => 'integer', 'null' => true),
|
|
|
|
|
'indexes' => array(
|
2009-03-17 21:10:28 +00:00
|
|
|
|
'name_idx' => array('column' => 'name', 'unique' => 1),
|
2008-12-09 04:54:58 +00:00
|
|
|
|
'group_idx' => array('column' => 'group2', 'unique' => 0),
|
|
|
|
|
'compound_idx' => array('column' => array('group2', 'group1'), 'unique' => 0),
|
|
|
|
|
'id_name_idx' => array('column' => array('id', 'name'), 'unique' => 0))
|
|
|
|
|
)));
|
|
|
|
|
|
2010-10-15 23:11:17 +00:00
|
|
|
|
$result = $this->Dbo->alterSchema($schema3->compare($schema2));
|
|
|
|
|
$this->assertContains('ALTER TABLE `altertest`', $result);
|
|
|
|
|
$this->assertContains('DROP PRIMARY KEY,', $result);
|
|
|
|
|
$this->assertContains('DROP KEY name_idx,', $result);
|
|
|
|
|
$this->assertContains('DROP KEY group_idx,', $result);
|
|
|
|
|
$this->assertContains('DROP KEY compound_idx,', $result);
|
|
|
|
|
$this->assertContains('ADD KEY id_name_idx (`id`, `name`),', $result);
|
|
|
|
|
$this->assertContains('ADD UNIQUE KEY name_idx (`name`),', $result);
|
|
|
|
|
$this->assertContains('ADD KEY group_idx (`group2`),', $result);
|
|
|
|
|
$this->assertContains('ADD KEY compound_idx (`group2`, `group1`);', $result);
|
2008-12-09 04:54:58 +00:00
|
|
|
|
|
2010-10-15 23:11:17 +00:00
|
|
|
|
$query = $this->Dbo->getConnection()->prepare($result);
|
|
|
|
|
$this->assertEquals($result, $query->queryString);
|
2008-12-09 04:54:58 +00:00
|
|
|
|
|
|
|
|
|
// Compare us to ourself.
|
|
|
|
|
$this->assertEqual($schema3->compare($schema3), array());
|
|
|
|
|
|
|
|
|
|
// Drop the indexes
|
2010-10-15 23:11:17 +00:00
|
|
|
|
$result = $this->Dbo->alterSchema($schema1->compare($schema3));
|
2008-12-09 04:54:58 +00:00
|
|
|
|
|
2010-10-15 23:11:17 +00:00
|
|
|
|
$this->assertContains('ALTER TABLE `altertest`', $result);
|
|
|
|
|
$this->assertContains('DROP KEY name_idx,', $result);
|
|
|
|
|
$this->assertContains('DROP KEY group_idx,', $result);
|
|
|
|
|
$this->assertContains('DROP KEY compound_idx,', $result);
|
|
|
|
|
$this->assertContains('DROP KEY id_name_idx;', $result);
|
2008-12-09 04:54:58 +00:00
|
|
|
|
|
2010-10-15 23:11:17 +00:00
|
|
|
|
$query = $this->Dbo->getConnection()->prepare($result);
|
|
|
|
|
$this->assertEquals($result, $query->queryString);
|
2009-10-05 01:48:20 +00:00
|
|
|
|
}
|
2010-10-15 23:11:17 +00:00
|
|
|
|
|
2009-10-24 16:53:22 +00:00
|
|
|
|
/**
|
|
|
|
|
* test saving and retrieval of blobs
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
2009-11-14 12:19:25 +00:00
|
|
|
|
*/
|
2009-10-24 16:53:22 +00:00
|
|
|
|
function testBlobSaving() {
|
2010-10-16 14:53:13 +00:00
|
|
|
|
$this->loadFixtures('BinaryTest');
|
2010-06-10 01:33:46 +00:00
|
|
|
|
$this->Dbo->cacheSources = false;
|
2009-10-24 16:53:22 +00:00
|
|
|
|
$data = "GIF87ab |