User Tools

Site Tools

Navigation:  Language Reference > 13 - Built-in Functions >====== SQLCALLBACK (register or unregister a SQLCallBackInterface) ====== Previous pageReturn to chapter overviewNext page


SQLCALLBACK(entity, SQLCallBackInterface, [flag])


SQLCALLBACK Register or unregister a SQLCallBackInterface.
entity The label of a FILE or VIEW.
SQLCallBackInterface The label of the interface that implements the SQLCallBackInterface. The method of the SQLCallbackInterface (ExecutingCode) is called just before the SQL statement is passed to the SQL server for execution.
flag An integer constant, variable, EQUATE, or expression that indicates whether or not to unregister an interface accociated with a FILE or VIEW. A value of one (1 or TRUE) unregisters the interface. If omitted, the interface is registered with the entity.

The SQLCallback method registers a callback interface with the specified entity. The methods of the registered interface are called whenever a file operation is done. Multiple interfaces can be registered with an entity.

To unregister an interface, set the flag to TRUE. Any registered interfaces must be unregistered before the object that implements the interface is removed.

Implementation: This function is only supported by the SQL drivers.






!Data file



KeyLastName  KEY(PEO:LastName),DUP,NOCASE

Record       RECORD,PRE()

Id            LONG

FirstName     STRING(30)

LastName      STRING(30)

Gender        LONG




SQLFile  FILE,DRIVER('MSSQL'),OWNER('(local),clarion,sa,;'),NAME('sptesttable')

Record    RECORD

Id         LONG





Record    RECORD

Operation  STRING(200)



!FileCallback implementation

FCB CLASS,IMPLEMENTS(FileCallBackInterface),IMPLEMENTS(SQLCallBackInterface)



   CALLBACK(People,FCB.FileCallBackInterface)             !Register Interface

  SQLCALLBACK(SQLFile,FCB.SQLCallBackInterface)          !Register Interface

   CREATE(Logfile)                                        !Create log file

   OPEN(Logfile)                                          !Open log file

   OPEN(People)                                           !Open data file

   SET(PEO:KeyId, PEO:KeyID)                              !Set and

   LOOP                                                   !loop thru

     NEXT(People)                                         !data until

     IF ERRORCODE() THEN BREAK END                        !end of file


   CLOSE(People)                                          !Close data file

   SQLFile{PROP:SQL} = 'CREATE TABLE sptesttable (c INT)' !Create SQL table

   OPEN(SQLFile)                                          !Open SQL table


   ADD(SQLFile)                                           !Update SQL table


   ADD(SQLFile)                                           !Update SQL table


   ADD(SQLFile)                                           !Update SQL table

   CLOSE(SQLFile)                                         !Close SQL table

   CALLBACK(People,FCB.FileCallBackInterface, TRUE)       !Unregister Interface

  SQLCALLBACK(SQLFile,FCB.SQLCallBackInterface, TRUE)    !Unregister Interface

!This method is called prior to each operation of the data file. The log file is updated

!with the file operation that is being executed.

FCB.FileCallBackInterface.FunctionCalled |

   PROCEDURE(SIGNED opCode, *Params Parameters, *CSTRING ErrCode, *CSTRING ErrMsg)

p LIKE(Params)


   p = Parameters

   CASE opCode

   OF DriverOp:ADD

     logFile.Operation = 'ADD(f)'

   OF DriverOp:APPEND

     logFile.Operation = 'APPEND(f)'

   OF DriverOp:CLOSE

     logFile.Operation = 'CLOSE(f)'

   OF DriverOp:COPY

     logFile.Operation = 'COPY(f,'&CLIP(Parameters.Text)&')'

   OF DriverOp:CREATE

     logFile.Operation = 'CREATE(f)'

   OF DriverOp:DELETE

     logFile.Operation = 'DELETE(f)'

   OF DriverOp:NEXT

     logFile.Operation = 'NEXT(f)'

   OF DriverOp:OPEN

     logFile.Operation = 'OPEN(f,'&Parameters.openMode&')'

   OF DriverOp:PUT

     logFile.Operation = 'PUT(f)'

   OF DriverOp:SETkeykey

     logFile.Operation = 'SET(k,k)'




!This method is called after each operation to the data file. This simply returns a TRUE !according to the rules of the FileCallBackInterface.

FCB.FileCallBackInterface.FunctionDone |

   PROCEDURE(SIGNED opCode, Params Parameters, *CSTRING ErrCode, *CSTRING ErrMsg)



!This method is called just before the SQL statement is passed to the SQL server for !execution

FCB.SQLCallBackInterface.ExecutingCode |



   Err = FALSE

   RETURN inStrPUT_re_write_record

sqlcallback_register_or_unregister_a_sqlcallbackinterface.htm.txt · Last modified: 2021/04/15 15:57 by