jbochi / lua-resty-cassandra

Pure Lua Cassandra client using CQL binary protocol

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Executing multiple commands

subnetmarco opened this issue · comments

I'm trying to execute multiple commands like:

local table_created, err = session:execute([[
    CREATE TABLE users (
      user_id uuid PRIMARY KEY,
      name varchar,
      age int
    );
    CREATE INDEX ON users(name);
    CREATE INDEX ON users(age);
]])

But it seems like the client doesn't like it and I get the following error:

Cassandra returned error (Syntax_error): "line 7:4 missing EOF at 'CREATE' (...varchar,      age int    );    [CREATE] INDEX...)"

This is currently not supported. We need to add BATCH support (issue #7)
first.
On Jan 14, 2015 6:19 PM, "Marco Palladino" notifications@github.com wrote:

I'm trying to execute multiple commands like:

local table_created, err = session:execute([[ CREATE TABLE users ( user_id uuid PRIMARY KEY, name varchar, age int ); CREATE INDEX ON users(name); CREATE INDEX ON users(age);]])

But it seems like the client doesn't like it and I get the following
error:

Cassandra returned error (Syntax_error): "line 7:4 missing EOF at 'CREATE' (...varchar, age int ); [CREATE] INDEX...)"


Reply to this email directly or view it on GitHub
#26.

I think we should not support multiple commands in a single string, since we would need a parser to split the statements.

We should follow the API of the BatchStatement in the Python driver:

batch = BatchStatement()
batch.add(SimpleStatement("INSERT INTO users (name, age) VALUES (%s, %s)"), (name, age))
batch.add(SimpleStatement("DELETE FROM pending_users WHERE name=%s"), (name,))
session.execute(batch)

That is much easier to implement.

I'm closing this issue now.