SAP Adaptive Server Enterprise SQL functions

You can use any function that Adaptive Server Enterprise supports (such as aggregate or mathematical functions) in SQL statements.

This example shows how to use the Adaptive Server Enterprise function UPPER in a SELECT statement:

SELECT UPPER(emp_name) 
   INTO :emp_name_var 
   FROM employee;

Calling Client Library functions

While PowerBuilder provides access to a large percentage of the features within Adaptive Server Enterprise, in some cases you may decide that you need to call one or more Client Library (CT-Lib) functions directly for a particular application. PowerBuilder provides access to any Windows DLL by using external function declarations.

CT-Lib calls require a pointer to one of the following structures as their first parameter:

  • CS_CONNECTION

  • CS_CONTEXT

  • CS_COMMAND

You can obtain the current CS_CONNECTION pointer by using the PowerScript DBHandle function.

Using DBHandle to obtain the CS_CONNECTION pointer

DBHandle takes a transaction object as a parameter and returns a long variable, which is the CS_CONNECTION pointer that PowerBuilder uses internally to communicate with the database. You can pass this value as one of the parameters to your external function.

This example shows how to use DBHandle. Assume a successful connection has occurred using the default transaction object (SQLCA):

// Define a variable to hold our DB handle. 
long    SQLServerHandle

// Go get the handle. 
SQLServerHandle = SQLCA.DBHandle( )

// Now that you have the CS_CONNECTION pointer, 
// call the DLL function. 
MyDLLFunction( SQLServerHandle, parm1, parm2, ... )

In your DLL, cast the incoming long value into a pointer to a CS_CONNECTION structure:

MyDLLFunction( long 1SQLServerHandle,
      parm1_type parm1,
      parm2_type Parm2, ... )
{
CS_CONNECTION * pConnect;
pConnect = (CS_CONNECTION *)  1SQLServerHandle;
// CT-LIB functions can be called using pConnect.
}

Obtaining the CS_CONTEXT pointer

Within your external function, you can obtain the CS_CONTEXT pointer with the following function call:

CS_RETCODE       RC;
CS_CONNECTION    * PConnect;
CS_INT           outlen;
CS_CONTEXT        * pContext;
rc = ct_con_props (pConnect,CS_GET,CS_PARENT_HANDLE,
               (CS_VOID *) &pContext, CS_UNUSED,
               &outlen);

Allocating a new command pointer

Likewise, you can allocate a new command pointer with the following code:

CS_COMMAND    * pCommand;
rc = ct_cmd_alloc(pConnect, &pCommand);