| **Navigation:**  [[introduction.htm|Language Reference]] > 13 - Built-in Functions >====== SQLCALLBACK (register or unregister a SQLCallBackInterface) ====== | [[sql use sql code .htm|{{btn_prev_n.gif|Previous page}}]][[introduction.htm|{{btn_home_n.gif|Return to chapter overview}}]][[sqrt return square root .htm|{{btn_next_n.gif|Next page}}]] | | || {{newc7.jpg|NewC7.jpg}} **SQLCALLBACK**(//entity//, //SQLCallBackInterface//, [//flag//]) {{blk2blue.jpg|blk2blue.jpg}} | **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. **Example:** **PROGRAM** **    MAP** **    END** **    INCLUDE ('FILECB.INC'),ONCE** **!Data file** **People      FILE,DRIVER('TOPSPEED'),PRE(PEO),CREATE,BINDABLE,THREAD** **KeyId        KEY(PEO:Id),NOCASE,OPT** **KeyLastName  KEY(PEO:LastName),DUP,NOCASE** **Record       RECORD,PRE()** **Id            LONG** **FirstName     STRING(30)** **LastName      STRING(30)** **Gender        LONG** **             END** **            END** **!DataFile** **SQLFile  FILE,DRIVER('MSSQL'),OWNER('(local),clarion,sa,;'),NAME('sptesttable')** **Record    RECORD** **Id         LONG** **          END** **         END** **!LogFile** **LogFile  FILE,DRIVER('BASIC','/ALWAYSQUOTE=OFF /COMMA=1,1'),CREATE,NAME('logfile.txt')** **Record    RECORD** **Operation  STRING(200)** **          END** **         END** **!FileCallback implementation** **FCB CLASS,IMPLEMENTS(FileCallBackInterface),IMPLEMENTS(SQLCallBackInterface)** **    END** **    CODE** **    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** **    END** **    CLOSE(People)                                          !Close data file** **    SQLFile{PROP:SQL} = 'CREATE TABLE sptesttable (c INT)' !Create SQL table** **    OPEN(SQLFile)                                          !Open SQL table** **    SQLFile.Id=5** **    ADD(SQLFile)                                           !Update SQL table** **    SQLFile.Id=7** **    ADD(SQLFile)                                           !Update SQL table** **    SQLFile.Id=8** **    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)** **  CODE** **    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)'** **    END** **    ADD(logFile)** **    RETURN TRUE** **!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)** **  CODE** **    RETURN TRUE** **!This method is called just before the SQL statement is passed to the SQL server for !execution** **FCB.SQLCallBackInterface.ExecutingCode |** **    PROCEDURE(CONST *CSTRING inStr, *BYTE Err, *CSTRING ErrCode, *CSTRING ErrMsg)** **  CODE** **    Err = FALSE** **    RETURN inStrPUT_re_write_record**