diff --git a/libraries/dbi/drizzle-wrappers.lib.php b/libraries/dbi/drizzle-wrappers.lib.php index 3f58043849..430a78d97f 100644 --- a/libraries/dbi/drizzle-wrappers.lib.php +++ b/libraries/dbi/drizzle-wrappers.lib.php @@ -15,67 +15,19 @@ if (! defined('PHPMYADMIN')) { exit; } -// TODO: drizzle module segfaults while freeing resources, often. -// This allows at least for some development -function _drizzle_shutdown_flush() +/** + * Workaround for crashing module + * + * @return void + * + * @todo drizzle module segfaults while freeing resources, often. + * This allows at least for some development + */ +function PMA_drizzleShutdownFlush() { flush(); } -register_shutdown_function('_drizzle_shutdown_flush'); - -function _dlog_argstr($args) -{ - $r = array(); - foreach ($args as $arg) { - if (is_object($arg)) { - $r[] = get_class($arg); - } elseif (is_bool($arg)) { - $r[] = $arg ? 'true' : 'false'; - } elseif (is_null($arg)) { - $r[] = 'null'; - } else { - $r[] = $arg; - } - } - return implode(', ', $r); -} - -function _dlog($end = false) -{ - /* - static $fp = null; - - if (!$fp) { - $fp = fopen('./drizzle_log.log', 'a'); - flock($fp, LOCK_EX); - fwrite($fp, "\r\n[" . date('H:i:s') . "]\t" . $_SERVER['REQUEST_URI'] . "\r\n"); - register_shutdown_function(function() use ($fp) { - fwrite($fp, '[' . date('H:i:s') . "]\tEND\r\n\r\n"); - }); - } - if ($end) { - fwrite($fp, '[' . date('H:i:s') . "]\tok\r\n"); - } else { - $bt = debug_backtrace(true); - $caller = (isset($bt[1]['class']) ? $bt[1]['class'] . '::' : '') . $bt[1]['function']; - if ($bt[1]['function'] == '__call') { - $caller .= '^' . $bt[1]['args'][0]; - $args = _dlog_argstr($bt[1]['args'][1]); - } else { - $args = _dlog_argstr($bt[1]['args']); - } - fwrite($fp, '[' . date('H:i:s') . "]\t" . $caller . "\t" . $args . "\r\n"); - for ($i = 2; $i <= count($bt)-1; $i++) { - if (!isset($bt[$i])) { - break; - } - $caller = (isset($bt[$i]['class']) ? $bt[$i]['class'] . '::' : '') . $bt[$i]['function']; - $caller .= ' (' . $bt[$i]['file'] . ':' . $bt[$i]['line'] . ')'; - fwrite($fp, str_repeat(' ', 20) . $caller . "\r\n"); - } - } - //*/ -} +register_shutdown_function('PMA_drizzleShutdownFlush'); /** * Wrapper for Drizzle class @@ -112,25 +64,23 @@ class PMA_Drizzle extends Drizzle */ public function __construct() { - _dlog(); parent::__construct(); } /** * Creates a new database conection using TCP * - * @param $host - * @param $port - * @param $user - * @param $password - * @param $db - * @param $options + * @param string $host Drizzle host + * @param integer $port Drizzle port + * @param string $user username + * @param string $password password + * @param string $db database name + * @param integer $options connection options * * @return PMA_DrizzleCon */ public function addTcp($host, $port, $user, $password, $db, $options) { - _dlog(); $dcon = parent::addTcp($host, $port, $user, $password, $db, $options); return $dcon instanceof DrizzleCon ? new PMA_DrizzleCon($dcon) @@ -140,17 +90,16 @@ class PMA_Drizzle extends Drizzle /** * Creates a new connection using unix domain socket * - * @param $uds - * @param $user - * @param $password - * @param $db - * @param $options + * @param string $uds socket + * @param string $user username + * @param string $password password + * @param string $db database name + * @param integer $options connection options * * @return PMA_DrizzleCon */ public function addUds($uds, $user, $password, $db, $options) { - _dlog(); $dcon = parent::addUds($uds, $user, $password, $db, $options); return $dcon instanceof DrizzleCon ? new PMA_DrizzleCon($dcon) @@ -172,48 +121,45 @@ class PMA_DrizzleCon * Instance of DrizzleCon class * @var DrizzleCon */ - private $dcon; + private $_dcon; /** * Result of the most recent query * @var PMA_DrizzleResult */ - private $lastResult; + private $_lastResult; /** * Constructor * - * @param DrizzleCon $dcon + * @param DrizzleCon $dcon connection handle * * @return void */ public function __construct(DrizzleCon $dcon) { - _dlog(); - $this->dcon = $dcon; + $this->_dcon = $dcon; } /** * Executes given query. Opens database connection if not already done. * - * @param string $query - * @param int $bufferMode PMA_Drizzle::BUFFER_RESULT,PMA_Drizzle::BUFFER_ROW - * @param int $fetchMode PMA_Drizzle::FETCH_ASSOC, PMA_Drizzle::FETCH_NUM - * or PMA_Drizzle::FETCH_BOTH + * @param string $query query to execute + * @param int $bufferMode PMA_Drizzle::BUFFER_RESULT,PMA_Drizzle::BUFFER_ROW + * @param int $fetchMode PMA_Drizzle::FETCH_ASSOC, PMA_Drizzle::FETCH_NUM + * or PMA_Drizzle::FETCH_BOTH * * @return PMA_DrizzleResult */ public function query($query, $bufferMode = PMA_Drizzle::BUFFER_RESULT, $fetchMode = PMA_Drizzle::FETCH_ASSOC ) { - _dlog(); - $result = $this->dcon->query($query); + $result = $this->_dcon->query($query); if ($result instanceof DrizzleResult) { - _dlog(true); - $this->lastResult = new PMA_DrizzleResult( + $this->_lastResult = new PMA_DrizzleResult( $result, $bufferMode, $fetchMode ); - return $this->lastResult; + return $this->_lastResult; } return $result; } @@ -225,23 +171,22 @@ class PMA_DrizzleCon */ public function affectedRows() { - return $this->lastResult - ? $this->lastResult->affectedRows() + return $this->_lastResult + ? $this->_lastResult->affectedRows() : false; } /** * Pass calls of undefined methods to DrizzleCon object * - * @param $method - * @param $args + * @param string $method method name + * @param mixed $args method parameters * * @return mixed */ public function __call($method, $args) { - _dlog(); - return call_user_func_array(array($this->dcon, $method), $args); + return call_user_func_array(array($this->_dcon, $method), $args); } /** @@ -251,8 +196,7 @@ class PMA_DrizzleCon */ public function getConnectionObject() { - _dlog(); - return $this->dcon; + return $this->_dcon; } } @@ -271,81 +215,78 @@ class PMA_DrizzleResult * Instamce of DrizzleResult class * @var DrizzleResult */ - private $dresult; + private $_dresult; /** * Fetch mode * @var int */ - private $fetchMode; + private $_fetchMode; /** * Buffering mode * @var int */ - private $bufferMode; + private $_bufferMode; /** * Cached column data * @var DrizzleColumn[] */ - private $columns = null; + private $_columns = null; /** * Cached column names * @var string[] */ - private $columnNames = null; + private $_columnNames = null; /** * Constructor * - * @param DrizzleResult $dresult - * @param int $bufferMode - * @param int $fetchMode + * @param DrizzleResult $dresult result handler + * @param int $bufferMode buffering mode + * @param int $fetchMode fetching mode */ public function __construct(DrizzleResult $dresult, $bufferMode, $fetchMode) { - _dlog(); - $this->dresult = $dresult; - $this->bufferMode = $bufferMode; - $this->fetchMode = $fetchMode; + $this->_dresult = $dresult; + $this->_bufferMode = $bufferMode; + $this->_fetchMode = $fetchMode; - if ($this->bufferMode == PMA_Drizzle::BUFFER_RESULT) { - $this->dresult->buffer(); + if ($this->_bufferMode == PMA_Drizzle::BUFFER_RESULT) { + $this->_dresult->buffer(); } } /** * Sets fetch mode * - * @param int $fetchMode + * @param int $fetchMode fetch mode * * @return void */ public function setFetchMode($fetchMode) { - _dlog(); - $this->fetchMode = $fetchMode; + $this->_fetchMode = $fetchMode; } /** * Reads information about columns contained in current result - * set into {@see $columns} and {@see $columnNames} arrays + * set into {@see $_columns} and {@see $_columnNames} arrays * * @return void */ private function _readColumns() { - _dlog(); - $this->columns = array(); - $this->columnNames = array(); - if ($this->bufferMode == PMA_Drizzle::BUFFER_RESULT) { - while (($column = $this->dresult->columnNext()) !== null) { - $this->columns[] = $column; - $this->columnNames[] = $column->name(); + $this->_columns = array(); + $this->_columnNames = array(); + if ($this->_bufferMode == PMA_Drizzle::BUFFER_RESULT) { + while (($column = $this->_dresult->columnNext()) !== null) { + $this->_columns[] = $column; + $this->_columnNames[] = $column->name(); } } else { - while (($column = $this->dresult->columnRead()) !== null) { - $this->columns[] = $column; - $this->columnNames[] = $column->name(); + while (($column = $this->_dresult->columnRead()) !== null) { + $this->_columns[] = $column; + $this->_columnNames[] = $column->name(); } } } @@ -357,11 +298,10 @@ class PMA_DrizzleResult */ public function getColumns() { - _dlog(); - if (!$this->columns) { + if (!$this->_columns) { $this->_readColumns(); } - return $this->columns; + return $this->_columns; } /** @@ -371,15 +311,14 @@ class PMA_DrizzleResult */ public function numColumns() { - _dlog(); - return $this->dresult->columnCount(); + return $this->_dresult->columnCount(); } /** * Transforms result row to conform to current fetch mode * - * @param mixed &$row - * @param int $fetchMode + * @param mixed &$row row to process + * @param int $fetchMode fetch mode * * @return void */ @@ -391,12 +330,12 @@ class PMA_DrizzleResult switch ($fetchMode) { case PMA_Drizzle::FETCH_ASSOC: - $row = array_combine($this->columnNames, $row); + $row = array_combine($this->_columnNames, $row); break; case PMA_Drizzle::FETCH_BOTH: $length = count($row); for ($i = 0; $i < $length; $i++) { - $row[$this->columnNames[$i]] = $row[$i]; + $row[$this->_columnNames[$i]] = $row[$i]; } break; default: @@ -413,22 +352,21 @@ class PMA_DrizzleResult */ public function fetchRow($fetchMode = null) { - _dlog(); // read column names on first fetch, only buffered results // allow for reading it later - if (!$this->columns) { + if (!$this->_columns) { $this->_readColumns(); } if ($fetchMode === null) { - $fetchMode = $this->fetchMode; + $fetchMode = $this->_fetchMode; } $row = null; - switch ($this->bufferMode) { + switch ($this->_bufferMode) { case PMA_Drizzle::BUFFER_RESULT: - $row = $this->dresult->rowNext(); + $row = $this->_dresult->rowNext(); break; case PMA_Drizzle::BUFFER_ROW: - $row = $this->dresult->rowBuffer(); + $row = $this->_dresult->rowBuffer(); break; } $this->_transformResultRow($row, $fetchMode); @@ -438,22 +376,21 @@ class PMA_DrizzleResult /** * Adjusts the result pointer to an arbitrary row in buffered result * - * @param $row_index + * @param integer $row_index where to seek * * @return bool */ public function seek($row_index) { - _dlog(); - if ($this->bufferMode != PMA_Drizzle::BUFFER_RESULT) { + if ($this->_bufferMode != PMA_Drizzle::BUFFER_RESULT) { trigger_error( __("Can't seek in an unbuffered result set"), E_USER_WARNING ); return false; } // rowSeek always returns NULL (drizzle extension v.0.5, API v.7) - if ($row_index >= 0 && $row_index < $this->dresult->rowCount()) { - $this->dresult->rowSeek($row_index); + if ($row_index >= 0 && $row_index < $this->_dresult->rowCount()) { + $this->_dresult->rowSeek($row_index); return true; } return false; @@ -466,14 +403,13 @@ class PMA_DrizzleResult */ public function numRows() { - _dlog(); - if ($this->bufferMode != PMA_Drizzle::BUFFER_RESULT) { + if ($this->_bufferMode != PMA_Drizzle::BUFFER_RESULT) { trigger_error( __("Can't count rows in an unbuffered result set"), E_USER_WARNING ); return false; } - return $this->dresult->rowCount(); + return $this->_dresult->rowCount(); } /** @@ -483,8 +419,7 @@ class PMA_DrizzleResult */ public function affectedRows() { - _dlog(); - return $this->dresult->affectedRows(); + return $this->_dresult->affectedRows(); } /** @@ -493,10 +428,10 @@ class PMA_DrizzleResult * @return void */ public function free() - {_dlog(); - unset($this->columns); - unset($this->columnNames); - drizzle_result_free($this->dresult); - unset($this->dresult); + { + unset($this->_columns); + unset($this->_columnNames); + drizzle_result_free($this->_dresult); + unset($this->_dresult); } } diff --git a/libraries/dbi/drizzle.dbi.lib.php b/libraries/dbi/drizzle.dbi.lib.php index 7ca60e523e..507d7dc1ad 100644 --- a/libraries/dbi/drizzle.dbi.lib.php +++ b/libraries/dbi/drizzle.dbi.lib.php @@ -31,14 +31,14 @@ if (!defined('PMA_MYSQL_CLIENT_API')) { /** * Helper function for connecting to the database server * - * @param PMA_Drizzle $drizzle - * @param string $host - * @param int $port - * @param string $uds - * @param string $user - * @param string $password - * @param string $db - * @param int $options + * @param PMA_Drizzle $drizzle connection handle + * @param string $host Drizzle host + * @param integer $port Drizzle port + * @param string $uds server socket + * @param string $user username + * @param string $password password + * @param string $db database name + * @param integer $options connection options * * @return PMA_DrizzleCon */ @@ -235,7 +235,7 @@ function PMA_DBI_fetch_row($result) * Adjusts the result pointer to an arbitrary row in the result * * @param PMA_DrizzleResult $result Drizzle result object - * @param int $offset + * @param int $offset offset to seek * * @return boolean true on success, false on failure */ diff --git a/test/Environment_test.php b/test/Environment_test.php index 8799f8794d..83af26d058 100644 --- a/test/Environment_test.php +++ b/test/Environment_test.php @@ -12,10 +12,17 @@ require_once 'config.sample.inc.php'; /** + * Environment tests + * * @package PhpMyAdmin-test */ -class Environment_test extends PHPUnit_Framework_TestCase +class Environment_Test extends PHPUnit_Framework_TestCase { + /** + * Tests PHP version + * + * @return void + */ public function testPhpVersion() { $this->assertTrue( @@ -24,30 +31,56 @@ class Environment_test extends PHPUnit_Framework_TestCase ); } + /** + * Tests MySQL connection + * + * @return void + */ public function testMySQL() { - try{ - $pdo = new PDO("mysql:host=".TESTSUITE_SERVER.";dbname=".TESTSUITE_DATABASE, TESTSUITE_USER, TESTSUITE_PASSWORD); - $this->assertNull($pdo->errorCode(), "Error when trying to connect to database"); + try { + $pdo = new PDO( + "mysql:host=" . TESTSUITE_SERVER . ";dbname=" . TESTSUITE_DATABASE, + TESTSUITE_USER, + TESTSUITE_PASSWORD + ); + $this->assertNull( + $pdo->errorCode(), + "Error when trying to connect to database" + ); //$pdo->beginTransaction(); $test = $pdo->exec("SHOW TABLES;"); //$pdo->commit(); - $this->assertEquals(0, $pdo->errorCode(), 'Error trying to show tables for database'); + $this->assertEquals( + 0, + $pdo->errorCode(), + 'Error trying to show tables for database' + ); } catch (Exception $e) { $this->fail("Error: ".$e->getMessage()); } // Check id MySQL server is 5 version - preg_match("/^(\d+)?\.(\d+)?\.(\*|\d+)/", $pdo->getAttribute(constant("PDO::ATTR_SERVER_VERSION")), $version_parts); + preg_match( + "/^(\d+)?\.(\d+)?\.(\*|\d+)/", + $pdo->getAttribute(constant("PDO::ATTR_SERVER_VERSION")), + $version_parts + ); $this->assertEquals(5, $version_parts[1]); } - //TODO: Think about this test -// public function testSession() -// { -// $this->markTestIncomplete(); -// } + /** + * Test of session handling + * + * @return void + * + * @todo Think about this test + */ + public function testSession() + { + $this->markTestIncomplete(); + } } ?>