forked from datastax/php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_statements.feature
212 lines (192 loc) · 6.61 KB
/
simple_statements.feature
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
Feature: Simple Statements
PHP Driver supports simple statements.
Background:
Given a running Cassandra cluster
And the following schema:
"""cql
CREATE KEYSPACE simplex WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 1
};
USE simplex;
CREATE TABLE playlists (
id uuid,
title text,
album text,
artist text,
song_id uuid,
PRIMARY KEY (id, title, album, artist)
);
"""
Scenario: Simple statements are initialized with a CQL string
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$statement = new Cassandra\SimpleStatement("SELECT * FROM playlists");
$result = $session->execute($statement);
echo "Result contains " . $result->count() . " rows";
"""
When it is executed
Then its output should contain:
"""
Result contains 0 rows
"""
@cassandra-version-2.0
Scenario: Simple statements support positional arguments
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$statement = new Cassandra\SimpleStatement(
"INSERT INTO playlists (id, song_id, artist, title, album) " .
"VALUES (62c36092-82a1-3a00-93d1-46196ee77204, ?, ?, ?, ?)"
);
$songs = array(
array(
new Cassandra\Uuid('756716f7-2e54-4715-9f00-91dcbea6cf50'),
'Joséphine Baker',
'La Petite Tonkinoise',
'Bye Bye Blackbird'
),
array(
new Cassandra\Uuid('f6071e72-48ec-4fcb-bf3e-379c8a696488'),
'Willi Ostermann',
'Die Mösch',
'In Gold'
),
array(
new Cassandra\Uuid('fbdf82ed-0063-4796-9c7c-a3d4f47b4b25'),
'Mick Jager',
'Memo From Turner',
'Performance'
),
);
foreach ($songs as $song) {
$options = array('arguments' => $song);
$session->execute($statement, $options);
}
$result = $session->execute("SELECT * FROM simplex.playlists");
foreach ($result as $row) {
echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . "\n";
}
"""
When it is executed
Then its output should contain:
"""
Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
"""
And its output should contain:
"""
Willi Ostermann: Die Mösch / In Gold
"""
And its output should contain:
"""
Mick Jager: Memo From Turner / Performance
"""
@cassandra-version-2.1
Scenario: Simple statements also support named arguments
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$statement = new Cassandra\SimpleStatement(
"INSERT INTO playlists (id, song_id, artist, title, album) " .
"VALUES (62c36092-82a1-3a00-93d1-46196ee77204, ?, ?, ?, ?)"
);
$songs = array(
array(
'song_id' => new Cassandra\Uuid('756716f7-2e54-4715-9f00-91dcbea6cf50'),
'artist' => 'Joséphine Baker',
'title' => 'La Petite Tonkinoise',
'album' => 'Bye Bye Blackbird'
),
array(
'song_id' => new Cassandra\Uuid('f6071e72-48ec-4fcb-bf3e-379c8a696488'),
'artist' => 'Willi Ostermann',
'title' => 'Die Mösch',
'album' => 'In Gold'
),
array(
'song_id' => new Cassandra\Uuid('fbdf82ed-0063-4796-9c7c-a3d4f47b4b25'),
'artist' => 'Mick Jager',
'title' => 'Memo From Turner',
'album' => 'Performance'
),
);
foreach ($songs as $song) {
$session->execute($statement, array('arguments' => $song));
}
$result = $session->execute("SELECT * FROM simplex.playlists");
foreach ($result as $row) {
echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . "\n";
}
"""
When it is executed
Then its output should contain:
"""
Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
"""
And its output should contain:
"""
Willi Ostermann: Die Mösch / In Gold
"""
And its output should contain:
"""
Mick Jager: Memo From Turner / Performance
"""
@cassandra-version-2.1
Scenario: Simple statements also supports ":name" arguments
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$songs = array(
array(
'song_id' => new Cassandra\Uuid('756716f7-2e54-4715-9f00-91dcbea6cf50'),
'artist' => 'Joséphine Baker',
'title' => 'La Petite Tonkinoise',
'album' => 'Bye Bye Blackbird'
),
);
foreach ($songs as $song) {
$options = array('arguments' => $song);
$session->execute(
"INSERT INTO playlists (id, song_id, artist, title, album) " .
"VALUES (62c36092-82a1-3a00-93d1-46196ee77204, ?, ?, ?, ?)",
$options
);
}
$statement = new Cassandra\SimpleStatement(
"SELECT * FROM simplex.playlists " .
"WHERE id = :id AND artist = :artist AND title = :title AND album = :album"
);
$options = array('arguments' =>
array(
'id' => new Cassandra\Uuid('62c36092-82a1-3a00-93d1-46196ee77204'),
'artist' => 'Joséphine Baker',
'title' => 'La Petite Tonkinoise',
'album' => 'Bye Bye Blackbird'
)
);
$result = $session->execute($statement, $options);
$row = $result->first();
echo $row['artist'] . ": " . $row['title'] . " / " . $row['album'] . "\n";
"""
When it is executed
Then its output should contain:
"""
Joséphine Baker: La Petite Tonkinoise / Bye Bye Blackbird
"""