The risnull() function

The risnull() function checks whether the C or the variable contains a null value.

Syntax

mint risnull(type; ptrvar)
   mint type;
   char *ptrvar;
type
An integer that corresponds to the data type of a C or variable. This type can be any data type except var binary or an lvarchar pointer variable. For more information, see Data type constants
ptrvar
A pointer to the C or variable.

Usage

The risnull() function determines whether variables of all data types except var binary and lvarchar pointer variables contain a null value. To determine whether a var binary or lvarchar pointer host variable contains null, use the ifx_var_isnull() macro. For more information, see The ifx_var_isnull() function.

Return codes

1
The variable does contain a null value.
0
The variable does not contain a null value.

Example

This sample program is in the risnull.ec file in the demo directory.
/*
   * risnull.ec *

   This program checks the paid_date column of the orders table for NULL
   to determine whether an order has been paid.
*/

#include <stdio.h>

EXEC SQL include sqltypes;

#define WARNNOTIFY          1
#define NOWARNNOTIFY    0

main()
{
    char ans;
    int4 ret, exp_chk();

    EXEC SQL BEGIN DECLARE SECTION;
        int4 order_num;

      mint order_date, ship_date, paid_date;
    EXEC SQL END DECLARE SECTION;

    printf("RISNULL Sample ESQL Program running.\n\n");
    EXEC SQL connect to 'stores7';        /* open stores7 database*/
    exp_chk("CONNECT TO stores7", NOWARNNOTIFY)

    EXEC SQL declare c cursor for
        select order_num, order_date, ship_date, paid_date from orders;
    EXEC SQL open c;
    if(exp_chk("OPEN c", WARNNOTIFY) == 1)  /* Found warnings */
      exit(1);
    printf("\n Order#\tPaid?\n");        /* print column hdgs */
    while(1)
      {
      EXEC SQL fetch c into :order_num, :order_date, :ship_date, :paid_date;
      if ((ret = exp_chk("FETCH c")) == 100)   /* if end of rows */
         break;         /* terminate loop */
      if(ret < 0)
         exit(1);
      printf("%5d\t", order_num);
      if (risnull(CDATETYPE, (char *)&paid_date)) /* is price NULL ? */
         printf("NO\n");
      else
         printf("Yes\n");
      }
   printf("\nRISNULL Sample Program over.\n\n");
}

/*
 *  The exp_chk() file contains the exception handling functions to
 *  check the SQLSTATE status variable to see if an error has occurred
 *  following an SQL statement. If a warning or an error has
 *  occurred, exp_chk() executes the GET DIAGNOSTICS statement and
 *  prints the detail for each exception that is returned.
 */

EXEC SQL include exp_chk.ec

For a complete listing of the exp_chk() function, see Guide to the exp_chk.ec file or see the exp_chk.ec file for a listing of this exception-handling function.

Output

RISNULL Sample ESQL Program running.


Order#      Paid?
 1001      Yes
 1002      Yes
 1003      Yes
 1004      NO
 1005      Yes
 1006      NO
 1007      NO
 1008      Yes
 1009      Yes
 1010      Yes
 1011      Yes
 1012      NO
 1013      Yes
 1014      Yes
 1015      Yes
 1016      NO
 1017      NO
 1018      Yes
 1019      Yes
 1020      Yes
 1021      Yes
 1022      Yes
 1023      Yes

RISNULL Sample Program over.