ODBC access is provided by the Data Driver verbs, that are defined in script dd.ijs. First load this file:
The Data Driver verbs may be summarized as follows:
Here, ch refers to a connection handle, and sh a statement handle. Note that SQL commands are not case-sensitive.
r=. ddcnm sh
Column names of selected data
r=. ddcnt '' (available in J Win95 only)
Rowcount of last
r=. 'tdata' ddcol ch
Column names and atrributes in a database
r=. ddcom ch
Commit a transaction (after a
ch=. ddcon 'dsn=jdata'
Connect to ODBC data source name. The result is a connection handle. The argument can set several parameters, separated by semicolons. Some are supported by all databases, and others have a meaning only for specific databases. Parameters recognized by most database systems are:
ODBC data source name
dlg=1 prompts for a connection string with a dialog box with entries for User Id and Password (not supported by the distributed dBase driver)
set to 1 (the default) to use ODBC SQL grammer. Set to 0 to use native database grammer.
set to 1 to force a re-read of a record after an update. This is useful for retrieving auto-updated values such as timestamps.
set to 1 to force a re-read of a record after an insert
r=. dddis ch
Closes connection handle (disconnects from the data source)
r=. ddend sh
Closes statement handle
r=. dderr ''
Return error message on last command. An error message is given when a data driver verb returns _1.
r=. ddfet sh,n
Fetch next records from selected data. Note that after you have read a record, the next fetch will not read it again. If you need to read it again, you must select it again. For example:
fetch next record (same as
fetch next 5 records
fetch all remaining records.
If you fetch all remaining records using
ddfet sh,_1, or if your fetch returns fewer records that you requested (i.e. the fetch reads past the end of the file), then
ddfet closes the statement handle. Otherwise, the statement handle remains open, and you should explicitly close it if you have finished reading the file.
r=. ddfch sh,n (available in J Win95 only)
ddfet, but returns data in columns
r=. ddrbk ch
Discards (rollbacks) a transaction (after a
sh=. 'select * from tdata' ddsel ch
Select data from a database, returning a statement handle
r=. 'create table mydata' ddsql ch
Execute an SQL statement
r=. ddsrc ''
In J Win95:
Data source names available from the ODBC manager.
These names can be used as the dsn= argument to
In J Win31:
a statement handle that can be used with
ddfet to return data source names.
sh=. ddtbl ch
Returns a statement handle for tables in the data source. Some ODBC drivers, including the distributed dBase driver, do not support this service and the result will be empty.
r=. ddtrn ch
Begin a transaction on a connection. Subsequent actions are not committed to the database until a
ddcom is done. Actions since the
ddtrn can be discarded by doing a