Esempio n. 1
0
 public function testBoundQuery()
 {
     $expected = new \query\BoundQuery();
     $expected->setSql('test query');
     add_bind_var($expected, \query\BindVariable\Type::TYPE_BYTES, 'setValueBytes', 'bytes', 'hello');
     add_bind_var($expected, \query\BindVariable\Type::TYPE_INT, 'setValueInt', 'int', 123);
     add_bind_var($expected, \query\BindVariable\Type::TYPE_UINT, 'setValueUint', 'uint_from_int', -123);
     add_bind_var($expected, \query\BindVariable\Type::TYPE_FLOAT, 'setValueFloat', 'float', 1.5);
     add_bind_var($expected, \query\BindVariable\Type::TYPE_BYTES_LIST, 'setValueBytesList', 'bytes_list', array('one', 'two'));
     add_bind_var($expected, \query\BindVariable\Type::TYPE_INT_LIST, 'setValueIntList', 'int_list', array(1, 2, 3));
     add_bind_var($expected, \query\BindVariable\Type::TYPE_UINT_LIST, 'setValueUintList', 'uint_list', array(123, 456));
     add_bind_var($expected, \query\BindVariable\Type::TYPE_FLOAT_LIST, 'setValueFloatList', 'float_list', array(2.0, 4.0));
     $actual = VTProto::BoundQuery('test query', array('bytes' => 'hello', 'int' => 123, 'uint_from_int' => new VTUnsignedInt(-123), 'float' => 1.5, 'bytes_list' => array('one', 'two'), 'int_list' => array(1, 2, 3), 'uint_list' => array(new VTUnsignedInt(123), new VTUnsignedInt(456)), 'float_list' => array(2.0, 4.0)));
     $this->assertEquals($expected, $actual);
 }
Esempio n. 2
0
 public function testBoundQuery()
 {
     $expected = new \query\BoundQuery();
     $expected->setSql('test query');
     add_bind_var($expected, \query\Type::VARBINARY, 'bytes', 'hello');
     add_bind_var($expected, \query\Type::INT64, 'int', '123');
     add_bind_var($expected, \query\Type::UINT64, 'uint_from_int', '18446744073709551493');
     // 18446744073709551493 = uint64(-123)
     add_bind_var($expected, \query\Type::UINT64, 'uint_from_string', '456');
     add_bind_var($expected, \query\Type::FLOAT64, 'float', '1.5');
     add_list_bind_var($expected, \query\Type::VARBINARY, 'bytes_list', array('one', 'two'));
     add_list_bind_var($expected, \query\Type::INT64, 'int_list', array('1', '2', '3'));
     add_list_bind_var($expected, \query\Type::UINT64, 'uint_list', array('123', '456'));
     add_list_bind_var($expected, \query\Type::FLOAT64, 'float_list', array('2.0', '4.0'));
     $actual = VTProto::BoundQuery('test query', array('bytes' => 'hello', 'int' => 123, 'uint_from_int' => new VTUnsignedInt(-123), 'uint_from_string' => new VTUnsignedInt('456'), 'float' => 1.5, 'bytes_list' => array('one', 'two'), 'int_list' => array(1, 2, 3), 'uint_list' => array(new VTUnsignedInt(123), new VTUnsignedInt('456')), 'float_list' => array(2.0, 4.0)));
     $this->assertEquals($expected, $actual);
 }
Esempio n. 3
0
 public function executeEntityIds(VTContext $ctx, $query, $keyspace, $entity_column_name, array $entity_keyspace_ids, array $bind_vars, $tablet_type = \topodata\TabletType::MASTER, $not_in_transaction = FALSE)
 {
     if (!$this->inTransaction()) {
         throw new VTException('execute called while not in transaction.');
     }
     $request = new \vtgate\ExecuteEntityIdsRequest();
     $request->setSession($this->session);
     $request->setQuery(VTProto::BoundQuery($query, $bind_vars));
     $request->setTabletType($tablet_type);
     $request->setNotInTransaction($not_in_transaction);
     $request->setKeyspace($keyspace);
     $request->setEntityColumnName($entity_column_name);
     VTProto::addEntityKeyspaceIds($request, $entity_keyspace_ids);
     if ($ctx->getCallerId()) {
         $request->setCallerId($ctx->getCallerId());
     }
     $response = $this->client->executeEntityIds($ctx, $request);
     $this->session = $response->getSession();
     VTProto::checkError($response);
     return new VTCursor($response->getResult());
 }
Esempio n. 4
0
 public function splitQuery(VTContext $ctx, $keyspace, $query, array $bind_vars, $split_column, $split_count)
 {
     $request = new \vtgate\SplitQueryRequest();
     $request->setKeyspace($keyspace);
     $request->setQuery(VTProto::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();
 }
Esempio n. 5
0
 public function testEchoSplitQuery()
 {
     $ctx = $this->ctx;
     $conn = $this->conn;
     $input_bind_vars = array('bytes' => 'hello', 'float' => 1.5, 'int' => 123, 'uint_from_int' => new VTUnsignedInt(345), 'uint_from_string' => new VTUnsignedInt('678'));
     $expected = new \vtgate\SplitQueryResponse\Part();
     $expected->setQuery(VTProto::BoundQuery(self::$ECHO_QUERY . ':split_column:123', $input_bind_vars));
     $krpart = new \vtgate\SplitQueryResponse\KeyRangePart();
     $krpart->setKeyspace(self::$KEYSPACE);
     $expected->setKeyRangePart($krpart);
     $actual = $conn->splitQuery($ctx, self::$KEYSPACE, self::$ECHO_QUERY, $input_bind_vars, 'split_column', 123);
     $this->assertEquals($expected, $actual[0]);
 }