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