|
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
|
|
|
$platform = $this->_conn->getDatabasePlatform()->getName(); |
|
24
|
|
|
|
|
25
|
|
|
if (! in_array($platform, ['sqlsrv', 'mssql'])) { |
|
26
|
|
|
$this->markTestSkipped('Related to SQLSRV only'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
$table = new Table('integer_string_table'); |
|
30
|
|
|
$table->addColumn('id', 'integer'); |
|
31
|
|
|
$table->addColumn('textfield', 'string'); |
|
32
|
|
|
$table->addColumn('number_as_string_field', 'string'); |
|
33
|
|
|
$table->setPrimaryKey(['id']); |
|
34
|
|
|
|
|
35
|
|
|
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ |
|
36
|
|
|
$sm = $this->_conn->getSchemaManager(); |
|
37
|
|
|
$sm->createTable($table); |
|
38
|
|
|
|
|
39
|
|
|
$this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('integer_string_table')); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @throws DBALException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function testInsert(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$ret = $this->_conn->insert( |
|
48
|
|
|
'integer_string_table', |
|
49
|
|
|
[ |
|
50
|
|
|
'id' => 1, |
|
51
|
|
|
'textfield' => 'test', |
|
52
|
|
|
'number_as_string_field' => '2', |
|
53
|
|
|
], |
|
54
|
|
|
[ |
|
55
|
|
|
ParameterType::INTEGER, |
|
56
|
|
|
ParameterType::STRING, |
|
57
|
|
|
ParameterType::STRING, |
|
58
|
|
|
] |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
self::assertEquals(1, $ret); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @throws DBALException |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testSelectOnId(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$this->_conn->insert( |
|
70
|
|
|
'integer_string_table', |
|
71
|
|
|
[ |
|
72
|
|
|
'id' => 1, |
|
73
|
|
|
'textfield' => 'test', |
|
74
|
|
|
'number_as_string_field' => '2', |
|
75
|
|
|
], |
|
76
|
|
|
[ |
|
77
|
|
|
ParameterType::INTEGER, |
|
78
|
|
|
ParameterType::STRING, |
|
79
|
|
|
ParameterType::STRING, |
|
80
|
|
|
] |
|
81
|
|
|
); |
|
82
|
|
|
|
|
83
|
|
|
$query = 'SELECT id, textfield, number_as_string_field FROM integer_string_table WHERE id = ?'; |
|
84
|
|
|
$stmt = $this->_conn->prepare($query); |
|
85
|
|
|
$stmt->bindValue(1, 1, ParameterType::STRING); |
|
86
|
|
|
$stmt->execute(); |
|
87
|
|
|
|
|
88
|
|
|
$ret = $stmt->fetch(); |
|
89
|
|
|
|
|
90
|
|
|
self::assertArrayHasKey('id', $ret); |
|
91
|
|
|
self::assertEquals($ret['id'], 1); |
|
92
|
|
|
self::assertArrayHasKey('textfield', $ret); |
|
93
|
|
|
self::assertEquals($ret['textfield'], 'test'); |
|
94
|
|
|
self::assertArrayHasKey('number_as_string_field', $ret); |
|
95
|
|
|
self::assertEquals($ret['number_as_string_field'], '2'); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @throws DBALException |
|
100
|
|
|
*/ |
|
101
|
|
|
public function testSelectOnParameter(): void |
|
102
|
|
|
{ |
|
103
|
|
|
$this->_conn->insert( |
|
104
|
|
|
'integer_string_table', |
|
105
|
|
|
[ |
|
106
|
|
|
'id' => 2, |
|
107
|
|
|
'textfield' => 'test2', |
|
108
|
|
|
'number_as_string_field' => '3', |
|
109
|
|
|
], |
|
110
|
|
|
[ |
|
111
|
|
|
ParameterType::INTEGER, |
|
112
|
|
|
ParameterType::STRING, |
|
113
|
|
|
ParameterType::STRING, |
|
114
|
|
|
] |
|
115
|
|
|
); |
|
116
|
|
|
|
|
117
|
|
|
$query = 'SELECT id, textfield, number_as_string_field FROM integer_string_table WHERE number_as_string_field = ?'; |
|
118
|
|
|
$stmt = $this->_conn->prepare($query); |
|
119
|
|
|
$stmt->bindValue(1, 3, ParameterType::STRING); |
|
120
|
|
|
$stmt->execute(); |
|
121
|
|
|
|
|
122
|
|
|
$ret = $stmt->fetch(); |
|
123
|
|
|
|
|
124
|
|
|
self::assertArrayHasKey('id', $ret); |
|
125
|
|
|
self::assertEquals($ret['id'], 2); |
|
126
|
|
|
self::assertArrayHasKey('textfield', $ret); |
|
127
|
|
|
self::assertEquals($ret['textfield'], 'test2'); |
|
128
|
|
|
self::assertArrayHasKey('number_as_string_field', $ret); |
|
129
|
|
|
self::assertEquals($ret['number_as_string_field'], '3'); |
|
130
|
|
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|