Browse Source

Re-implementing Mysql::listDetailedSources() to not use prepared statements, using php <= 5.3.5 + mysqlnd internal driver causes segmentation faults when using a similar query from this method several times.

Jose Lorenzo Rodriguez 14 years ago
parent
commit
b8aa000589

+ 21 - 20
lib/Cake/Model/Datasource/Database/Mysql.php

@@ -607,34 +607,35 @@ class Mysql extends DboSource {
 		$condition = '';
 		$params = array();
 		if (is_string($name)) {
-			$condition = ' WHERE name = ?' ;
-			$params = array($name);
+				$condition = ' WHERE name = ' . $this->value($name);
+				$params = array($name);
 		}
-		$result = $this->_execute('SHOW TABLE STATUS ' . $condition, $params);
+		$result = $this->_connection->query('SHOW TABLE STATUS ' . $condition, PDO::FETCH_ASSOC);
 
 		if (!$result) {
-			$result->closeCursor();
-			return array();
+				$result->closeCursor();
+				return array();
 		} else {
-			$tables = array();
-			while ($row = $result->fetch()) {
-				$tables[$row->Name] = (array) $row;
-				unset($tables[$row->Name]['queryString']);
-				if (!empty($row->Collation)) {
-					$charset = $this->getCharsetName($row->Collation);
-					if ($charset) {
-						$tables[$row->Name]['charset'] = $charset;
-					}
+				$tables = array();
+				foreach ($result as $row) {
+						$tables[$row['Name']] = (array) $row;
+						unset($tables[$row['Name']]['queryString']);
+						if (!empty($row['Collation'])) {
+								$charset = $this->getCharsetName($row['Collation']);
+								if ($charset) {
+										$tables[$row['Name']]['charset'] = $charset;
+								}
+						}
 				}
-			}
-			$result->closeCursor();
-			if (is_string($name) && isset($tables[$name])) {
-				return $tables[$name];
-			}
-			return $tables;
+				$result->closeCursor();
+				if (is_string($name) && isset($tables[$name])) {
+						return $tables[$name];
+				}
+				return $tables;
 		}
 	}
 
+
 /**
  * Converts database-layer column types to basic types
  *

+ 1 - 1
lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php

@@ -65,7 +65,7 @@ class MysqlTest extends CakeTestCase {
 		}
 		$this->_debug = Configure::read('debug');
 		Configure::write('debug', 1);
-		$this->model = new MysqlTestModel();
+		$this->model = ClassRegistry::init('MysqlTestModel');
 	}
 
 /**