Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

CQLSTATE[HY000] [2] Invalid STRING constant (...) for key of type uuid #64

Open
mcd-php opened this issue Sep 4, 2014 · 1 comment
Open

Comments

@mcd-php
Copy link

mcd-php commented Sep 4, 2014

Demo:

bug_uuid_type.create.cql3

DROP KEYSPACE IF EXISTS bug_uuid_type;
CREATE KEYSPACE bug_uuid_type WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor' : 1};
USE bug_uuid_type;

CREATE COLUMNFAMILY user (
    KEY uuid,
    name text,
    email text,
    login text,
    PRIMARY KEY ( KEY )
);
CREATE INDEX user__email ON user (email);
CREATE INDEX user__login ON user (login);

INSERT INTO user (key,name,login,email) VALUES (
   bd74f920-3408-11e4-8c21-0800200c9a66 -- key
  ,'John Galt' -- name
  ,'john-galt' -- login
  ,'[email protected]' -- email
);

cassandra_pdo_uuid_wrong_type.php

<?php

$db = new PDO('cassandra:host=localhost;cqlversion=3.0.0;dbname=bug_uuid_type','bug_uuid_type','yet-no-password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql = 'SELECT * FROM user WHERE key=:qp0';
$userUUID = 'bd74f920-3408-11e4-8c21-0800200c9a66';

$stmtPlain = $db->query(str_replace(':qp0', $userUUID, $sql));
$stmtPlain->setFetchMode(PDO::FETCH_ASSOC);
$resultPlain = $stmtPlain->fetchAll();
var_dump($resultPlain);

$stmtBind = $db->prepare($sql);
$stmtBind->setFetchMode(PDO::FETCH_ASSOC);
$stmtBind->bindValue(':qp0',$userUUID,PDO::PARAM_STR);
$stmtBind->execute();
$resultBind = $stmtBind->fetchAll();
var_dump($resultBind);

Versions:
OS: Ubuntu 14.04, updated daily (development workstation). Same on Debian Wheezy (production host), not yet investigated.
php5: 5.5.9+dfsg-1ubuntu4.3
thrift: 0.9.1 (tar.gz ... make ... checkinstall, 0.9.2 had errors, failed to build or install)
YACassandraPDO: 0.5.2-1 (git pull ... checkinstall)
cassandra: 2.0.9

@xawksow
Copy link

xawksow commented Dec 26, 2014

The line
"$stmtBind->bindValue(':qp0',$userUUID,PDO::PARAM_STR);"
should be
"$stmtBind->bindValue(':qp0',$userUUID,PDO::CASSANDRA_UUID);"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants