ct_send

Description

Send a command to the server.

Syntax

CS_RETCODE ct_send(cmd)
 
 CS_COMMAND     *cmd;

Parameters

cmd

A pointer to the CS_COMMAND structure managing a client/server operation.

Returns

ct_send returns the following values:

Return value

Meaning

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

For less serious failures, the application can call ct_cancel(CS_CANCEL_ALL) to clean up the command structure.

For more serious failures, the application must call ct_close(CS_FORCE_CLOSE) to force the connection closed.

CS_CANCELED

The routine was canceled.

CS_PENDING

Asynchronous network I/O is in effect. See “Asynchronous programming”.

CS_BUSY

An asynchronous operation is already pending for this connection. See “Asynchronous programming”.

Common causes of ct_send failure include results-pending errors and attempts to send a command that has not been initiated.

Examples

Example 1

The following fragment declares a function that sends a language command and processes the results. The code assumes that the command returns no fetchable results.

          /*
           ** ex_execute_cmd()
           */
          CS_RETCODE      CS_PUBLIC
           ex_execute_cmd(connection, cmdbuf)
           CS_CONNECTION   *connection;
           CS_CHAR         *cmdbuf;
           {
                CS_RETCODE   retcode;
                CS_INT       restype;
                CS_COMMAND   *cmd;
                CS_RETCODE   query_code;
               /*
                ** Get a command handle, store the command string 
                ** in it, and send it to the server.
                */
                if ((retcode = ct_cmd_alloc(connection, &cmd)) !=
                      CS_SUCCEED)
                {
                     ex_error("ex_execute_cmd: ct_cmd_alloc() \ 
                          failed");
                     return retcode;
                }
               if ((retcode = ct_command(cmd, CS_LANG_CMD, 
                     cmdbuf, CS_NULLTERM, CS_UNUSED)) !=
                     CS_SUCCEED)
                {
                     ex_error("ex_execute_cmd: ct_command() \ 
                          failed");
                     (void)ct_cmd_drop(cmd);
                     return retcode;
                }
               if ((retcode = ct_send(cmd)) != CS_SUCCEED)
                {
                     ex_error("ex_execute_cmd: ct_send() failed");
                     (void)ct_cmd_drop(cmd);
                     return retcode;
                }
               /*
                ** Examine the results coming back. If any errors 
                ** are seen, the query result code (which we will 
                ** return from this function) will be set to FAIL.
                */
                ...CODE DELETED.....
               /* Clean up the command handle used */
                if (retcode == CS_END_RESULTS)
                {
                     retcode = ct_cmd_drop(cmd);
                     if (retcode != CS_SUCCEED)
                     {
                          query_code = CS_FAIL;
                     }
                }
               else
                {
                     (void)ct_cmd_drop(cmd);
                     query_code = CS_FAIL;
                }
               return query_code;
           }

This code excerpt is from the exutils.c example program.

Usage


First-time sends


Resending commands

See also

ct_command, ct_cursor, ct_dynamic, ct_fetch, ct_param, ct_results, ct_setparam