class Query implements Iterator

Abstract query-result class. A query result provides an iterator that returns a map for each record of a query result.

The map should be keyed by the column names, and the values should use the following types:

  • boolean returned as integer 1 or 0 (to ensure consistency with MySQL that doesn't have native booleans)
  • integer types returned as integers
  • floating point / decimal types returned as floats
  • strings returned as strings
  • dates / datetimes returned as strings

Note that until SilverStripe 4.3, bugs meant that strings were used for every column type.

Once again, this should be subclassed by an actual database implementation. It will only ever be constructed by a subclass of SS_Database. The result of a database query - an iteratable object that's returned by DB::SS_Query

Primarily, the Query class takes care of the iterator plumbing, letting the subclasses focusing on providing the specific data-access methods that are required: {@link nextRecord()}, {@link numRecords()} and {@link seek()}

Methods

array
column(string $column = null)

Return an array containing all the values from a specific column. If no column is set, then the first will be returned

array
keyedColumn()

Return an array containing all values in the leftmost column, where the keys are the same as the values.

array
map()

Return a map from the first column to the second column.

array
record()

Returns the next record in the iterator.

string
value()

Returns the first column of the first record.

string
table()

Return an HTML table containing the full result-set

void
rewind()

Iterator function implementation. Rewind the iterator to the first item and return it.

array
current()

Iterator function implementation. Return the current item of the iterator.

array
first()

Iterator function implementation. Return the first item of this iterator.

int
key()

Iterator function implementation. Return the row number of the current item.

array
next()

Iterator function implementation. Return the next record in the iterator.

bool
valid()

Iterator function implementation. Check if the iterator is pointing to a valid item.

array
nextRecord()

Return the next record in the query result.

int
numRecords()

Return the total number of items in the query result.

array
seek(int $rowNum)

Go to a specific row number in the query result and return the record.

Details

at line 61
array column(string $column = null)

Return an array containing all the values from a specific column. If no column is set, then the first will be returned

Parameters

string $column

Return Value

array

at line 82
array keyedColumn()

Return an array containing all values in the leftmost column, where the keys are the same as the values.

Return Value

array

at line 97
array map()

Return a map from the first column to the second column.

Return Value

array

at line 113
array record()

Returns the next record in the iterator.

Return Value

array

at line 123
string value()

Returns the first column of the first record.

Return Value

string

at line 137
string table()

Return an HTML table containing the full result-set

Return Value

string

at line 173
void rewind()

Iterator function implementation. Rewind the iterator to the first item and return it.

Makes use of {@link seek()} and {@link numRecords()}, takes care of the plumbing.

Return Value

void

at line 187
array current()

Iterator function implementation. Return the current item of the iterator.

Return Value

array

at line 201
array first()

Iterator function implementation. Return the first item of this iterator.

Return Value

array

at line 212
int key()

Iterator function implementation. Return the row number of the current item.

Return Value

int

at line 223
array next()

Iterator function implementation. Return the next record in the iterator.

Makes use of {@link nextRecord()}, takes care of the plumbing.

Return Value

array

at line 236
bool valid()

Iterator function implementation. Check if the iterator is pointing to a valid item.

Return Value

bool

at line 249
abstract array nextRecord()

Return the next record in the query result.

Return Value

array

at line 256
abstract int numRecords()

Return the total number of items in the query result.

Return Value

int

at line 264
abstract array seek(int $rowNum)

Go to a specific row number in the query result and return the record.

Parameters

int $rowNum Row number to go to.

Return Value

array