Commit f92d3f49 authored by Marco Pivetta's avatar Marco Pivetta Committed by GitHub

Merge pull request #2640 from deeky666/fix-driver-exec-method

Fix drivers' exec() method to not execute via prepared statements
parents 609a8d31 19033366
...@@ -113,10 +113,13 @@ class DB2Connection implements Connection, ServerInfoAwareConnection ...@@ -113,10 +113,13 @@ class DB2Connection implements Connection, ServerInfoAwareConnection
*/ */
public function exec($statement) public function exec($statement)
{ {
$stmt = $this->prepare($statement); $stmt = @db2_exec($this->_conn, $statement);
$stmt->execute();
if (false === $stmt) {
throw new DB2Exception(db2_stmt_errormsg());
}
return $stmt->rowCount(); return db2_num_rows($stmt);
} }
/** /**
......
...@@ -121,11 +121,11 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection ...@@ -121,11 +121,11 @@ class SQLAnywhereConnection implements Connection, ServerInfoAwareConnection
*/ */
public function exec($statement) public function exec($statement)
{ {
$stmt = $this->prepare($statement); if (false === sasql_real_query($this->connection, $statement)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
$stmt->execute(); }
return $stmt->rowCount(); return sasql_affected_rows($this->connection);
} }
/** /**
......
...@@ -118,10 +118,13 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection ...@@ -118,10 +118,13 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
*/ */
public function exec($statement) public function exec($statement)
{ {
$stmt = $this->prepare($statement); $stmt = sqlsrv_query($this->conn, $statement);
$stmt->execute();
if (false === $stmt) {
throw SQLSrvException::fromSqlSrvErrors();
}
return $stmt->rowCount(); return sqlsrv_rows_affected($stmt);
} }
/** /**
......
...@@ -590,7 +590,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -590,7 +590,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
*/ */
public function testBitComparisonExpressionSupport() public function testBitComparisonExpressionSupport()
{ {
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute(); $this->_conn->exec('DELETE FROM fetch_table');
$platform = $this->_conn->getDatabasePlatform(); $platform = $this->_conn->getDatabasePlatform();
$bitmap = array(); $bitmap = array();
...@@ -771,7 +771,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -771,7 +771,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
*/ */
public function testEmptyFetchColumnReturnsFalse() public function testEmptyFetchColumnReturnsFalse()
{ {
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute(); $this->_conn->exec('DELETE FROM fetch_table');
$this->assertFalse($this->_conn->fetchColumn('SELECT test_int FROM fetch_table')); $this->assertFalse($this->_conn->fetchColumn('SELECT test_int FROM fetch_table'));
$this->assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn()); $this->assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn());
} }
...@@ -846,7 +846,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -846,7 +846,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
private function setupFixture() private function setupFixture()
{ {
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute(); $this->_conn->exec('DELETE FROM fetch_table');
$this->_conn->insert('fetch_table', array( $this->_conn->insert('fetch_table', array(
'test_int' => 1, 'test_int' => 1,
'test_string' => 'foo', 'test_string' => 'foo',
......
...@@ -22,9 +22,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -22,9 +22,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer', array()); $table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) { $this->_conn->getSchemaManager()->createTable($table);
$this->_conn->executeQuery($sql);
}
$this->_conn->insert("duplicatekey_table", array('id' => 1)); $this->_conn->insert("duplicatekey_table", array('id' => 1));
...@@ -43,17 +41,14 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -43,17 +41,14 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testTableExistsException() public function testTableExistsException()
{ {
$schemaManager = $this->_conn->getSchemaManager();
$table = new \Doctrine\DBAL\Schema\Table("alreadyexist_table"); $table = new \Doctrine\DBAL\Schema\Table("alreadyexist_table");
$table->addColumn('id', 'integer', array()); $table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
$this->setExpectedException('\Doctrine\DBAL\Exception\TableExistsException'); $this->setExpectedException('\Doctrine\DBAL\Exception\TableExistsException');
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) { $schemaManager->createTable($table);
$this->_conn->executeQuery($sql); $schemaManager->createTable($table);
}
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
} }
public function testForeignKeyConstraintViolationExceptionOnInsert() public function testForeignKeyConstraintViolationExceptionOnInsert()
...@@ -204,7 +199,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -204,7 +199,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->exec($sql);
} }
$this->setExpectedException('\Doctrine\DBAL\Exception\NotNullConstraintViolationException'); $this->setExpectedException('\Doctrine\DBAL\Exception\NotNullConstraintViolationException');
...@@ -219,7 +214,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -219,7 +214,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer', array()); $table->addColumn('id', 'integer', array());
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->exec($sql);
} }
$this->setExpectedException('\Doctrine\DBAL\Exception\InvalidFieldNameException'); $this->setExpectedException('\Doctrine\DBAL\Exception\InvalidFieldNameException');
...@@ -237,7 +232,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -237,7 +232,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table2->addColumn('id', 'integer'); $table2->addColumn('id', 'integer');
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->exec($sql);
} }
$sql = 'SELECT id FROM ambiguous_list_table, ambiguous_list_table_2'; $sql = 'SELECT id FROM ambiguous_list_table, ambiguous_list_table_2';
...@@ -254,7 +249,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -254,7 +249,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addUniqueIndex(array('id')); $table->addUniqueIndex(array('id'));
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) { foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql); $this->_conn->exec($sql);
} }
$this->_conn->insert("unique_field_table", array('id' => 5)); $this->_conn->insert("unique_field_table", array('id' => 5));
...@@ -268,9 +263,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -268,9 +263,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer', array()); $table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) { $this->_conn->getSchemaManager()->createTable($table);
$this->_conn->executeQuery($sql);
}
$sql = 'SELECT id FRO syntax_error_table'; $sql = 'SELECT id FRO syntax_error_table';
$this->setExpectedException('\Doctrine\DBAL\Exception\SyntaxErrorException'); $this->setExpectedException('\Doctrine\DBAL\Exception\SyntaxErrorException');
...@@ -308,7 +301,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -308,7 +301,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->setExpectedException($exceptionClass); $this->setExpectedException($exceptionClass);
foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) { foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
$conn->executeQuery($sql); $conn->exec($sql);
} }
} }
...@@ -350,7 +343,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -350,7 +343,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->setExpectedException('Doctrine\DBAL\Exception\ConnectionException'); $this->setExpectedException('Doctrine\DBAL\Exception\ConnectionException');
foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) { foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
$conn->executeQuery($sql); $conn->exec($sql);
} }
} }
......
...@@ -73,7 +73,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -73,7 +73,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
public function testListForeignKeysFromExistingDatabase() public function testListForeignKeysFromExistingDatabase()
{ {
$this->_conn->executeQuery(<<<EOS $this->_conn->exec(<<<EOS
CREATE TABLE user ( CREATE TABLE user (
id INTEGER PRIMARY KEY AUTOINCREMENT, id INTEGER PRIMARY KEY AUTOINCREMENT,
page INTEGER CONSTRAINT FK_1 REFERENCES page (key) DEFERRABLE INITIALLY DEFERRED, page INTEGER CONSTRAINT FK_1 REFERENCES page (key) DEFERRABLE INITIALLY DEFERRED,
...@@ -144,7 +144,7 @@ EOS ...@@ -144,7 +144,7 @@ EOS
if(version_compare($version['versionString'], '3.7.16', '<')) { if(version_compare($version['versionString'], '3.7.16', '<')) {
$this->markTestSkipped('This version of sqlite doesn\'t return the order of the Primary Key.'); $this->markTestSkipped('This version of sqlite doesn\'t return the order of the Primary Key.');
} }
$this->_conn->executeQuery(<<<EOS $this->_conn->exec(<<<EOS
CREATE TABLE non_default_pk_order ( CREATE TABLE non_default_pk_order (
id INTEGER, id INTEGER,
other_id INTEGER, other_id INTEGER,
...@@ -173,7 +173,7 @@ CREATE TABLE dbal_1779 ( ...@@ -173,7 +173,7 @@ CREATE TABLE dbal_1779 (
) )
SQL; SQL;
$this->_conn->executeQuery($sql); $this->_conn->exec($sql);
$columns = $this->_sm->listTableColumns('dbal_1779'); $columns = $this->_sm->listTableColumns('dbal_1779');
......
...@@ -50,9 +50,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -50,9 +50,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn("id", "integer"); $table->addColumn("id", "integer");
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($platform->getCreateTableSQL($table) as $sql) { $this->_conn->getSchemaManager()->createTable($table);
$this->_conn->executeQuery($sql);
}
$this->_conn->beginTransaction(); $this->_conn->beginTransaction();
$this->_conn->insert("nontemporary", array("id" => 1)); $this->_conn->insert("nontemporary", array("id" => 1));
...@@ -87,9 +85,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -87,9 +85,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn("id", "integer"); $table->addColumn("id", "integer");
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($platform->getCreateTableSQL($table) as $sql) { $this->_conn->getSchemaManager()->createTable($table);
$this->_conn->executeQuery($sql);
}
$this->_conn->beginTransaction(); $this->_conn->beginTransaction();
$this->_conn->insert("nontemporary", array("id" => 1)); $this->_conn->insert("nontemporary", array("id" => 1));
...@@ -108,4 +104,4 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -108,4 +104,4 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$rows = $this->_conn->fetchAll('SELECT * FROM nontemporary'); $rows = $this->_conn->fetchAll('SELECT * FROM nontemporary');
$this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit."); $this->assertEquals(array(), $rows, "In an event of an error this result has one row, because of an implicit commit.");
} }
} }
\ No newline at end of file
...@@ -16,7 +16,7 @@ class DBAL202Test extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -16,7 +16,7 @@ class DBAL202Test extends \Doctrine\Tests\DbalFunctionalTestCase
} }
if ($this->_conn->getSchemaManager()->tablesExist('DBAL202')) { if ($this->_conn->getSchemaManager()->tablesExist('DBAL202')) {
$this->_conn->executeQuery('DELETE FROM DBAL202'); $this->_conn->exec('DELETE FROM DBAL202');
} else { } else {
$table = new \Doctrine\DBAL\Schema\Table('DBAL202'); $table = new \Doctrine\DBAL\Schema\Table('DBAL202');
$table->addColumn('id', 'integer'); $table->addColumn('id', 'integer');
......
...@@ -34,9 +34,7 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -34,9 +34,7 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
try { try {
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) { $this->_conn->getSchemaManager()->createTable($table);
$this->_conn->executeQuery($sql);
}
} catch(\Exception $e) { } catch(\Exception $e) {
} }
...@@ -98,4 +96,4 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -98,4 +96,4 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase
} }
} }
} }
} }
\ No newline at end of file
...@@ -18,9 +18,7 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -18,9 +18,7 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('test_string', 'string', array('notnull' => false)); $table->addColumn('test_string', 'string', array('notnull' => false));
$table->setPrimaryKey(array('id')); $table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) { $this->_conn->getSchemaManager()->createTable($table);
$this->_conn->executeQuery($sql);
}
} catch(\Exception $e) { } catch(\Exception $e) {
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment