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); }
public function next() { // Get the next row from the current QueryResult. if ($this->rows && ++$this->pos < count($this->rows)) { return VTProto::RowValues($this->rows[$this->pos]); } // Get the next QueryResult. Loop in case we get a QueryResult with no rows (e.g. only fields). while ($this->nextQueryResult()) { // Get the first row from the new QueryResult. if ($this->rows && ++$this->pos < count($this->rows)) { return VTProto::RowValues($this->rows[$this->pos]); } } // No more rows and no more QueryResults. return FALSE; }
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); }
/** * fetch reads and returns the next VTQueryResult from the stream. * * If there are no more results and the stream has finished successfully, * it returns FALSE. */ public function fetch() { $resp = $this->client->streamNext($this->ctx); if ($resp === FALSE) { return FALSE; } VTProto::checkError($resp->reply); return VTQueryResult::fromBsonP3($resp->reply['Result']); }
public function executeBatchKeyspaceIds(VTContext $ctx, array $bound_keyspace_id_queries, $tablet_type = \topodata\TabletType::MASTER, $as_transaction = TRUE) { if (!$this->inTransaction()) { throw new VTException('execute called while not in transaction.'); } $request = new \vtgate\ExecuteBatchKeyspaceIdsRequest(); $request->setSession($this->session); VTProto::addQueries($request, $bound_keyspace_id_queries); $request->setTabletType($tablet_type); $request->setAsTransaction($as_transaction); if ($ctx->getCallerId()) { $request->setCallerId($ctx->getCallerId()); } $response = $this->client->executeBatchKeyspaceIds($ctx, $request); $this->session = $response->getSession(); VTProto::checkError($response); $results = array(); foreach ($response->getResultsList() as $result) { $results[] = new VTCursor($result); } return $results; }
public function testTransactionExecuteErrors() { $this->checkTransactionExecuteErrors(function ($ctx, $tx, $query) { $tx->execute($ctx, $query, self::$BIND_VARS, self::$TABLET_TYPE, TRUE); }); $this->checkTransactionExecuteErrors(function ($ctx, $tx, $query) { $tx->executeShards($ctx, $query, self::$KEYSPACE, self::$SHARDS, self::$BIND_VARS, self::$TABLET_TYPE, TRUE); }); $this->checkTransactionExecuteErrors(function ($ctx, $tx, $query) { $tx->executeKeyspaceIds($ctx, $query, self::$KEYSPACE, self::$KEYSPACE_IDS, self::$BIND_VARS, self::$TABLET_TYPE, TRUE); }); $this->checkTransactionExecuteErrors(function ($ctx, $tx, $query) { $tx->executeKeyRanges($ctx, $query, self::$KEYSPACE, self::$KEY_RANGES, self::$BIND_VARS, self::$TABLET_TYPE, TRUE); }); $this->checkTransactionExecuteErrors(function ($ctx, $tx, $query) { $tx->executeEntityIds($ctx, $query, self::$KEYSPACE, self::$ENTITY_COLUMN_NAME, self::$ENTITY_KEYSPACE_IDS, self::$BIND_VARS, self::$TABLET_TYPE, TRUE); }); $this->checkTransactionExecuteErrors(function ($ctx, $tx, $query) { $tx->executeBatchShards($ctx, array(VTProto::BoundShardQuery($query, self::$BIND_VARS, self::$KEYSPACE, self::$SHARDS)), self::$TABLET_TYPE, TRUE); }); $this->checkTransactionExecuteErrors(function ($ctx, $tx, $query) { $tx->executeBatchKeyspaceIds($ctx, array(VTProto::BoundKeyspaceIdQuery($query, self::$BIND_VARS, self::$KEYSPACE, self::$KEYSPACE_IDS)), self::$TABLET_TYPE, TRUE); }); }
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(); }
private function callExecuteBatch(VTContext $ctx, $queries, $tablet_type, $as_transaction, $method, $req = array()) { $req['Queries'] = $queries; $req['TabletType'] = $tablet_type; $req['AsTransaction'] = $as_transaction; if ($ctx->getCallerId()) { $req['CallerId'] = $ctx->getCallerId()->toBsonP3(); } $resp = $this->client->call($ctx, $method, $req)->reply; VTProto::checkError($resp); $results = array(); foreach ($resp['Results'] as $result) { $results[] = new VTQueryResult($result); } return $results; }