mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Allowing multiple sql sentences to be executed only for creting or altering databases
This commit is contained in:
parent
09487f830c
commit
0ffe6de9e4
2 changed files with 10 additions and 1 deletions
|
@ -321,6 +321,15 @@ class DboSource extends DataSource {
|
|||
* query returning no rows, suchs as a CREATE statement, false otherwise
|
||||
*/
|
||||
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->setFetchMode(PDO::FETCH_LAZY);
|
||||
if (!$query->execute($params)) {
|
||||
|
|
|
@ -691,7 +691,7 @@ class DboPostgresTest extends CakeTestCase {
|
|||
'group2' => array('type' => 'integer', 'null' => true)
|
||||
)
|
||||
));
|
||||
$this->Dbo->query($this->Dbo->createSchema($schema1));
|
||||
$this->Dbo->rawQuery($this->Dbo->createSchema($schema1));
|
||||
|
||||
$schema2 = new CakeSchema(array(
|
||||
'name' => 'AlterTest2',
|
||||
|
|
Loading…
Reference in a new issue