Skip to content

Commit

Permalink
Implementing DboMysql::getVersion()
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Oct 15, 2010
1 parent b847945 commit 09e06d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cake/libs/model/datasources/dbo/dbo_mysql.php
Expand Up @@ -796,8 +796,17 @@ function fetchResult() {
*
* @return string The database encoding
*/
function getEncoding() {
return mysql_client_encoding($this->connection);
public function getEncoding() {
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;
}

/**
Expand Down
22 changes: 22 additions & 0 deletions cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php
Expand Up @@ -862,4 +862,26 @@ public function testListSources() {
$tables = $db->listSources();
$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);
}
}

0 comments on commit 09e06d5

Please sign in to comment.