A newer version of Max is available. Click here to access the latest version of the Max documentation

The SQLResult Object

An SQLResult object is a container for results obtained in an SQLite.exec call. Not every exec() call will produce results, but any database query (SELECT in particular) will generate an SQLResult object even if the result is empty.

SQLResult Constructor

var res = new SQLResult()

No arguments are required for the constructor.

SQLResult Methods

All data from the SQLResult object is retrieved using object methods.

SQLResult Methods

numrecords

Returns the number of records that were returned in the SQLResult object.

numfields

Returns the number of fields in the dataset returned in the SQLResult object.

fieldname

Arguments

index [Number]

Returns the name of a column at the requested index.

value

Arguments

index [Number]
record_no [Number]

Returns the value of the column identified by index, and in the record identified by record_no.

Example:

function print_everything(sqlres) {
  var numrecs = sqlres.numrecords()
  var numflds = sqlres.numfields()

  var field_names = new Array()
  for (var i = 0; i < numflds; i++) {
    field_names[i] = sqlres.fieldname(i)
  }

  for (var i = 0; i < numrecs; i++) {
    for (var j = 0; j < numflds; j++) {
      post(
        "Rec: ",
        i,
        " field ",
        field_names[j],
        " value ",
        sqlres.value(j, i),
        "\n"
      )
    }
  }
}

See Also

Name Description
JavaScript Usage JavaScript Usage