1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\ParameterType; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @group DBAL-2369 |
9
|
|
|
*/ |
10
|
|
|
class DBAL2369Test extends \Doctrine\Tests\DbalFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
protected function setUp() |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
parent::setUp(); |
16
|
|
|
|
17
|
|
|
$platform = $this->_conn->getDatabasePlatform()->getName(); |
18
|
|
|
|
19
|
|
|
if (!in_array($platform, ['sqlsrv', 'mssql'])) { |
20
|
|
|
$this->markTestSkipped('Related to SQLSRV only'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
try { |
24
|
|
|
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */ |
25
|
|
|
$table = new \Doctrine\DBAL\Schema\Table('interger_string_table'); |
26
|
|
|
$table->addColumn('id', 'integer'); |
27
|
|
|
$table->addColumn('textfield', 'string'); |
28
|
|
|
$table->addColumn('number_as_string_field', 'string'); |
29
|
|
|
$table->setPrimaryKey(['id']); |
30
|
|
|
|
31
|
|
|
$sm = $this->_conn->getSchemaManager(); |
32
|
|
|
$sm->createTable($table); |
33
|
|
|
} catch (\Exception $e) { |
|
|
|
|
34
|
|
|
|
35
|
|
|
} |
36
|
|
|
$this->_conn->exec($this->_conn->getDatabasePlatform()->getTruncateTableSQL('interger_string_table')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testInsert() |
40
|
|
|
{ |
41
|
|
|
$ret = $this->_conn->insert( |
42
|
|
|
'interger_string_table', |
43
|
|
|
[ |
44
|
|
|
'id' => 1, |
45
|
|
|
'textfield' => 'test', |
46
|
|
|
'number_as_string_field' => '2', |
47
|
|
|
], |
48
|
|
|
[ |
49
|
|
|
ParameterType::INTEGER, |
50
|
|
|
ParameterType::STRING, |
51
|
|
|
ParameterType::STRING, |
52
|
|
|
] |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
self::assertEquals(1, $ret); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testSelectOnId() |
59
|
|
|
{ |
60
|
|
|
$this->_conn->insert( |
61
|
|
|
'interger_string_table', |
62
|
|
|
[ |
63
|
|
|
'id' => 1, |
64
|
|
|
'textfield' => 'test', |
65
|
|
|
'number_as_string_field' => '2', |
66
|
|
|
], |
67
|
|
|
[ |
68
|
|
|
ParameterType::INTEGER, |
69
|
|
|
ParameterType::STRING, |
70
|
|
|
ParameterType::STRING, |
71
|
|
|
] |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
$query = 'SELECT id, textfield, number_as_string_field FROM interger_string_table WHERE id = ?'; |
75
|
|
|
$stmt = $this->_conn->prepare($query); |
76
|
|
|
$stmt->bindValue(1, 1, 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
|
|
|
self::assertArrayHasKey('number_as_string_field', $ret); |
86
|
|
|
self::assertEquals($ret['number_as_string_field'], '2'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testSelectOnParameter() |
90
|
|
|
{ |
91
|
|
|
$this->_conn->insert( |
92
|
|
|
'interger_string_table', |
93
|
|
|
[ |
94
|
|
|
'id' => 2, |
95
|
|
|
'textfield' => 'test2', |
96
|
|
|
'number_as_string_field' => '3', |
97
|
|
|
], |
98
|
|
|
[ |
99
|
|
|
ParameterType::INTEGER, |
100
|
|
|
ParameterType::STRING, |
101
|
|
|
ParameterType::STRING, |
102
|
|
|
] |
103
|
|
|
); |
104
|
|
|
|
105
|
|
|
$query = 'SELECT id, textfield, number_as_string_field FROM interger_string_table WHERE number_as_string_field = ?'; |
106
|
|
|
$stmt = $this->_conn->prepare($query); |
107
|
|
|
$stmt->bindValue(1, (int) 3, ParameterType::STRING); |
108
|
|
|
$stmt->execute(); |
109
|
|
|
|
110
|
|
|
$ret = $stmt->fetch(); |
111
|
|
|
|
112
|
|
|
// var_dump($ret); |
|
|
|
|
113
|
|
|
|
114
|
|
|
self::assertArrayHasKey('id', $ret); |
115
|
|
|
self::assertEquals($ret['id'], 2); |
116
|
|
|
self::assertArrayHasKey('textfield', $ret); |
117
|
|
|
self::assertEquals($ret['textfield'], 'test2'); |
118
|
|
|
self::assertArrayHasKey('number_as_string_field', $ret); |
119
|
|
|
self::assertEquals($ret['number_as_string_field'], '3'); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|