Implementing DboMysql::getVersion()

This commit is contained in:
José Lorenzo Rodríguez 2010-10-14 23:15:17 -04:30
parent b8479459d6
commit 09e06d52b9
2 changed files with 33 additions and 2 deletions

View file

@ -796,8 +796,17 @@ class DboMysql extends DboMysqlBase {
* *
* @return string The database encoding * @return string The database encoding
*/ */
function getEncoding() { public function getEncoding() {
return mysql_client_encoding($this->connection); return $this->_execute('SHOW VARIABLES LIKE ?', array('character_set_client'))->fetchObject()->Value;
}
/**
* Gets the version string of the database server
*
* @return string The database encoding
*/
public function getVersion() {
return $this->_execute('SELECT VERSION() as mysql_version')->fetchObject()->mysql_version;
} }
/** /**

View file

@ -862,4 +862,26 @@ class DboMysqlTest extends CakeTestCase {
$tables = $db->listSources(); $tables = $db->listSources();
$this->assertEqual($tables, array('cake_table', 'another_table')); $this->assertEqual($tables, array('cake_table', 'another_table'));
} }
/**
* Tests that getVersion method sends the correct query for getting the mysql version
* @return void
*/
public function testGetVersion() {
$db = $this->getMock('DboMysql', array('connect', '_execute'));
$queryResult = $this->getMock('PDOStatement');
$db->expects($this->once())
->method('_execute')
->with('SELECT VERSION() as mysql_version')
->will($this->returnValue($queryResult));
$result = new StdClass;
$result->mysql_version = '5.1';
$queryResult->expects($this->once())
->method('fetchObject')
->will($this->returnValue($result));
$version = $db->getVersion();
$this->assertEqual('5.1', $version);
}
} }