SQL Programming Manual for TAL

Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for TAL527887-001
C-30
Detailed Dynamic SQL Program
Page 19 [1] $VOL1.S04.TALDYN 1991-10-15 13:42:28
allocate^sqlda
750. 000000 0 0 INT(32) PROC allocate^sqlda (num^entries);
751. 000000 1 0
752. 000000 1 0 !******************************************************!
753. 000000 1 0 ! PROC allocate^sqlda: !
754. 000000 1 0 ! This proc allocates an sqlda structure with num^entries
entries. !
755. 000000 1 0 ! It also initializes the sqlda and the sqlvars. !
756. 000000 1 0 ! A names buffer is also allocated. !
757. 000000 1 0 ! !
758. 000000 1 0 ! Returns: address of the sqlda created if successful !
759. 000000 1 0 ! NULL^ADDR if unsuccessful !
760. 000000 1 0 !******************************************************!
761. 000000 1 0
762. 000000 1 0 INT num^entries; ! IN -- number of parameters or columns
763. 000000 1 0 BEGIN
764. 000000 1 1 INT .EXT sqlda(sqlda^type); ! sqlda pointer to return
765. 000000 1 1 INT mem^reqd; ! gets amount of space needed for the sqlda
766. 000000 1 1 INT i; ! loop counter
767. 000000 1 1
768. 000000 1 1 ! Return null if zero entries requested
769. 000000 1 1
770. 000000 1 1 if num^entries = 0 then return NULL^ADDR;
771. 000006 1 1
772. 000006 1 1 ! Compute amount of memory needed for the sqlda
773. 000006 1 1
774. 000006 1 1 mem^reqd := $LEN(sqlda^type) + (num^entries-
1)*$LEN(sqlda^type.sqlvar);
775. 000015 1 1
776. 000015 1 1 ! Allocate the space. If error allocating, return null
address.
777. 000015 1 1
778. 000015 1 1 @sqlda := GETPOOL(pool^head,$DBL(mem^reqd));
779. 000025 1 1 if @sqlda = -1D then return NULL^ADDR;
780. 000034 1 1
781. 000034 1 1 ! Initialize the sqlda eye catcher and number of entries.
782. 000034 1 1
783. 000034 1 1 sqlda.eye^catcher ':=' SQLDA^EYE^CATCHER;
784. 000046 1 1 sqlda.num^entries := num^entries;
785. 000051 1 1
786. 000051 1 1 ! Initialize the pointers to the variable value and to the
787. 000051 1 1 ! null indicator in each sqlvar entry to the null address.
788. 000051 1 1
789. 000051 1 1 for i := 0 to num^entries-1 do
790. 000053 1 1 begin
791. 000053 1 2 sqlda.sqlvar[i].var^ptr := NULL^ADDR;
792. 000067 1 2 sqlda.sqlvar[i].ind^ptr := NULL^ADDR;
793. 000103 1 2 end;
794. 000112 1 1
795. 000112 1 1 ! Return the address of the sqlda allocated.
796. 000112 1 1
797. 000112 1 1 return @sqlda;
798. 000114 1 1 END; ! of proc allocate^sqlda
799. 000000 0 0
800. 000000 0 0
801. 000000 0 0
802. 000000 0 0