public function testBoundQuery() { $expected = new Proto\Query\BoundQuery(); $expected->setSql('test query'); add_bind_var($expected, Proto\Query\Type::VARBINARY, 'bytes', 'hello'); add_bind_var($expected, Proto\Query\Type::INT64, 'int', '123'); add_bind_var($expected, Proto\Query\Type::UINT64, 'uint_from_int', '18446744073709551493'); // 18446744073709551493 = uint64(-123) add_bind_var($expected, Proto\Query\Type::UINT64, 'uint_from_string', '456'); add_bind_var($expected, Proto\Query\Type::FLOAT64, 'float', '1.5'); add_list_bind_var($expected, Proto\Query\Type::VARBINARY, 'bytes_list', array('one', 'two')); add_list_bind_var($expected, Proto\Query\Type::INT64, 'int_list', array('1', '2', '3')); add_list_bind_var($expected, Proto\Query\Type::UINT64, 'uint_list', array('123', '456')); add_list_bind_var($expected, Proto\Query\Type::FLOAT64, 'float_list', array('2.0', '4.0')); $actual = ProtoUtils::BoundQuery('test query', array('bytes' => 'hello', 'int' => 123, 'uint_from_int' => new UnsignedInt(-123), 'uint_from_string' => new UnsignedInt('456'), 'float' => 1.5, 'bytes_list' => array('one', 'two'), 'int_list' => array(1, 2, 3), 'uint_list' => array(new UnsignedInt(123), new UnsignedInt('456')), 'float_list' => array(2.0, 4.0))); $this->assertEquals($expected, $actual); }
public function splitQuery(Context $ctx, $keyspace, $query, array $bind_vars, $split_column, $split_count) { $request = new Proto\Vtgate\SplitQueryRequest(); $request->setKeyspace($keyspace); $request->setQuery(ProtoUtils::BoundQuery($query, $bind_vars)); $request->setSplitColumn($split_column); $request->setSplitCount($split_count); if ($ctx->getCallerId()) { $request->setCallerId($ctx->getCallerId()); } $response = $this->client->splitQuery($ctx, $request); return $response->getSplitsList(); }
public function executeEntityIds(Context $ctx, $query, $keyspace, $entity_column_name, array $entity_keyspace_ids, array $bind_vars, $tablet_type = Proto\Topodata\TabletType::MASTER) { if (!$this->inTransaction()) { throw new \Vitess\Exception('execute called while not in transaction.'); } $request = new Proto\Vtgate\ExecuteEntityIdsRequest(); $request->setSession($this->session); $request->setQuery(ProtoUtils::BoundQuery($query, $bind_vars)); $request->setTabletType($tablet_type); $request->setKeyspace($keyspace); $request->setEntityColumnName($entity_column_name); ProtoUtils::addEntityKeyspaceIds($request, $entity_keyspace_ids); if ($ctx->getCallerId()) { $request->setCallerId($ctx->getCallerId()); } $response = $this->client->executeEntityIds($ctx, $request); $this->session = $response->getSession(); ProtoUtils::checkError($response); return new Cursor($response->getResult()); }