Defines an output variable for a specified select-list item in a SQL query. It is necessary to call this function for each select-list item of a SQL query. After the OdbcExecute and OdbcFetch functions have been called, the OdbcGet functions can be used to retrieve the values of the select-list items:
ODBC.bdh
OdbcDefine( in cCursor : cursor, in sPosition : string, in nDataType : number optional, in nSize : number optional ): boolean;
true if successful
false otherwise
Parameter | Description |
---|---|
cCursor | Cursor associated with a database connection. |
sPosition | Index of the select-list item in the SQL query. Position indices start at 1 for the first (left-most) select-list item. |
nDataType |
ODBC data type of the select-list item (optional). The default value is SQL_C_CHAR. |
nSize | Length of the select-list item in bytes (optional). This parameter should be omitted for data types of fixed length. |
var hEnv, hDbc : number; cCursor : cursor; dcltrans transaction TMain begin OdbcAlloc(SQL_HANDLE_ENV, hEnv); OdbcAlloc(SQL_HANDLE_DBC, hDbc, hEnv); OdbcConnect(hDbc, "DSN=database;UID=user;PWD=pass;"); OdbcOpen(cCursor, hDbc); OdbcPrepare(cCursor, sqlSelect); OdbcExecute(cCursor); OdbcDefine(cCursor, "1", SQL_C_CHAR, 32); OdbcDefine(cCursor, "2", SQL_C_LONG); while OdbcFetch(cCursor) do write("name: " + OdbcGetString(cCursor, "1")); writeln(" age: " + (string)OdbcGetInt(cCursor, "2")); end; OdbcClose(cCursor, SQL_DROP); OdbcCommit(hDbc); OdbcDisconnect(hDbc); OdbcFree(hDbc); OdbcFree(hEnv); end TMain; dclsql sqlSelect: SELECT * FROM persons;