From 09e06d52b9b6cef4402d23f17b99bf3ec4b2f9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Lorenzo=20Rodr=C3=ADguez?= Date: Thu, 14 Oct 2010 23:15:17 -0430 Subject: [PATCH] Implementing DboMysql::getVersion() --- cake/libs/model/datasources/dbo/dbo_mysql.php | 13 +++++++++-- .../model/datasources/dbo/dbo_mysql.test.php | 22 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 671c32659..6f7ca6e55 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -796,8 +796,17 @@ class DboMysql extends DboMysqlBase { * * @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; } /** diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index 11d81938c..cf4ebf6df 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -862,4 +862,26 @@ class DboMysqlTest extends CakeTestCase { $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); + } }