sqlite_fetch_field

mIRC SQLite

sqlite_fetch_field
Fetches and returns the specified column of the current row from a result and then advances to the next row.
Syntax
$sqlite_fetch_field ( result, field [, &binvar; ] ) [ .name ]
Parameters
result
The result identifier.
field
The field index or name. See remarks for details.
binvar
The name of the binary variable to assign binary data to. Optional.
Properties
name
Forces field to be treated as name.
Return Value
The value of the specified column of the fetched row if &binvar; isn't specified, otherwise the size of the binary variable on success, $null if there are no more rows, or if there was an error.
Remarks
$sqlite_fetch_field is identical to $sqlite_fetch_single with the only difference being that $sqlite_fetch_field returns a value of specified column, instead of the first column.

If field is numeric it is treated as an ordinal index for the column, first column being 1, otherwise it is treated as the column's name. You can use the .name property to force the field to be treated as column name even if it's a number.

See $sqlite_fetch_single for more details.
Example
; This code assumes a connection is already established and stored in %db
var %sql = SELECT 1, 'test' AS '1'
var %res = $sqlite_query(%db, %sql)
if (%res) {
  ; This treats 1 as field ordinal, thus first column is returned
  echo -a Fetch 1st field: $sqlite_fetch_field(%res, 1)
  ; Go back to previous row because $sqlite_fetch_field increments row counter
  sqlite_rewind %res
  ; This treats 1 as field nane because of the .name property, second column is returned
  echo -a Fetch 2nd field: $sqlite_fetch_field(%res, 1).name
  ; Free result
  sqlite_free %res
}
else {
  echo -a Error executing query: %sqlite_errstr
}

; Output:
; Fetch 1st field: 1
; Fetch 2nd field: a