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
*/
public function exec($statement)
{
$stmt = $this->prepare($statement);
$stmt->execute();
$stmt = @db2_exec($this->_conn, $statement);
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
*/
public function exec($statement)
{
$stmt = $this->prepare($statement);
$stmt->execute();
if (false === sasql_real_query($this->connection, $statement)) {
throw SQLAnywhereException::fromSQLAnywhereError($this->connection);
}
return $stmt->rowCount();
return sasql_affected_rows($this->connection);
}
/**
......
......@@ -118,10 +118,13 @@ class SQLSrvConnection implements Connection, ServerInfoAwareConnection
*/
public function exec($statement)
{
$stmt = $this->prepare($statement);
$stmt->execute();
$stmt = sqlsrv_query($this->conn, $statement);
if (false === $stmt) {
throw SQLSrvException::fromSqlSrvErrors();
}
return $stmt->rowCount();
return sqlsrv_rows_affected($stmt);
}
/**
......
......@@ -590,7 +590,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
*/
public function testBitComparisonExpressionSupport()
{
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
$this->_conn->exec('DELETE FROM fetch_table');
$platform = $this->_conn->getDatabasePlatform();
$bitmap = array();
......@@ -771,7 +771,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
*/
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->query('SELECT test_int FROM fetch_table')->fetchColumn());
}
......@@ -846,7 +846,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
private function setupFixture()
{
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
$this->_conn->exec('DELETE FROM fetch_table');
$this->_conn->insert('fetch_table', array(
'test_int' => 1,
'test_string' => 'foo',
......
......@@ -22,9 +22,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
$this->_conn->getSchemaManager()->createTable($table);
$this->_conn->insert("duplicatekey_table", array('id' => 1));
......@@ -43,17 +41,14 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
public function testTableExistsException()
{
$schemaManager = $this->_conn->getSchemaManager();
$table = new \Doctrine\DBAL\Schema\Table("alreadyexist_table");
$table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id'));
$this->setExpectedException('\Doctrine\DBAL\Exception\TableExistsException');
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
$schemaManager->createTable($table);
$schemaManager->createTable($table);
}
public function testForeignKeyConstraintViolationExceptionOnInsert()
......@@ -204,7 +199,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->setPrimaryKey(array('id'));
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql);
$this->_conn->exec($sql);
}
$this->setExpectedException('\Doctrine\DBAL\Exception\NotNullConstraintViolationException');
......@@ -219,7 +214,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer', array());
foreach ($schema->toSql($this->_conn->getDatabasePlatform()) as $sql) {
$this->_conn->executeQuery($sql);
$this->_conn->exec($sql);
}
$this->setExpectedException('\Doctrine\DBAL\Exception\InvalidFieldNameException');
......@@ -237,7 +232,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table2->addColumn('id', 'integer');
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';
......@@ -254,7 +249,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addUniqueIndex(array('id'));
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));
......@@ -268,9 +263,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('id', 'integer', array());
$table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
$this->_conn->getSchemaManager()->createTable($table);
$sql = 'SELECT id FRO syntax_error_table';
$this->setExpectedException('\Doctrine\DBAL\Exception\SyntaxErrorException');
......@@ -308,7 +301,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->setExpectedException($exceptionClass);
foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
$conn->executeQuery($sql);
$conn->exec($sql);
}
}
......@@ -350,7 +343,7 @@ class ExceptionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this->setExpectedException('Doctrine\DBAL\Exception\ConnectionException');
foreach ($schema->toSql($conn->getDatabasePlatform()) as $sql) {
$conn->executeQuery($sql);
$conn->exec($sql);
}
}
......
......@@ -73,7 +73,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
public function testListForeignKeysFromExistingDatabase()
{
$this->_conn->executeQuery(<<<EOS
$this->_conn->exec(<<<EOS
CREATE TABLE user (
id INTEGER PRIMARY KEY AUTOINCREMENT,
page INTEGER CONSTRAINT FK_1 REFERENCES page (key) DEFERRABLE INITIALLY DEFERRED,
......@@ -144,7 +144,7 @@ EOS
if(version_compare($version['versionString'], '3.7.16', '<')) {
$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 (
id INTEGER,
other_id INTEGER,
......@@ -173,7 +173,7 @@ CREATE TABLE dbal_1779 (
)
SQL;
$this->_conn->executeQuery($sql);
$this->_conn->exec($sql);
$columns = $this->_sm->listTableColumns('dbal_1779');
......
......@@ -50,9 +50,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn("id", "integer");
$table->setPrimaryKey(array('id'));
foreach ($platform->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
$this->_conn->getSchemaManager()->createTable($table);
$this->_conn->beginTransaction();
$this->_conn->insert("nontemporary", array("id" => 1));
......@@ -87,9 +85,7 @@ class TemporaryTableTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn("id", "integer");
$table->setPrimaryKey(array('id'));
foreach ($platform->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
$this->_conn->getSchemaManager()->createTable($table);
$this->_conn->beginTransaction();
$this->_conn->insert("nontemporary", array("id" => 1));
......
......@@ -16,7 +16,7 @@ class DBAL202Test extends \Doctrine\Tests\DbalFunctionalTestCase
}
if ($this->_conn->getSchemaManager()->tablesExist('DBAL202')) {
$this->_conn->executeQuery('DELETE FROM DBAL202');
$this->_conn->exec('DELETE FROM DBAL202');
} else {
$table = new \Doctrine\DBAL\Schema\Table('DBAL202');
$table->addColumn('id', 'integer');
......
......@@ -34,9 +34,7 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->setPrimaryKey(array('id'));
try {
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
$this->_conn->getSchemaManager()->createTable($table);
} catch(\Exception $e) {
}
......
......@@ -18,9 +18,7 @@ class WriteTest extends \Doctrine\Tests\DbalFunctionalTestCase
$table->addColumn('test_string', 'string', array('notnull' => false));
$table->setPrimaryKey(array('id'));
foreach ($this->_conn->getDatabasePlatform()->getCreateTableSQL($table) as $sql) {
$this->_conn->executeQuery($sql);
}
$this->_conn->getSchemaManager()->createTable($table);
} 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