20.11.6 Interactions with foreign calls

You can define your own foreign calls and use them on the underlying OCI descriptors. For this, you need to access the OCI handles using
ora-lob-lob-locator
, and maybe
ora-lob-env-handle
and
ora-lob-svc-ctx-handle
. These accessors return foreign pointers that can be passed to foreign functions in the usual way.

When the foreign functions deal only with the data, rather than with LOB objects, use the functions
ora-lob-read-foreign-buffer
,
ora-lob-write
-
foreign-buffer
and
ora-lob-get-buffer
.

For example:

;;; You have a C function my_lob_processor

;;; int my_lob_processor(OCILobLocator *lob,

;;; OCISvcCtx *Context,

;;; int other_arg)

(fli:define-foreign-function my-lob-processor

((lob sql:p-oci-lob-locator)

(env sql:p-oci-svc-ctx)

(other-arg :int))

:result-type :int)

Assuming you have the LOB locator in the variable
lob
, call the foreign function on it:

(my-lob-processor (sql:ora-lob-lob lob
)

(sql:ora-lob-svc-ctx-handle lob
)

36)

There are three handles in the LOB: the LOB descriptor itself, the environment and the context. The pointer types, the reader and the corresponding C type for each handle are shown in Handles in the LOB locator below..

Handles in the LOB locator

OCI handle

Reader

Pointer type

C type

LOB
descriptor

ora-lob-lob-locator

p-oci-lob-locator
or
p-oci-file

OCILobLocator*

context

ora-lob-svc-ctx-handle

p-oci-svc-ctx

OCISvcCtx*

environment

ora-lob-env-handle

p-oci-env

OCIEnv*

The
p-oci-lob-locator
pointer type is used for internal LOBs (that is, BLOB, CLOB and NCLOB). The
p-oci-file
pointer type is used for file LOBs (CFILE and BFILE). For functions that take both, the type
p-oci-lob-or-file
is defined as the union of these two types