Same Embedded SQL program with the -e option

/* Program name: ocs_test.cp 
 **
 ** Description  : This program declares a cursor which retireves rows
 ** from the 'titles' table based on condition checking for NULLS
 ** in the NON-ANSI style.
 ** The program will be compiled using the -e option which will
 ** use the server name that the application connects to, as the
 ** corresponding section to look up in the configuration file.
 */
 
 #include <stdio.h>
 
 /* Declare the SQLCA */
 EXEC SQL INCLUDE sqlca;
  
 EXEC SQL BEGIN DECLARE SECTION;
        /* storage for login name and password */
         CS_CHARusername[30], password[30];
         CS_CHARtitle_id[7], price[30]; 
 EXEC SQL END DECLARE SECTION;
 
  
 /*
 ** Forward declarations of the error and message handlers and
 ** other subroutines called from main().
 */
 void    error_handler();
 void    warning_handler();
 
 int main()
 {
         int i=0 ;
 
         EXEC SQL WHENEVER SQLERROR CALL error_handler();
         EXEC SQL WHENEVER SQLWARNING CALL warning_handler();
         EXEC SQL WHENEVER NOT FOUND CONTINUE ;
 
         /*
         ** Copy the user name and password defined in sybsqlex.h to
         ** the variables declared for them in the declare section.
         */
 
         strcpy(username, "sa");
         strcpy(password, "");
 
         EXEC SQL CONNECT :username IDENTIFIED BY :password ;
         EXEC SQL USE pubs2 ;
    
         EXEC SQL DECLARE title_list CURSOR FOR 
                 SELECT title_id, price FROM titles 
                       WHERE price != NULL;
 
        EXEC SQL OPEN title_list ;
        for ( ;; )
        {
               EXEC SQL FETCH title_list INTO
                         :title_id, :price;
               if ( sqlca.sqlcode == 100 )
               {
                       printf("End of fetch! \n");
                       break;
               }
               printf("Title ID : %s\n", title_id );
               printf("Price    : %s\n", price) ;
               printf("Please press RETURN to continue .. ");
               getchar();
               printf("\n\n");
        }
        EXEC SQL CLOSE title_list;
        exit(0);
 
 }
 
 void error_handler()
 {
         . . .}

NotePrecompiler option to set in the makefile: cpre -e.

The following is a sample configuration file for the preceding program:

[DEFAULT]
 ;
 
 [SYBASE]
 ;This is name of the server that the application connect to. Therefore
 ;this is the section that will be referred to a runtime.
 ;
 CS_OPT_ANSINULL=CS_FALSE
 ;The above option will enable comparisons of nulls in the NON-ANSI
 ;style.

The above configuration files have been vastly simplified. A typical Open Client/Server configuration file would be in the following format:

[DEFAULT]
 ;
 [ANSI_ESQL]
 CS_CAP_RESPONSE=CS_RES_NOSTRIPBLANKS
 CS_EXTRA_INF=CS_TRUE
 CS_ANSI_BINDS=CS_TRUE
 CS_OPT_ANSINULL=CS_TRUE
 CS_OPT_ANSIPERM=CS_TRUE
 CS_OPT_STR_RTRUNC=CS_TRUE
 CS_OPT_ARITHABORT=CS_FALSE
 CS_OPT_TRUNCIGNORE=CS_TRUE
 CS_OPT_ISOLATION=CS_OPT_LEVEL3
 CS_OPT_CHAINXACTS=CS_TRUE
 CS_OPT_CURCLOSEONXACT=CS_TRUE
 CS_OPT_QUOTED_IDENT=CS_TRUE
 ;
 ;The following is a sample section showing how to alter standard
 ;configuration:
 ;
 [RELEVANT_SECION_NAME]
 ;
 ;Use most of the ANSI properties defined above,
 ;
 include=ANSI_ESQL
 
 ;but override some default properties
 
 CS_OPT_ANSINULL=CS_TRUE    ; enable non-ansi style null comparisons
 CS_OPT_CHAINXACTS=CS_FALSE ; run in autocommit mode