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/Func | Remarks |
---|---|
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. |
rc | The latest return code from the underlying ODBC call. Often 0. |
diagnostic | A message related to the underlying ODBC call. Often "" . |
Connector Object Details
Prop/Func | Remarks |
---|---|
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. |
rc | The latest return code from the underlying ODBC call. Often 0. |
diagnostic | A message related to the underlying ODBC call. Often "" . |
DSN | Returns the DSN string, in case you forgot it. |
rowCount | Returns the number of rows that were affected by your non-query statement. (-1 if a query statement) |
colCount | Returns the number of columns in your query statement. |
Statement Object Details
Prop/Func | Remarks |
---|---|
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. |
rc | The latest return code from the underlying ODBC call. Often 0. |
diagnostic | A message related to the underlying ODBC call. Often "" . |
colCount | Returns the number of columns in your query statement. |
row | Returns the row number (starting at 1) of the just-fetched row. |
Row Object Details
Prop/Func | Remarks |
---|---|
columnName | columnValue |
columnName | columnValue |
... | ... |
Column Object Details
Prop/Func | Remarks |
---|---|
colNumber | The column number: 1 to oStmnt.colCount |
name | The column name. May be "" for unaliased expressions. |
maxLen | The maximum length for this column. |
value | The 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. |