This example describes the lang_execute event handler provided in the sample gateway application. This event handler is implemented as a callback function that sends a client's language command to the SQL Server example remote database, receives the results, and returns the results to the client.
int lang_execute(srvproc)
SRV_PROC *srvproc;
{
REMOTE_DBMS *rmt_dbms; // Remote database pointer
DBPROCESS *rmtproc; // Open Data Services DBPROCESS pointer
DBCHAR *query; // Pointer to language buffer
int query_len; // Length of query
int status; // Status of DB-Library calls
rmt_dbms = (REMOTE_DBMS *)srv_getuserdata(srvproc);
rmtproc = rmt_dbms->dbproc;
// Get the pointer to the client language request command buffer.
query = srv_langptr (srvproc);
// Place the pointer in the remote DBPROCESS pointer rmtproc.
status = dbcmd (rmtproc, query);
if (status == SUCCEED) // Previous DB-Library call successful
status = dbsqlexec (rmtproc);
else
// If an attention event was issued or if the previous DB-Library
// call was not successful, acknowledge and send a results
// completion message to the client.
srv_senddone (srvproc, SRV_DONE_FINAL, (DBUSMALLINT) 0,
(DBINT) 0);
handle_results (rmtproc, srvproc);
(For more information about this function, see Receiving Results from a Remote Database.
return (SRV_CONTINUE);