1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Licensed to CRATE Technology GmbH("Crate") under one or more contributor |
4
|
|
|
* license agreements. See the NOTICE file distributed with this work for |
5
|
|
|
* additional information regarding copyright ownership. Crate licenses |
6
|
|
|
* this file to you under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. You may |
8
|
|
|
* obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
14
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
15
|
|
|
* License for the specific language governing permissions and limitations |
16
|
|
|
* under the License. |
17
|
|
|
* |
18
|
|
|
* However, if you have executed another commercial license agreement |
19
|
|
|
* with Crate these terms will supersede the license and you may use the |
20
|
|
|
* software solely pursuant to the terms of the relevant commercial agreement. |
21
|
|
|
*/ |
22
|
|
|
namespace Crate\Test\DBAL\Functional; |
23
|
|
|
|
24
|
|
|
use Crate\Test\DBAL\DBALFunctionalTestCase; |
25
|
|
|
use Doctrine\DBAL\DBALException; |
26
|
|
|
|
27
|
|
|
class BindingTestCase extends DBALFunctionalTestCase |
28
|
|
|
{ |
29
|
|
|
|
30
|
|
|
public function testBindPositionalParam() |
31
|
|
|
{ |
32
|
|
|
$name = 'crate'; |
33
|
|
|
|
34
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = ?'); |
35
|
|
|
$stmt->bindParam(1, $name); |
36
|
|
|
$stmt->execute(); |
37
|
|
|
|
38
|
|
|
$noName = 'i0ejfNlzSFCloGYtSzddTw'; |
39
|
|
|
|
40
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = ? OR master_node = ?'); |
41
|
|
|
$stmt->bindParam(1, $name); |
42
|
|
|
$stmt->bindParam(2, $noName); |
43
|
|
|
$this->assertTrue($stmt->execute()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testBindPositionalValue() |
47
|
|
|
{ |
48
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = ?'); |
49
|
|
|
$stmt->bindValue(1, 'crate'); |
50
|
|
|
$stmt->execute(); |
51
|
|
|
|
52
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = ? OR master_node = ?'); |
53
|
|
|
$stmt->bindValue(1, 'crate'); |
54
|
|
|
$stmt->bindValue(2, 'i0ejfNlzSFCloGYtSzddTw'); |
55
|
|
|
$this->assertTrue($stmt->execute()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testBindNamedParam() |
59
|
|
|
{ |
60
|
|
|
$name = 'crate'; |
61
|
|
|
|
62
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = :name'); |
63
|
|
|
$stmt->bindParam('name', $name); |
64
|
|
|
$stmt->execute(); |
65
|
|
|
|
66
|
|
|
$noName = 'i0ejfNlzSFCloGYtSzddTw'; |
67
|
|
|
|
68
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = :name OR master_node = :master_node'); |
69
|
|
|
$stmt->bindParam('name', $name); |
70
|
|
|
$stmt->bindParam('master_node', $noName); |
71
|
|
|
$this->assertTrue($stmt->execute()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testBindNamedValue() |
75
|
|
|
{ |
76
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = :name'); |
77
|
|
|
$stmt->bindValue('name', 'crate'); |
78
|
|
|
$stmt->execute(); |
79
|
|
|
|
80
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM sys.cluster WHERE name = :name OR master_node = :master_node'); |
81
|
|
|
$stmt->bindValue('name', 'crate'); |
82
|
|
|
$stmt->bindValue('master_node', 'i0ejfNlzSFCloGYtSzddTw'); |
83
|
|
|
$this->assertTrue($stmt->execute()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testBindTimestamp() |
87
|
|
|
{ |
88
|
|
|
if ($this->_conn->getSchemaManager()->tablesExist("foo")) { |
89
|
|
|
$this->execute("DROP TABLE foo"); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$this->execute("CREATE TABLE foo (id int, ts timestamp) with (number_of_replicas=0)"); |
93
|
|
|
$this->execute("INSERT INTO foo (id, ts) VALUES (1, 1413901591000)"); |
94
|
|
|
$this->execute("INSERT INTO foo (id, ts) VALUES (2, 1413901592000)"); |
95
|
|
|
$this->execute("INSERT INTO foo (id, ts) VALUES (3, 1413901593000)"); |
96
|
|
|
$this->execute("REFRESH TABLE foo"); |
97
|
|
|
|
98
|
|
|
$date = new \DateTime("2014-10-21 14:26:32"); // => 1413901592000 |
99
|
|
|
|
100
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM foo WHERE ts > ?'); |
101
|
|
|
$stmt->bindValue(1, $date, 'datetimetz'); |
102
|
|
|
$stmt->execute(); |
103
|
|
|
$row = $stmt->fetchAll(); |
104
|
|
|
$this->assertEquals($row[0]['id'], 3); |
105
|
|
|
$this->assertEquals($row[0]['ts'], 1413901593000); |
106
|
|
|
|
107
|
|
|
$stmt = $this->prepareStatement('SELECT * FROM foo WHERE ts < ?'); |
108
|
|
|
$stmt->bindValue(1, $date, 'datetime'); |
109
|
|
|
$stmt->execute(); |
110
|
|
|
$row = $stmt->fetchAll(); |
111
|
|
|
$this->assertEquals($row[0]['id'], 1); |
112
|
|
|
$this->assertEquals($row[0]['ts'], 1413901591000); |
113
|
|
|
|
114
|
|
|
$this->execute("DROP TABLE foo"); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|