Freeing up some memory in dbos after the result set has been completly fetched.

Adding dbo_mysql and dbo_postgres to the AllDAtabase testsuite
This commit is contained in:
José Lorenzo Rodríguez 2010-11-16 23:59:24 -04:30
parent c0f10437ea
commit 40418de218
6 changed files with 25 additions and 1 deletions

View file

@ -187,6 +187,7 @@ class DboMysql extends DboSource {
$result = $this->_execute('SHOW TABLES FROM ' . $this->config['database']); $result = $this->_execute('SHOW TABLES FROM ' . $this->config['database']);
if (!$result) { if (!$result) {
$result->closeCursor();
return array(); return array();
} else { } else {
$tables = array(); $tables = array();
@ -194,6 +195,8 @@ class DboMysql extends DboSource {
while ($line = $result->fetch()) { while ($line = $result->fetch()) {
$tables[] = $line[0]; $tables[] = $line[0];
} }
$result->closeCursor();
parent::listSources($tables); parent::listSources($tables);
return $tables; return $tables;
} }
@ -245,6 +248,7 @@ class DboMysql extends DboSource {
} }
return $resultRow; return $resultRow;
} else { } else {
$this->_result->closeCursor();
return false; return false;
} }
} }
@ -322,6 +326,7 @@ class DboMysql extends DboSource {
} }
} }
$this->__cacheDescription($this->fullTableName($model, false), $fields); $this->__cacheDescription($this->fullTableName($model, false), $fields);
$cols->closeCursor();
return $fields; return $fields;
} }
@ -437,6 +442,7 @@ class DboMysql extends DboSource {
$index[$idx->Key_name]['column'] = $col; $index[$idx->Key_name]['column'] = $col;
} }
} }
$indices->closeCursor();
} }
return $index; return $index;
} }
@ -596,6 +602,7 @@ class DboMysql extends DboSource {
$result = $this->_execute('SHOW TABLE STATUS ' . $condition, $params); $result = $this->_execute('SHOW TABLE STATUS ' . $condition, $params);
if (!$result) { if (!$result) {
$result->closeCursor();
return array(); return array();
} else { } else {
$tables = array(); $tables = array();
@ -609,6 +616,7 @@ class DboMysql extends DboSource {
} }
} }
} }
$result->closeCursor();
if (is_string($name)) { if (is_string($name)) {
return $tables[$name]; return $tables[$name];
} }

View file

@ -164,6 +164,7 @@ class DboPostgres extends DboSource {
$result = $this->_execute($sql, array($schema)); $result = $this->_execute($sql, array($schema));
if (!$result) { if (!$result) {
$result->closeCursor();
return array(); return array();
} else { } else {
$tables = array(); $tables = array();
@ -172,6 +173,7 @@ class DboPostgres extends DboSource {
$tables[] = $item->name; $tables[] = $item->name;
} }
$result->closeCursor();
parent::listSources($tables); parent::listSources($tables);
return $tables; return $tables;
} }
@ -247,6 +249,8 @@ class DboPostgres extends DboSource {
if (isset($model->sequence)) { if (isset($model->sequence)) {
$this->_sequenceMap[$table][$model->primaryKey] = $model->sequence; $this->_sequenceMap[$table][$model->primaryKey] = $model->sequence;
} }
$cols->closeCursor();
return $fields; return $fields;
} }
@ -717,6 +721,7 @@ class DboPostgres extends DboSource {
} }
return $resultRow; return $resultRow;
} else { } else {
$this->_result->closeCursor();
return false; return false;
} }
} }

View file

@ -333,9 +333,11 @@ class DboSource extends DataSource {
if (!$query->execute($params)) { if (!$query->execute($params)) {
$this->_results = $query; $this->_results = $query;
$this->error = $this->lastError($query); $this->error = $this->lastError($query);
$query->closeCursor();
return false; return false;
} }
if (!$query->columnCount()) { if (!$query->columnCount()) {
$query->closeCursor();
return true; return true;
} }
return $query; return $query;

View file

@ -38,7 +38,14 @@ class AllDatabaseTest extends PHPUnit_Framework_TestSuite {
$path = CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS; $path = CORE_TEST_CASES . DS . 'libs' . DS . 'model' . DS;
$tasks = array('db_acl', 'cake_schema', 'connection_manager', 'datasources' . DS . 'dbo_source'); $tasks = array(
'db_acl',
'cake_schema',
'connection_manager',
'datasources' . DS . 'dbo_source',
'datasources' . DS . 'dbo' . DS . 'dbo_mysql',
'datasources' . DS . 'dbo' . DS . 'dbo_postgres'
);
foreach ($tasks as $task) { foreach ($tasks as $task) {
$suite->addTestFile($path . $task . '.test.php'); $suite->addTestFile($path . $task . '.test.php');
} }

View file

@ -62,6 +62,7 @@ class DboMysqlTest extends CakeTestCase {
*/ */
public function setUp() { public function setUp() {
$this->Dbo = ConnectionManager::getDataSource('test'); $this->Dbo = ConnectionManager::getDataSource('test');
$this->skipIf(!($this->Dbo instanceof DboMysql));
if ($this->Dbo->config['driver'] !== 'mysql') { if ($this->Dbo->config['driver'] !== 'mysql') {
$this->markTestSkipped('The MySQL extension is not available.'); $this->markTestSkipped('The MySQL extension is not available.');
} }

View file

@ -244,6 +244,7 @@ class DboPostgresTest extends CakeTestCase {
public function setUp() { public function setUp() {
Configure::write('Cache.disable', true); Configure::write('Cache.disable', true);
$this->Dbo = ConnectionManager::getDataSource('test'); $this->Dbo = ConnectionManager::getDataSource('test');
$this->skipIf(!($this->Dbo instanceof DboPostgres));
$this->Dbo2 = new DboPostgresTestDb($this->Dbo->config, false); $this->Dbo2 = new DboPostgresTestDb($this->Dbo->config, false);
$this->skipUnless($this->Dbo->config['driver'] == 'postgres', 'PostgreSQL connection not available'); $this->skipUnless($this->Dbo->config['driver'] == 'postgres', 'PostgreSQL connection not available');
$this->model = new PostgresTestModel(); $this->model = new PostgresTestModel();