-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Postgres positional parameters to Parser #6634
base: 4.3.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\SQL; | ||
|
||
use Doctrine\DBAL\ParameterType; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
use Doctrine\DBAL\Tests\TestUtil; | ||
use Doctrine\DBAL\Types\Types; | ||
|
||
final class PostgresNativePositionalParametersTest extends FunctionalTestCase | ||
{ | ||
public function testPostgresNativePositionalParameters(): void | ||
{ | ||
if (! TestUtil::isDriverOneOf('pgsql')) { | ||
self::markTestSkipped('This test requires the pgsql driver.'); | ||
} | ||
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about the PDO driver? Does it support this style of positional parameters? The behavior of the two drivers should be as similar as possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested with the pdo_pgsql driver and it does not seem to support this style of positional parameters. Only the native pgsql driver supports this native postgresql functionality |
||
|
||
$table = new Table('dummy_table'); | ||
$table->addColumn('a_number', Types::SMALLINT); | ||
$table->addColumn('a_number_2', Types::SMALLINT); | ||
$table->addColumn('b_number', Types::SMALLINT); | ||
$table->addColumn('c_number', Types::SMALLINT); | ||
$table->addColumn('a_number_3', Types::SMALLINT); | ||
$this->dropAndCreateTable($table); | ||
$this->connection->executeStatement( | ||
'INSERT INTO dummy_table (a_number, a_number_2, b_number, c_number, a_number_3)' . | ||
' VALUES ($1, $1, $2, $3, $1)', | ||
[1, 2, 3], | ||
[ParameterType::INTEGER, ParameterType::INTEGER, ParameterType::INTEGER], | ||
); | ||
$result = $this->connection->executeQuery('SELECT * FROM dummy_table')->fetchAllAssociative(); | ||
self::assertCount(1, $result); | ||
self::assertEquals(1, $result[0]['a_number']); | ||
self::assertEquals(1, $result[0]['a_number_2']); | ||
self::assertEquals(2, $result[0]['b_number']); | ||
self::assertEquals(3, $result[0]['c_number']); | ||
self::assertEquals(1, $result[0]['a_number_3']); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to extract the new pattern into a separate constant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. Two arguments: