ct_command

Description

Initiate a language, package, RPC, message, or send-data command.

Syntax

CS_RETCODE ct_command(cmd, type, buffer, buflen,
                option)
 
 CS_COMMAND     *cmd;
 CS_INT                  type;
 CS_VOID               *buffer;
 CS_INT                  buflen;
 CS_INT                  option;

Parameters

cmd

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

type

The type of command to initiate. Table 3-9 lists the symbolic values for type.

buffer

A pointer to data space. Table 3-9 lists the datatypes and meanings for *buffer values.

buflen

The length, in bytes, of the *buffer data, or CS_UNUSED if *buffer represents a fixed-length or symbolic value.

option

The option associated with this command.

Language, RPC (remote procedure call), send-data, and send-bulk-data commands take options. For all other types of commands, pass option as CS_UNUSED.

The following table lists the symbolic values for option:

Table 3-8: Values for ct_command option parameter

type is

Value of option

Meaning

CS_LANG_CMD

CS_MORE

The text in buffer is only part of the language command to be executed.

CS_END

The text in buffer is the last part of the language command to be executed.

CS_UNUSED

Equivalent to CS_END.

CS_RPC_CMD

CS_RECOMPILE

Recompile the stored procedure before executing it.

CS_NO_RECOMPILE

Do not recompile the stored procedure before executing it.

CS_UNUSED

Equivalent to CS_NO_RECOMPILE.

CS_SEND_DATA_CMD

CS_COLUMN_DATA

The data will be used for a text or image column update.

CS_BULK_DATA

For internal Sybase use only. The data will be used for a bulk copy operation.

CS_SEND_BULK_CMD

CS_BULK_INIT

For internal Sybase use only. Initialize a bulk copy operation.

CS_BULK_CONT

For internal Sybase use only. Continue a bulk copy operation.

Returns

ct_command returns the following values:

Returns

Meaning

CS_SUCCEED

The routine completed successfully.

CS_FAIL

The routine failed.

CS_BUSY

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

Examples

Example 1

/*
 ** ex_execute_cmd()
 **
 ** Type of function:   
 **      example program utility api
 **
 ** Purpose:
 ** Sends a language command to the server. 
 */
 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 structure,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;
    }
   /* Now send the command and process the results */
    ... ct_send, ct_results, and so forth deleted ...
   return CS_SUCCEED;
 }

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

Usage

Table 3-9 summarizes ct_command usage.

Table 3-9: Summary of ct_command parameters

Value of type

Command initiated

buffer is

buflen is

CS_LANG_CMD

A language command

A pointer to a CS_CHAR array that contains all or part of the language command text.

Use the CS_MORE and CS_END options to build the command text in pieces. See Table 3-8 for details.

The length of the *buffer data or CS_NULLTERM.

CS_MSG_CMD

A message command

A pointer to a CS_INT variable that contains the message ID.

CS_UNUSED

CS_PACKAGE_CMD

A package command

A pointer to a CS_CHAR array that contains the name of the package.

The length of the *buffer data or CS_NULLTERM.

CS_RPC_CMD

A remote procedure call command

A pointer to a CS_CHAR array that contains the name of the remote procedure.

The length of the *buffer data or CS_NULLTERM.

CS_SEND_DATA_CMD

A send-data command

NULL.

CS_UNUSED.

CS_SEND_DATA_NOCMD

A send-data command

NULL.

CS_UNUSED.

CS_SEND_BULK_CMD

A Sybase internal send-bulk-data command

A pointer to a CS_CHAR array that contains the database table name.

The length of the *buffer data or CS_NULLTERM.


Language commands


Message commands


Package commands


RPC commands


Send-data commands


Send-bulk-data commands


Suppressing commands

To update a text or image column, a client application typically calls the ct_command routine to initiate a send-data command. The client then calls the ct_data_info command to retrieve the CS_IODESC and determine the appropriate SQL command to generate (update or writetext) in a subsequent call to the ct_send_data routine.

To simplify this process and potentially improve performance, a client can suppress the generation of the SQL command (update or writetext) and send data directly to the server bulk handler. The client must initiate the send-data command by calling the ct_command routine with the type parameter set to CS_SEND_DATA_NOCMD. The client application can then use send-data commands to send only text or image data to the server bulk handler. When a bulk event occurs at the server, a 4-byte field is sent indicating the total number of bytes to be sent, followed by the text or image data. The bulk handler reads the total number of bytes expected using srv_text_info and the data using srv_get_data.

The server must define a stored procedure, sp_mda, to indicate whether or not it supports the ct_send_data routine sending only text or image data without a SQL command. The server sp_mda procedure is called only if the client application sets certain properties—for example, ct_con_props(CS_SENDDATA_NOCMD)—before the ct_connect routine is called. If any of these properties (such as CS_PARTIAL_TEXT or the CS_SENDDATA_NOCMD connection property) is set, the server sp_mda procedure is called during execution of ct_connect. If sp_mda indicates that the server does not support the ct_send_data routine sending only text or image data without a SQL command, any calls to the ct_command routine with the type parameter set to CS_SEND_DATA_NOCMD fail.

If the server can receive text or image data without a SQL command, sp_mda returns the following:

Parameter

Value

mdinfo

“SENDDATA_NOCMD”

querytype

2

query

senddata no cmd

NoteAdaptive Server cannot receive image or text data without a SQL command.

See also

ct_cmd_alloc, ct_cursor, ct_dynamic, ct_param, ct_send, ct_setparam