2.1.2 Functions

cs_ctx_alloc ([version = CS_VERSION_100])
Execute the Sybase-CT function cs_ctx_alloc(). The result is a tuple containing the Sybase result code and a new instance of the CS_CONTEXT class. None is returned as the CS_CONTEXT object when the result code is not CS_SUCCEED.

from sybasect import *
status, ctx = cs_ctx_alloc(CS_VERSION_100)
if status != CS_SUCCEED:
    raise 'cs_ctx_alloc'

cs_ctx_global ([version = CS_VERSION_100])
Execute the Sybase-CT function cs_ctx_global(). The result is a tuple containing the Sybase result code and a new instance of the CS_CONTEXT class. None is returned as the CS_CONTEXT object when the result code is not CS_SUCCEED.

from sybasect import *
status, ctx = cs_ctx_global(CS_VERSION_100)
if status != CS_SUCCEED:
    raise 'cs_ctx_global'

DataBuf (obj)
Return a new instance of the DataBuf class. The obj argument is used to initialise the DataBuf object.

For all types of obj other than CS_DATAFMT a buffer will be initialised which contains a single value.

buf = DataBuf('hello')
if cmd.ct_param(buf) != CS_SUCCEED:
    raise 'ct_param'

When obj is a CS_DATAFMT object an empty buffer will be created according to the attributes of the CS_DATAFMT object. It is most common to create and bind a buffer in a single operation via the ct_bind() method of the CS_COMMAND class.

For example, the following code creates a set of buffers for retrieving 16 rows at a time. Note that it is your responsibility to ensure that the buffers are not released until they are no longer required.

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

numeric (obj [, precision = -1][, scale = -1])
Return a new instance of the NumericType class.

The obj argument can accept any of the following types; IntType, LongType, FloatType, StringType, or NumericType.

If greater than or equal to zero the precision and scale arguments are used as the precision and scale attributes of the CS_DATAFMT which is used in the Sybase cs_convert() function to create the new NumericType object. The default values for these arguments depends upon the type being converted to NumericType.

Type precision scale
IntType 16 0
LongType # of digits in str() conversion 0
FloatType CS_MAX_PREC 12
StringType # digits before decimal point # digits after decimal point
NumericType input precision input scale

sizeof_type (type_code)
Returns the size of the type identified by the Sybase type code specified in the type_code argument.

The values expected for the type_code argument things like; CS_CHAR_TYPE, CS_TINYINT_TYPE, etc.

CS_DATAFMT ()
Return a new instance of the DataFmtType class. This is used to wrap the Sybase CS_DATAFMT structure.

CS_IODESC ()
Return a new instance of the IODescType class. This is used to wrap the Sybase CS_IODESC structure.

CS_LAYER (msgnumber)
Return the result of applying the Sybase CS_LAYER macro to the msgnumber argument.

CS_ORIGIN (msgnumber)
Return the result of applying the Sybase CS_ORIGIN macro to the msgnumber argument.

CS_SEVERITY (msgnumber)
Return the result of applying the Sybase CS_SEVERITY macro to the msgnumber argument.

CS_NUMBER (msgnumber)
Return the result of applying the Sybase CS_NUMBER macro to the msgnumber argument.