Esempio n. 1
0
 /**
  * @return array|bool
  * @throws Exception
  */
 public function next()
 {
     if ($this->rows && ++$this->pos < count($this->rows)) {
         return ProtoUtils::RowValues($this->rows[$this->pos], $this->getFields());
     } else {
         return FALSE;
     }
 }
Esempio n. 2
0
 public function testRowValues()
 {
     $row = new Proto\Query\Row();
     $row->setValues('onethree');
     $row->setLengths([3, -1, 5, 0]);
     $fields = [make_field('c1'), make_field('c2'), make_field('c3'), make_field('c4')];
     $expected = [0 => 'one', 1 => null, 2 => 'three', 3 => '', 'c1' => 'one', 'c2' => null, 'c3' => 'three', 'c4' => ''];
     $actual = ProtoUtils::RowValues($row, $fields);
     $this->assertEquals($expected, $actual);
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
 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(ProtoUtils::BoundShardQuery($query, self::$BIND_VARS, self::$KEYSPACE, self::$SHARDS)), self::$TABLET_TYPE, TRUE);
     });
     $this->checkTransactionExecuteErrors(function ($ctx, $tx, $query) {
         $tx->executeBatchKeyspaceIds($ctx, array(ProtoUtils::BoundKeyspaceIdQuery($query, self::$BIND_VARS, self::$KEYSPACE, self::$KEYSPACE_IDS)), self::$TABLET_TYPE, TRUE);
     });
 }
Esempio n. 6
0
 public function executeBatchKeyspaceIds(Context $ctx, array $bound_keyspace_id_queries, $tablet_type = Proto\Topodata\TabletType::MASTER)
 {
     if (!$this->inTransaction()) {
         throw new \Vitess\Exception('execute called while not in transaction.');
     }
     $request = new Proto\Vtgate\ExecuteBatchKeyspaceIdsRequest();
     $request->setSession($this->session);
     ProtoUtils::addQueries($request, $bound_keyspace_id_queries);
     $request->setTabletType($tablet_type);
     if ($ctx->getCallerId()) {
         $request->setCallerId($ctx->getCallerId());
     }
     $response = $this->client->executeBatchKeyspaceIds($ctx, $request);
     $this->session = $response->getSession();
     ProtoUtils::checkError($response);
     $results = array();
     foreach ($response->getResultsList() as $result) {
         $results[] = new Cursor($result);
     }
     return $results;
 }