oratcl - Tcl 9 interface to Oracle via ODPI-C 5.6.2
oralogon  connect-string ?-pool min max incr? ?-homogeneous 0|1? ?-getmode wait|nowait|force?
oralogoff logon-handle
oraopen   logon-handle           # open a statement handle
orastmt   logon-handle           # alias of oraopen
oraclose  statement-handle
oraparse  statement-handle sql-text
orasql    statement-handle sql-text ?-parseonly? ?-commit?
oraplexec statement-handle {pl/sql block} ?-commit?
oraexec   statement-handle ?-commit?
orabind      statement-handle :name value ? :name value ... ?
orabindexec  statement-handle ?-commit? ?-arraydml? :name list ...
orafetch statement-handle
         ?-datavariable varName?
         ?-dataarray arrayName?
         ?-indexbyname|-indexbynumber?
         ?-command script?
         ?-max N?
         ?-resultvariable varName?
         ?-returnrows?
         ?-asdict?
oracols statement-handle
oradesc statement-handle           # {name type} pairs
oramsg  handle rc|error|rows|peo|ocicode|sqltype|fn|action|sqlstate|recoverable|warning|offset|all|allx
oralob  size|read|write|trim|close lob-handle ?args...?
oraautocommit logon-handle 0|1
oracommit    logon-handle
orarollback  logon-handle
orabreak     logon-handle         # cancel active call
oraexecasync  statement-handle ?-commit?
orawaitasync  statement-handle ?-timeout milliseconds?
oratcl 9.0 implements the classic Oratcl API on top of ODPI-C (no OCI). It targets Tcl 9: command signatures use Tcl_Size and are thread/multi-interp safe. One ODPI context is created per process; per-interp state (handles, registries) is created on each load. Async execution uses per-statement workers with proper addRef/release of underlying dpi handles.
"-pool Create/acquire via session pool.
"-homogeneous Homogeneous pool (default 1).
"-getmode Pool get mode.
Returns a logon-handle (e.g. "oraL1").
Connect using either username/password@connect_identifier, or external auth (leave user/pw empty). Options:
Close the connection (see ORA_MSG behavior for error reporting).
Set autocommit. DML/PLSQL commit on success when enabled or when -commit is supplied to exec commands.
Return a dict with the current connection info. Currently it returns autocommit only.
Open a statement handle.
Parse and, unless -parseonly, execute once. Clears the per-statement stored-bind cache if text changes.
Execute the already-parsed statement (single execution).
Prepare and execute a PL/SQL block.
Bind scalars by name. LOB type is inferred by name and/or value representation.
Array DML with name→list pairs. BYTES elements are copied to private buffers to remain stable until executeMany().
Fetches up to -max N rows and returns 0 while data remains, or 1403 at end-of-data. Use -returnrows or -resultvariable to obtain a list of rows; -asdict returns dicts keyed by column names.
Return column names of the current query.
Return {name type} pairs.
Read as a bytearray. When inlineLobs is enabled at the connection, orafetch returns raw data instead of handles.
Begin execution in a worker thread. The worker holds addRef() on the underlying dpi handles.
Wait for completion or timeout. On completion, temp LOBs created by orabind are released.
Use oraconfig on a logon-handle or a statement-handle.
Connection-level keys:
stmtcachesize, fetcharraysize, prefetchrows, prefetchmemory, calltimeout (ms),
inlineLobs (0/1), and failover policy: foMaxAttempts, foBackoffMs, foBackoffFactor,
foErrorClasses, foDebounceMs, -failovercallback.
Statement-level keys:
fetchrows, prefetchrows (overrides connection defaults when the statement exists).
Basic select:
set L [oralogon "scott/tiger@//dbhost/pdb"]
set S [oraopen $L]
oraparse $S {select empno, ename from emp where deptno = :d}
orabind  $S :d 10
oraexec  $S
set rows {}
while 1 {
    set rc [orafetch $S -asdict -datavariable row]
    if {$rc == 1403} break
    lappend rows [dict get $row EMPNO] [dict get $row ENAME]
}
oraclose $S
oralogoff $L
Array DML:
set S [oraopen $L]
oraparse $S {insert into t(x,y) values(:x,:y)}
orabindexec $S -commit -arraydml :x {1 2 3} :y {A B C}
Async:
oraparse $S {begin dbms_lock.sleep(2); end;}
oraexecasync $S
# do other work...
orawaitasync $S -timeout 3000
The test suite uses ORATCL_CONNECT for the connect string.
One global ODPI context is created lazily and destroyed on process exit.
Each interpreter has isolated handle registries. When statically linked into tclsh, every interp calls oratcl_Init; the driver ensures client libraries are loaded only once.
↑ Top