execute() public method

Executes a given statement and returns a result.
public execute ( cassandra\Statement $statement, ExecutionOptions $options = null ) : Rows
$statement cassandra\Statement statement to be executed
$options ExecutionOptions execution options (optional)
return Rows execution result
コード例 #1
0
ファイル: Connector.php プロジェクト: kris-nova/API
 /**
  * Accepts a query string
  *
  * @param string $queryString            
  * @param bool $throw            
  * @throws ApiException
  * @return Cassandra\Rows
  */
 public function query($queryString, $throw = false)
 {
     if (empty($this->cluster) || empty($this->session)) {
         throw new ApiException('Query failure - missing connection stream');
     }
     $query = new Cassandra\SimpleStatement($queryString);
     try {
         $result = $this->session->execute($query);
         return $result;
     } catch (\Cassandra\Exception\RuntimeException $e) {
         LogException::e($e);
         if ($throw) {
             throw new ApiException('Query Failure', r_server);
         }
     }
 }
コード例 #2
0
ファイル: Integration.php プロジェクト: r3nat/php-driver
 public function __destruct()
 {
     // Drop keyspace for integration test (may or may have not been created)
     if (!is_null($this->session)) {
         try {
             $statement = new SimpleStatement('DROP KEYSPACE "' . $this->keyspaceName . '"');
             $this->session->execute($statement);
         } catch (Exception $e) {
             // no-op
         }
     }
 }
コード例 #3
0
 /**
  * Gets column key data, reads data from system.schema_columns
  * Need to have read access to this system table
  * @param   string $columnName
  * @param   string $tableName
  * @param   string $keyspaceName
  * @return  array
  */
 protected function _getColumnKeyData($columnName, $tableName, $keyspaceName)
 {
     $statement = new SimpleStatement('SELECT type FROM system.schema_columns WHERE keyspace_name = ? AND columnfamily_name = ? AND column_name = ?');
     $params = ['consistency' => \Cassandra::CONSISTENCY_LOCAL_ONE, 'arguments' => [$keyspaceName, $tableName, $columnName]];
     $result = $this->_session->execute($statement, new ExecutionOptions($params));
     if ($result[0]['type'] == 'partition_key') {
         return [true, true, false];
     }
     if ($result[0]['type'] == 'clustering_key') {
         return [true, true, true];
     }
     return [false, false, false];
 }
コード例 #4
0
 /**
  * {@inheritDoc}
  */
 public function find($storageName, $key)
 {
     $where = [];
     foreach ($key as $name => $value) {
         $where[] = $name . ' = ?';
     }
     $stmt = $this->session->prepare('SELECT * FROM ' . $storageName . ' WHERE ' . implode(' AND ', $where));
     $options = new ExecutionOptions(['arguments' => array_values($key)]);
     $result = $this->session->execute($stmt, $options);
     $rows = iterator_to_array($result);
     if (!isset($rows[0])) {
         throw new NotFoundException();
     }
     $data = [];
     foreach ($rows[0] as $column => $value) {
         if (isset($key[$column])) {
             continue;
         }
         $data[$column] = $value;
     }
     return $data;
 }