Orange-OpenSource / YACassandraPDO

Cassandra PDO Driver fork
Apache License 2.0
85 stars 32 forks source link

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

Open mcd-php opened 10 years ago

mcd-php commented 10 years ago

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
  ,'john.galt@example.com' -- 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 commented 9 years ago

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