SQL Programming Manual for TAL

Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for TAL527887-001
C-28
Detailed Dynamic SQL Program
Page 17 [1] $VOL1.S04.TALDYN 1991-10-15 13:42:28
setupvarbuffers
643. 000000 0 0 INT PROC setupvarbuffers(sqlda);
644. 000000 1 0
645. 000000 1 0 !********************************************************!
646. 000000 1 0 ! PROC setupvarbuffers: !
647. 000000 1 0 ! This function takes an SQLDA as a parameter and !
648. 000000 1 0 ! allocates the data and indicator value buffers. !
649. 000000 1 0 ! For each sqlvar, var^ptr is set to point to the !
650. 000000 1 0 ! data buffer and if null^info is set, ind^ptr is !
651. 000000 1 0 ! set to point to the indicator value. !
652. 000000 1 0 ! !
653. 000000 1 0 ! The sqlda is also changed by altering unsupported !
654. 000000 1 0 ! data types to the nearest equivalent data types !
655. 000000 1 0 ! and by setting the scale information to 0. !
656. 000000 1 0 ! !
657. 000000 1 0 ! sqlda.num^entries is assumed to have a valid value. !
658. 000000 1 0 ! !
659. 000000 1 0 ! Returns: 0 if successful !
660. 000000 1 0 ! -1 if failure !
661. 000000 1 0 ! !
662. 000000 1 0 !********************************************************!
663. 000000 1 0
664. 000000 1 0 STRUCT .ext sqlda (sqlda^type); ! IN -- pointer to the SQLDA
665. 000000 1 0
666. 000000 1 0 BEGIN
667. 000000 1 1 INT i;
668. 000000 1 1 INT .EXT ind^ptr^; ! temporary pointer for initializing
IND^PTR
669. 000000 1 1 ! to 0
670. 000000 1 1 INT mem^reqd;
671. 000000 1 1
672. 000000 1 1 !********************************************************!
673. 000000 1 1 ! Handle unsupported types; set scale information to 0. !
674. 000000 1 1 !********************************************************!
675. 000000 1 1 call adjust^sqlda^scale^types(sqlda);
676. 000004 1 1
677. 000004 1 1 FOR i := 0 TO sqlda.num^entries-1 DO
678. 000006 1 1 BEGIN
679. 000006 1 2 !***************************************************!
680. 000006 1 2 ! Determine the amount of memory needed by this entry's
data type. !
681. 000006 1 2 !******************************************************!
682. 000006 1 2 CASE sqlda.sqlvar[i].data^type OF
683. 000021 1 2 BEGIN
684. 000021 1 3 _SQLDT_ASCII_F, ! CHAR datatype
685. 000021 1 3 _SQLDT_ASCII_F_UP ->
686. 000021 1 3 mem^reqd := sqlda.sqlvar[i].data^len;
687. 000034 1 3 _SQLDT_ASCII_V, ! VARCHAR
688. 000035 1 3 _SQLDT_ASCII_V_UP ->
689. 000035 1 3 mem^reqd := sqlda.sqlvar[i].data^len + 2;
690. 000051 1 3 _SQLDT_16BIT_S, ! SMALLINT
691. 000052 1 3 _SQLDT_16BIT_U, ! UNSIGNED SMALLINT
692. 000052 1 3 _SQLDT_32BIT_S, ! INTEGER
693. 000052 1 3 _SQLDT_32BIT_U, ! UNSIGNED INTEGER
694. 000052 1 3 _SQLDT_64BIT_S, ! LARGEINT
695. 000052 1 3 _SQLDT_REAL, ! REAL
696. 000052 1 3 _SQLDT_DOUBLE -> ! DOUBLE PRECISION
697. 000052 1 3 mem^reqd := sqlda.sqlvar[i].data^len.<8:15>;
698. 000066 1 3 _SQLDT_DEC_U, ! DECIMAL unsigned
699. 000067 1 3 _SQLDT_DEC_LSS, ! DECIMAL LSS