>>  <<  Ndx  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  wd  Help  User

Data Driver

ODBC access is provided by the Data Driver verbs, that are defined in script dd.ijs. First load this file:

   load 'dd'

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.

ddcnm r=. ddcnm sh
Column names of selected data

ddcnt r=. ddcnt '' (available in J Win95 only)
Rowcount of last ddsql command

ddcol r=. 'tdata' ddcol ch
Column names and atrributes in a database

ddcom r=. ddcom ch
Commit a transaction (after a ddtrn)

ddcon 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:

dsn

ODBC data source name

dlg

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)

uid

user name

pwd

user password

modifysql

set to 1 (the default) to use ODBC SQL grammer. Set to 0 to use native database grammer.

rereadafterupdate

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.

rereadafterinsert

set to 1 to force a re-read of a record after an insert
For example:
ch=. ddcon'dsn=mydata;uid=george;pwd=sesame'

dddis r=. dddis ch
Closes connection handle (disconnects from the data source)

ddend r=. ddend sh
Closes statement handle

dderr r=. dderr ''
Return error message on last command. An error message is given when a data driver verb returns _1.

ddfet 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:

r=. ddfet sh

fetch next record (same as ddfet sh,1)

r=. ddfet sh,5

fetch next 5 records

r=. ddfet sh,_1

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.

ddfch r=. ddfch sh,n (available in J Win95 only)
As ddfet, but returns data in columns

ddrbk r=. ddrbk ch
Discards (rollbacks) a transaction (after a ddtrn)

ddsel sh=. 'select * from tdata' ddsel ch
Select data from a database, returning a statement handle

ddsql r=. 'create table mydata' ddsql ch
Execute an SQL statement

ddsrc r=. ddsrc ''
In J Win95:
Data source names available from the ODBC manager.
These names can be used as the dsn= argument to ddcon.

In J Win31:
a statement handle that can be used with ddfet to return data source names.

ddtbl 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.

ddtrn 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 ddrbk (rollback).


>>  <<  Ndx  Usr  Pri  JfC  LJ  Phr  Dic  Rel  Voc  !:  wd  Help  User