1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\DBALException; |
6
|
|
|
use Doctrine\DBAL\ParameterType; |
7
|
|
|
use Doctrine\DBAL\Schema\Table; |
8
|
|
|
use Doctrine\Tests\DbalFunctionalTestCase; |
9
|
|
|
use function in_array; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @group DBAL-2369 |
13
|
|
|
*/ |
14
|
|
|
class DBAL2369Test extends DbalFunctionalTestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @throws DBALException |
18
|
|
|
*/ |
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
parent::setUp(); |
22
|
|
|
|
23
|
|
|
if ($this->_conn->getDatabasePlatform()->getName() !== 'mssql') { |
24
|
|
|
$this->markTestSkipped('Related to SQLSRV only'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ |
28
|
|
|
$sm = $this->_conn->getSchemaManager(); |
29
|
|
|
if (! $sm->tablesExist(['dbal2369'])) { |
30
|
|
|
$table = new Table('dbal2369'); |
31
|
|
|
$table->addColumn('id', 'integer'); |
32
|
|
|
$table->addColumn('textfield', 'string'); |
33
|
|
|
$table->setPrimaryKey(['id']); |
34
|
|
|
|
35
|
|
|
$sm->createTable($table); |
36
|
|
|
|
37
|
|
|
$this->_conn->insert( |
38
|
|
|
'dbal2369', |
39
|
|
|
[ |
40
|
|
|
'id' => 1, |
41
|
|
|
'textfield' => 'test', |
42
|
|
|
], |
43
|
|
|
[ |
44
|
|
|
ParameterType::INTEGER, |
45
|
|
|
ParameterType::STRING, |
46
|
|
|
] |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @throws DBALException |
53
|
|
|
*/ |
54
|
|
|
public function testSelectOnId() : void |
55
|
|
|
{ |
56
|
|
|
$query = 'SELECT id, textfield FROM dbal2369 WHERE id = ?'; |
57
|
|
|
$stmt = $this->_conn->prepare($query); |
58
|
|
|
$stmt->bindValue(1, 1, ParameterType::INTEGER); |
59
|
|
|
$stmt->execute(); |
60
|
|
|
|
61
|
|
|
$ret = $stmt->fetch(); |
62
|
|
|
|
63
|
|
|
self::assertArrayHasKey('id', $ret); |
64
|
|
|
self::assertEquals($ret['id'], 1); |
65
|
|
|
self::assertArrayHasKey('textfield', $ret); |
66
|
|
|
self::assertEquals($ret['textfield'], 'test'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @throws DBALException |
71
|
|
|
*/ |
72
|
|
|
public function testSelectOnParameterSuccess() : void |
73
|
|
|
{ |
74
|
|
|
$query = 'SELECT id, textfield FROM dbal2369 WHERE textfield = ?'; |
75
|
|
|
$stmt = $this->_conn->prepare($query); |
76
|
|
|
$stmt->bindValue(1, 'test', ParameterType::STRING); |
77
|
|
|
$stmt->execute(); |
78
|
|
|
|
79
|
|
|
$ret = $stmt->fetch(); |
80
|
|
|
|
81
|
|
|
self::assertArrayHasKey('id', $ret); |
82
|
|
|
self::assertEquals($ret['id'], 1); |
83
|
|
|
self::assertArrayHasKey('textfield', $ret); |
84
|
|
|
self::assertEquals($ret['textfield'], 'test'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* This case triggers the exception of string to int conversion error on SQL Server |
89
|
|
|
* |
90
|
|
|
* @throws DBALException |
91
|
|
|
*/ |
92
|
|
|
public function testSelectOnParameterFails() : void |
93
|
|
|
{ |
94
|
|
|
self::expectException(DBALException::class); |
|
|
|
|
95
|
|
|
|
96
|
|
|
$query = 'SELECT id, textfield FROM dbal2369 WHERE textfield = ?'; |
97
|
|
|
$stmt = $this->_conn->prepare($query); |
98
|
|
|
$stmt->bindValue(1, 3, ParameterType::INTEGER); |
99
|
|
|
$stmt->execute(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @throws DBALException |
104
|
|
|
*/ |
105
|
|
|
public function testSelectOnParameterWithOtherType() : void |
106
|
|
|
{ |
107
|
|
|
$query = 'SELECT id, textfield FROM dbal2369 WHERE textfield = ?'; |
108
|
|
|
$stmt = $this->_conn->prepare($query); |
109
|
|
|
$stmt->bindValue(1, '3', ParameterType::INTEGER); |
110
|
|
|
$stmt->execute(); |
111
|
|
|
|
112
|
|
|
self::assertFalse($stmt->fetch()); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|