2.1.5 CS_COMMAND Objects

Calling the ct_cmd_alloc() method of a CS_CONNECTION object will create a CS_COMMAND object. When the CS_COMMAND object is deallocated the Sybase ct_cmd_drop() function will be called for the command.

CS_COMMAND objects have the following interface:

is_eed
A read only integer which indicates when the CS_COMMAND object is an extended error data command structure.

conn
This is a read only reference to the parent CS_CONNECTION object. This prevents the connection from being dropped while the command still exists.

strip
An integer which controls right whitespace stripping of char columns. The default value is inherited from the parent connection when the command is created.

debug
An integer which controls printing of debug messages to stderr. The default value is inherited from the parent connection when the command is created.

ct_bind (num, datafmt)
Calls the Sybase ct_bind() function passing the num and datafmt arguments. It returns a tuple containing the Sybase result code and a DataBuf object which is used to retrieve data from the column identified by num.

See the description of the ct_describe() method for an example.

ct_cancel (type)
Calls the Sybase ct_cancel() function passing a NULL CS_CONNECTION, the wrapped CS_COMMAND pointer and the integer type argument and returns the Sybase result code.

ct_cmd_drop ()
Calls the Sybase ct_cmd_drop() function. Returns the Sybase result code.

This method will be automatically called when the CS_COMMAND object is deleted. Applications do not need to call the method.

ct_command (type [, ...])

ct_cursor (type [, ...])

ct_data_info (actio, num [, iodesc])

ct_describe (num)
Calls the Sybase ct_describe() function passing the num argument and a tuple containing the Sybase result code and a CS_DATAFMT object which describes the column identified by num. None is returned as the CS_DATAFMT object when the result code is not CS_SUCCEED.

def row_bind(cmd, count = 1):
    status, num_cols = cmd.ct_res_info(CS_NUMDATA)
    if status != CS_SUCCEED:
        raise StandardError(build_ct_exception(con, 'ct_res_info'))
    bufs = []
    for i in range(num_cols):
        status, fmt = cmd.ct_describe(i + 1)
        if status != CS_SUCCEED:
            raise StandardError(build_ct_exception(con, 'ct_describe'))
        fmt.count = count
        status, buf = cmd.ct_bind(i + 1, fmt)
        if status != CS_SUCCEED:
            raise StandardError(build_ct_exception(con, 'ct_bind'))
        bufs.append(buf)
    return bufs

ct_dynamic (type [, ...])

ct_fetch ()

ct_get_data (num, buf)

ct_param (buffer)

ct_res_info (type)

ct_results ()
Calls the Sybase ct_results() function and returns a tuple containing the Sybase result code and the result type returned by the Sybase function.

if cmd.ct_command(CS_LANG_CMD, 'select * from pubs..titles') != CS_SUCCEED:
    raise StandardError(build_ct_exception(con, 'ct_command'))
if cmd.ct_send() != CS_SUCCEED:
    raise StandardError(build_ct_exception(con, 'ct_send'))
while 1:
    status, result = cmd.ct_results()
    if status == CS_END_RESULTS:
        break
    elif status != CS_SUCCEED:
        raise StandardError(build_ct_exception(con, 'ct_results'))
    if result in (CS_COMPUTE_RESULT, CS_CURSOR_RESULT,
                  CS_PARAM_RESULT, CS_ROW_RESULT, CS_STATUS_RESULT):
        bufs = row_bind(cmd, 16)
	fetch_logical_result(bufs)
    elif result not in (CS_CMD_DONE, CS_CMD_SUCCEED):
        raise StandardError(build_ct_exception(con, 'ct_results'))

ct_send ()
Calls the Sybase ct_send() function and returns the Sybase result code.

status, cmd = con.ct_cmd_alloc()
if status != CS_SUCCEED:
    raise StandardError(build_ct_exception(con, 'ct_cmd_alloc'))
if cmd.ct_command(CS_LANG_CMD, 'select * from pubs..titles') != CS_SUCCEED:
    raise StandardError(build_ct_exception(con, 'ct_command'))
if cmd.ct_send() != CS_SUCCEED:
    raise StandardError(build_ct_exception(con, 'ct_send'))

ct_send_data (string)
Calls the Sybase ct_send_data() function and returns the Sybase result code.

ct_setparam (buffer)