Container for an AQL query

Optional bind parameters can be used when issuing the AQL query to separate the query from the values. Executing a query will result in a cursor being created.

There is an important distinction between two different types of statements:

  • statements that produce an array of documents as their result AND
  • statements that do not produce documents

For example, a statement such as "FOR e IN example RETURN e" will produce an array of documents as its result. The result can be treated as an array of documents, and each document can be updated and sent back to the server by the client.

However, the query "RETURN 1 + 1" will not produce an array of documents as its result, but an array with a single scalar value (the number 2). "2" is not a valid document so creating a document from it will fail.

To turn the results of this query into a document, the following needs to be done:

  • modify the query to "RETURN { value: 1 + 1 }". The result will then be a an array of documents with a "value" attribute
  • use the "_flat" option for the statement to indicate that you don't want to treat the statement result as an array of documents, but as a flat array
package ArangoDBClient
since 0.2

 Methods

Initialise the statement

__construct(\ArangoDBClient\Connection $connection, array $data) 

The $data property can be used to specify the query text and further options for the query.

An important consideration when creating a statement is whether the statement will produce a list of documents as its result or any other non-document value. When a statement is created, by default it is assumed that the statement will produce documents. If this is not the case, executing a statement that returns non-documents will fail.

To explicitly mark the statement as returning non-documents, the '_flat' option should be specified in $data.

Parameters

$connection

\ArangoDBClient\Connection
  • the connection to be used

$data

array
  • statement initialization data

Exceptions

\ArangoDBClient\Exception

Invoke the statement

__invoke(mixed $args) : \ArangoDBClient\Cursor

This will simply call execute(). Arguments are ignored.

Parameters

$args

mixed
  • arguments for invocation, will be ignored

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\Cursor- the result cursor

Return a string representation of the statement

__toString() : string

Returns

string- the current query string

Bind a parameter to the statement

bind(mixed $key, mixed $value = null) : void

This method can either be called with a string $key and a separate value in $value, or with an array of all bind bind parameters in $key, with $value being NULL.

Allowed value types for bind parameters are string, int, double, bool and array. Arrays must not contain any other than these types.

Parameters

$key

mixed
  • name of bind variable OR an array of all bind variables

$value

mixed
  • value for bind variable

Exceptions

\ArangoDBClient\Exception

Execute the statement

execute() : \ArangoDBClient\Cursor

This will post the query to the server and return the results as a Cursor. The cursor can then be used to iterate the results.

Exceptions

\ArangoDBClient\Exception

Returns

\ArangoDBClient\Cursor

Explain the statement's execution plan

explain() : array

This will post the query to the server and return the execution plan as an array.

Exceptions

\ArangoDBClient\Exception

Returns

array

Get the batch size for the statement

getBatchSize() : integer

Returns

integer- current batch size value

Get all bind parameters as an array

getBindVars() : array

Returns

array- array of bind variables/values

Get the caching option value of the statement

getCache() : boolean

Returns

boolean- current value of 'cache' option

Get the count option value of the statement

getCount() : boolean

Returns

boolean- current value of count option

Get the configured value for fail-on-warning

getFailOnWarning() : boolean

Returns

boolean- current value of fail-on-warning option

Get the full count option value of the statement

getFullCount() : boolean

Returns

boolean- current value of full count option

Get the configured memory limit for the statement

getMemoryLimit() : integer

Returns

integer- current value of memory limit option

Get the query string

getQuery() : string

Returns

string- current query string value

Get the streaming option value of the statement

getStream() : boolean

Returns

boolean- current value of stream option

Get the ttl option value of the statement

getTtl() : double

Returns

double- current value of ttl option

Set the batch size for the statement

setBatchSize(integer $value) : void

The batch size is the number of results to be transferred in one server round-trip. If a query produces more results than the batch size, it creates a server-side cursor that provides the additional results.

The server-side cursor can be accessed by the client with subsequent HTTP requests.

Parameters

$value

integer
  • batch size value

Exceptions

\ArangoDBClient\ClientException

Set the caching option for the statement

setCache(boolean $value) : void

Parameters

$value

boolean
  • value for 'cache' option

Set the count option for the statement

setCount(boolean $value) : void

