3.2 Functions

cs_ctx_alloc([version = CS_VERSION_100])
Calls the Sybase-CT cs_ctx_alloc() function:

result = cs_ctx_alloc(version, &ctx);

Returns a tuple containing the Sybase result code and a new instance of the CS_CONTEXT class constructed from the ctx value returned by cs_ctx_alloc(). None is returned as the CS_CONTEXT object if the result code is not CS_SUCCEED.

cs_ctx_global([version = CS_VERSION_100])
Calls the Sybase-CT cs_ctx_global() function:

result = cs_ctx_global(version, &ctx);

Returns a tuple containing the Sybase result code and a new instance of the CS_CONTEXT class constructed from the ctx value returned by cs_ctx_global(). None is returned as the CS_CONTEXT object if the result code is not CS_SUCCEED.

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.

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 Numeric 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

money(obj [, type = CS_MONEY_TYPE])
Return a new instance of the Money class.

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

Passing CS_MONEY4_TYPE in the type argument will create a smallmoney value instead of the default money.

datetime(str [, type = CS_DATETIME_TYPE])
Return a new instance of the DateTime class.

The str argument must be a string.

Passing CS_DATETIME4_TYPE in the type argument will create a smalldatetime value instead of the default datetime.

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 CS_DATAFMT class. This is used to wrap the Sybase CS_DATAFMT structure.

CS_IODESC()
Return a new instance of the CS_IODESC 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.