@Test
public void testStrings() throws Exception {
String createTable =
"create table vtocc_strings(vb varbinary(16), c char(16), vc varchar(16), b binary(4), tb tinyblob, bl blob, ttx tinytext, tx text, en enum('a','b'), s set('a','b'), primary key(vb)) comment 'vtocc_nocache'\n" + "";
VtGate vtgate = VtGate.connect("localhost:" + testEnv.port, 0);
vtgate.begin();
vtgate.execute(getQuery(createTable));
vtgate.commit();
String insertSql =
"insert into vtocc_strings values(:vb, :c, :vc, :b, :tb, :bl, :ttx, :tx, :en, :s)";
Query insertQuery = new QueryBuilder(insertSql, testEnv.keyspace, "master")
.addBindVar(BindVariable.forBytes("vb", "a".getBytes()))
.addBindVar(BindVariable.forBytes("c", "b".getBytes()))
.addBindVar(BindVariable.forBytes("vc", "c".getBytes()))
.addBindVar(BindVariable.forBytes("b", "d".getBytes()))
.addBindVar(BindVariable.forBytes("tb", "e".getBytes()))
.addBindVar(BindVariable.forBytes("bl", "f".getBytes()))
.addBindVar(BindVariable.forBytes("ttx", "g".getBytes()))
.addBindVar(BindVariable.forBytes("tx", "h".getBytes()))
.addBindVar(BindVariable.forString("en", "a"))
.addBindVar(BindVariable.forString("s", "a,b"))
.addKeyRange(KeyRange.ALL)
.build();
vtgate.begin();
vtgate.execute(insertQuery);
vtgate.commit();
String selectSql = "select * from vtocc_strings where vb = 'a'";
Query selectQuery =
new QueryBuilder(selectSql, testEnv.keyspace, "master").addKeyRange(KeyRange.ALL).build();
Cursor cursor = vtgate.execute(selectQuery);
Assert.assertEquals(1, cursor.getRowsAffected());
Row row = cursor.next();
Assert.assertTrue(Arrays.equals(row.getBytes("vb"), "a".getBytes()));
Assert.assertTrue(Arrays.equals(row.getBytes("c"), "b".getBytes()));
Assert.assertTrue(Arrays.equals(row.getBytes("vc"), "c".getBytes()));
// binary(4) column will be suffixed with three 0 bytes
Assert.assertTrue(
Arrays.equals(row.getBytes("b"), ByteBuffer.allocate(4).put((byte) 'd').array()));
Assert.assertTrue(Arrays.equals(row.getBytes("tb"), "e".getBytes()));
Assert.assertTrue(Arrays.equals(row.getBytes("bl"), "f".getBytes()));
Assert.assertTrue(Arrays.equals(row.getBytes("ttx"), "g".getBytes()));
Assert.assertTrue(Arrays.equals(row.getBytes("tx"), "h".getBytes()));
// Assert.assertTrue(row.getString("en").equals("a"));
// Assert.assertTrue(row.getString("s").equals("a,b"));
vtgate.close();
}