forked from datastax/php-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepared_statements.feature
83 lines (76 loc) · 2.62 KB
/
prepared_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
Feature: Prepared Statements
PHP Driver supports prepared statements. Prepared statements must be
initialized using `Cassandra\Session::prepare()`.
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: Prepared statements support named arguments
Given the following example:
"""php
<?php
$cluster = Cassandra::cluster()
->withContactPoints('127.0.0.1')
->build();
$session = $cluster->connect("simplex");
$insert = $session->prepare(
"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'),
'title' => 'La Petite Tonkinoise',
'album' => 'Bye Bye Blackbird',
'artist' => 'Joséphine Baker'
),
array(
'song_id' => new Cassandra\Uuid('f6071e72-48ec-4fcb-bf3e-379c8a696488'),
'title' => 'Die Mösch',
'album' => 'In Gold',
'artist' => 'Willi Ostermann'
),
array(
'song_id' => new Cassandra\Uuid('fbdf82ed-0063-4796-9c7c-a3d4f47b4b25'),
'title' => 'Memo From Turner',
'album' => 'Performance',
'artist' => 'Mick Jager'
),
);
foreach ($songs as $song) {
$options = new Cassandra\ExecutionOptions(array('arguments' => $song));
$session->execute($insert, $options);
}
$statement = new Cassandra\SimpleStatement("SELECT * FROM simplex.playlists");
$result = $session->execute($statement);
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
"""