On this Page

    The API

    The API is deliberately simple. The normal flow is as follows:

    var oConn  = _odbc.connect("MyDSN");
    var oStmnt = oConn.exec("select * from MyTable where ...");
    while (true) {
        var oRow = oStmnt.fetchRow();
        if (oRow == null) break;
        // User code to examine oRow.columnName as desired
    }
    oStmnt.close();
    oConn.disconnect();
    _odbc.term();

    If you prefer to do individual column access you could use:

    ...
    while (true) {
        var rc = oStmnt.fetch();     // fetch, not fetchRow
        if (rc != 0) break;          // at end-of-fetch it will be ODBC standard 100
        var oCol = oStmnt.col(3);    // or some column number ... or
        var oCol = oStmnt.col(colName);
        // User code to examine oCol.value
    }
    ...

    _odbc Object Details

    Prop/FuncRemarks
    init()Initialize the ODBC system, get "handles" etc. In practice, this is not called explicitly since any .connect call will invoke it as needed.
    connect(DSN)Connect to the database as identified by the DSN which you setup previously using an ODBC Administrator tool. Returns a connector object or null on failure (see rc).
    term()Close off all ODBC access. Close all statements. Disconnect all connections. Release all ODBC handles.
    rcThe latest return code from the underlying ODBC call. Often 0.
    diagnosticA message related to the underlying ODBC call. Often "".

    Connector Object Details

    Prop/FuncRemarks
    exec(SQL)Execute an SQL statement on this connection. Returns a statement object or null. Non-query statements return null. Check rc.
    disconnect()Disconnect from this connection. Close any statements. Free resources.
    rcThe latest return code from the underlying ODBC call. Often 0.
    diagnosticA message related to the underlying ODBC call. Often "".
    DSNReturns the DSN string, in case you forgot it.
    rowCountReturns the number of rows that were affected by your non-query statement. (-1 if a query statement)
    colCountReturns the number of columns in your query statement.

    Statement Object Details

    Prop/FuncRemarks
    fetch()Advances to the next row in the query result. Returns a return code. 0 - Ok, 100 - end-of-fetch, else a standard ODBC error code.
    col(col#OrName)Returns a column object or null if there is no such column. Column numbers go from 1 to colCount.
    fetchRow()Advances to the next row in the query result and constructs and returns a row object with the column names and values. Returns null on end-of-fetch.
    close()Free any ODBC resources related to this statement.
    rcThe latest return code from the underlying ODBC call. Often 0.
    diagnosticA message related to the underlying ODBC call. Often "".
    colCountReturns the number of columns in your query statement.
    rowReturns the row number (starting at 1) of the just-fetched row.

    Row Object Details

    Prop/FuncRemarks
    columnNamecolumnValue
    columnNamecolumnValue
    ......

    Column Object Details

    Prop/FuncRemarks
    colNumberThe column number: 1 to oStmnt.colCount
    nameThe column name. May be "" for unaliased expressions.
    maxLenThe maximum length for this column.
    valueThe value of this column. Known only after a fetch is done. The other properties are known as soon as the connector object executes the statement.