cs_ctx_alloc

Description

Allocates a CS_CONTEXT structure.

Syntax

CS_RETCODE cs_ctx_alloc(version, ctx_pointer)
 
 CS_INT                 version;
 CS_CONTEXT      **ctx_pointer;

Parameters

version

One of the following symbolic values, to indicate the intended version of CS-Library behavior:

Value of version

Indicates

Features supported

CS_VERSION_100

10.0 behavior

Initial version.

CS_VERSION_110

11.1 behavior

Unicode character set support.

Use of external configuration files to control Client-Library property settings.

CS_VERSION_120

12.0 behavior

All above features.

CS_VERSION_125

12.5 behavior

unichar support, wide data and columns, SSL.

CS_VERSION_150

15.0 behavior

BCP partitions, BCP computed columns, large identifiers, Unilib®, Adaptive Server Enterprise default packet size, scrollable cursors, and clusters support. Also, support for unitext, xml, bigint, usmallint, uint, and ubigint datatypes. Note the Sybase library name change.

CS_VERSION_155

15.5 behavior

CS_BIGDATETIME and CS_BIGTIME datatypes and microsecond granularity for time data, ct_send_data enhancement, Open Server dynamic listeners, Open Client CS_RES_ NOXNLMETADATA response capability, FIPS-140-2-compliant password encryption.

ctx_pointer

The address of a pointer variable. cs_ctx_alloc sets *ctx_pointer to the address of a newly allocated CS_CONTEXT structure.

In case of error, cs_ctx_alloc sets *ctx_pointer to NULL.

Returns

cs_ctx_alloc returns:

Returns

Indicates

CS_SUCCEED

The routine completed successfully.

CS_MEM_ERROR

The routine failed because it could not allocate sufficient memory.

CS_FAIL

The routine failed for other reasons.

The most common reason for a cs_ctx_alloc failure is a misconfigured system environment. cs_ctx_alloc must read the locales file that specifies the default localization values for the allocated context. If CS-Library cannot find the locales file or if the locales file is misconfigured, cs_ctx_alloc fails.

NoteWhen cs_ctx_alloc returns CS_FAIL an extended error message is sent to standard error (SDTERR) and to the sybinit.err file that is created in the current working directory.

On most systems, the SYBASE environment variable or logical name specifies the location of the locales file. The Open Client and Open Server Configuration Guide for Microsoft Windows or Open Client and Open Server Configuration Guide for UNIX describes the environmental configuration required for CS-Library localization values.

Other common reasons for a cs_ctx_alloc failure include:

NoteOn platforms that have a standard error device, cs_ctx_alloc prints U.S. English error messages to the standard error device when CS-Library cannot find the locales file. For Windows and other platforms that lack a standard error device, U.S. English error messages are written to a text file called sybinit.err in the application’s working directory.

Examples

Example 1

  /*
   ** ex_init()
   */
  CS_RETCODE CS_PUBLIC
   ex_init(context)
   CS_CONTEXT*     *context;
   {
        CS_RETCODE         retcode;
        CS_INT             netio_type = CS_SYNC_IO;
       /* Get a context handle to use */
        retcode = cs_ctx_alloc(CS_VERSION_125, context);
        if (retcode != CS_SUCCEED)
        {
             ex_error("ex_init: cs_ctx_alloc() failed");
             return retcode;
        }
        /* Initialize Open Client */
         ...CODE DELETED.....
        /* Install client and server message handlers */
         ...CODE DELETED.....
        if (retcode != CS_SUCCEED)
         {
         				ct_exit(*context, CS_FORCE_EXIT);
         				cs_ctx_drop(*context);
         				*context = NULL;
         }
        return retcode;
 }

Usage

See also

ct_con_alloc, ct_config, cs_ctx_drop, cs_ctx_global, cs_config