3. The Query Class

3.1. Query Documentation

Table A.3, “Query Methods” contains the exhaustive list of methods, in alphabetical order. The documentation of each method follows.

Table A.3. Query Methods

TypeNameArgs
method at() 1
method clear() 0
method isNull?() 1
method isValid?() 0
method exec() 1
method each() 0
method []() 1
method () 0
method moveFirst() 0
method moveNext() 0
method moveLast() 0
method moveNext() 0
method movePrevious() 0
method row() 1
method rows() 0
method rowsAffected() 0
method seek() 1
method single() 1
method value() 1


method: at()

at() returns the index of where the cursor currently is in the result set.

method: clear()

clear() clears resources related to the query.

method: isNull?()

isNull?() Returns true if the query is active and positioned on a valid record and the field is NULL; otherwise returns false. Note that for some drivers, isNull() will not return accurate information until after an attempt is made to retrieve data.

Definition

def isNull?(index)

  • index: the column index.

method: isValid?()

isValid?() returns true if the query is currently positioned on a valid record; otherwise returns false.

method: exec()

exec() executes SQL. Returns true and sets the query state to active if the query was successful; otherwise returns false. The query string must use syntax appropriate for the SQL database being queried (for example, standard SQL). After the query is executed, the query is positioned on the first record.

Note that the last error for this query is reset when exec() is called.

Definition

def exec(sql)

  • sql: the SQL to execute.

method: each()

each() iterates over the result set, yielding a record at a time..

method: []()

[]() returns the record at the specified index. The row() method is an alias for this method.

Definition

def [](index)

  • index: the index of the record to returm.

method: error()

error() returns a string containing the last error.

method: moveFirst()

moveFirst() moves the cursor to the first record.

method: moveLast()

moveLast() moves the cursor to the last record.

method: moveNext()

moveNext() moves the cursor to the next record.

method: movePrevious()

movePrevious() moves the cursor to the previous record.

method: rows()

rows() returns the number of rows in the result set.

method: rowsAffected()

rowsAffected() returns the number of rows affected in a modifying SQL statement (e.g. UPDATE or DELETE). set.

method: seek()

seek() moves the cursor to the given index. Returns true if the seek was positioned on a valid record, false otherwise. If you seek beyond the end of the set, the cursor will be position will be invalid and called to row() will return nil.

Definition

def seek(index)

  • index: the index of the record to returm.

method: single()

single() is like but it returns the first record of the result set.

Definition

def single(sql)

  • sql: the SQL to execute.

method: value()

value() returns the field value of current record given by the index.

Definition

def value(index)

  • index: the column ordinal of the value to return.