Parameters

$value

boolean
  • value for count option

Sets the document class to use

setDocumentClass(string $class) : \ArangoDBClient\Statement

Parameters

$class

string

Document class to use

Returns

\ArangoDBClient\Statement

Set whether or not the cache should abort when it encounters a warning

setFailOnWarning(boolean $value = true) : void

Parameters

$value

boolean
  • value for fail-on-warning

Set the full count option for the statement

setFullCount(boolean $value) : void

Parameters

$value

boolean
  • value for full count option

Set the approximate memory limit threshold to be used by the query on the server-side (a value of 0 or less will mean the memory is not limited)

setMemoryLimit(integer $value) : void

Parameters

$value

integer
  • value for memory limit

Set the query string

setQuery(string $query) : void

Parameters

$query

string
  • query string

Exceptions

\ArangoDBClient\ClientException

setResultType

setResultType($resultType) : string

Parameters

$resultType

Returns

string- resultType of the query

Set the streaming option for the statement

setStream(boolean $value) : void

Parameters

$value

boolean
  • value for stream option

Set the ttl option for the statement

setTtl(double $value) : void

Parameters

$value

double
  • value for ttl option

Validates the statement

validate() : array

This will post the query to the server for validation and return the validation result as an array.

Exceptions

\ArangoDBClient\Exception

Returns

array

Return the connection object

getConnection() : \ArangoDBClient\Connection

Returns

\ArangoDBClient\Connection- the connection object

Build an array of data to be posted to the server when issuing the statement

buildData() : array

Returns

array- array of data to be sent to server

Return an array of cursor options

getCursorOptions() : array

Returns

array- array of options

 Properties

 

$_documentClass

$_documentClass 

Default

 

The current batch size (number of result documents retrieved per round-trip)

$_batchSize : mixed

Default

 

The bind variables and values used for the statement

$_bindVars : \ArangoDBClient\BindVars

Default

 

Whether or not the query cache should be consulted

$_cache : boolean

Default

 

The connection object

$_connection : \ArangoDBClient\Connection

Default

 

The count flag (should server return total number of results)

$_doCount : boolean

Default

false
 

Whether or not the cache should abort when it encounters a warning

$_failOnWarning : boolean

Default

false
 

"flat" flag (if set, the query results will be treated as a simple array, not documents)

$_flat : boolean

Default

false
 

The count flag (should server return total number of results ignoring the limit) Be careful! This option also prevents ArangoDB from using some server side optimizations!

$_fullCount : boolean

Default

false
 

Approximate memory limit value (in bytes) that a query can use on the server-side (a value of 0 or less will mean the memory is not limited)

$_memoryLimit : integer

Default

0
 

The query string

$_query : string

Default

 

Number of retries in case a deadlock occurs

$_retries : boolean

Default

0
 

Sanitation flag (if set, the _id and _rev attributes will be removed from the results)

$_sanitize : boolean

Default

false
 

Whether or not the query results should be build up dynamically and streamed to the client application whenever available, or build up entirely on the server first and then streamed incrementally (false)

$_stream : boolean

Default

 

transaction id (used internally)

$_trxId : string

Default

null
 

Number of seconds the cursor will be kept on the server if the statement result is bigger than the initial batch size. The default value is a server-defined value

$_ttl : double

Default

 

resultType

$resultType : string

Default

 Constants

 

Batch size index

ENTRY_BATCHSIZE = 'batchSize' 
 

Bind variables index

ENTRY_BINDVARS = 'bindVars' 
 

Count option index

ENTRY_COUNT = 'count' 
 

Fail on warning flag

ENTRY_FAIL_ON_WARNING = 'failOnWarning' 
 

Memory limit threshold for query

ENTRY_MEMORY_LIMIT = 'memoryLimit' 
 

Query string index

ENTRY_QUERY = 'query' 
 

Retries index

ENTRY_RETRIES = 'retries' 
 

Stream attribute

ENTRY_STREAM = 'stream' 
 

transaction attribute (used internally)

ENTRY_TRANSACTION = 'transaction' 
 

TTL attribute

ENTRY_TTL = 'ttl' 
 

Full count option index

FULL_COUNT = 'fullCount'