Allowing multiple sql sentences to be executed only for creting or altering databases

This commit is contained in:
José Lorenzo Rodríguez 2010-10-20 23:57:00 -04:30
parent 09487f830c
commit 0ffe6de9e4
2 changed files with 10 additions and 1 deletions

View file

@ -321,6 +321,15 @@ class DboSource extends DataSource {
* query returning no rows, suchs as a CREATE statement, false otherwise * query returning no rows, suchs as a CREATE statement, false otherwise
*/ */
protected function _execute($sql, $params = array()) { protected function _execute($sql, $params = array()) {
$sql = trim($sql);
if (preg_match('/^CREATE|^ALTER|^DROP/i', $sql)) {
$statements = array_filter(explode(';', $sql));
if (count($statements) > 1) {
$result = array_map(array($this, '_execute'), $statements);
return array_search(false, $result) === false;
}
}
$query = $this->_connection->prepare($sql); $query = $this->_connection->prepare($sql);
$query->setFetchMode(PDO::FETCH_LAZY); $query->setFetchMode(PDO::FETCH_LAZY);
if (!$query->execute($params)) { if (!$query->execute($params)) {

View file

@ -691,7 +691,7 @@ class DboPostgresTest extends CakeTestCase {
'group2' => array('type' => 'integer', 'null' => true) 'group2' => array('type' => 'integer', 'null' => true)
) )
)); ));
$this->Dbo->query($this->Dbo->createSchema($schema1)); $this->Dbo->rawQuery($this->Dbo->createSchema($schema1));
$schema2 = new CakeSchema(array( $schema2 = new CakeSchema(array(
'name' => 'AlterTest2', 'name' => 'AlterTest2',