SQL Programming Manual for TAL
Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for TAL—527887-001
C-26
Detailed Dynamic SQL Program
Page 15 [1] $VOL1.S04.TALDYN 1991-10-15 13:42:28
adjust^sqlda^scale^types
569. 000000 0 0 PROC adjust^sqlda^scale^types(sqlda);
570. 000000 1 0
571. 000000 1 0 !******************************************************!
572. 000000 1 0 ! PROC adjust^sqlda^scale^types: !
573. 000000 1 0 ! This function takes an SQLDA as a parameter and !
574. 000000 1 0 ! adjusts the recommended (by SQL) data types and !
575. 000000 1 0 ! scales to what TAL supports. !
576. 000000 1 0 ! !
577. 000000 1 0 ! Adjusting for supported data types involves
modifying !
578. 000000 1 0 ! the data^len and data^type of the SQLVAR entry to !
579. 000000 1 0 ! reflect the data attributes that TAL can support. !
580. 000000 1 0 ! !
581. 000000 1 0 ! For example, an input parameter or output variable
with !
582. 000000 1 0 ! data^type = _SQLDT_DEC_LSS and !
583. 000000 1 0 ! data^len = 7 (assuming scale = 0) !
584. 000000 1 0 ! can be modified to have !
585. 000000 1 0 ! data^type = _SQLDT_32BIT_S and !
586. 000000 1 0 ! data^len = 4. !
587. 000000 1 0 ! !
588. 000000 1 0 ! Independently of the data type change, the scale is !
589. 000000 1 0 ! set to 0. This will cause the TAL program to deal !
590. 000000 1 0 ! only with the integer part of the value. More !
591. 000000 1 0 ! sophisticated programs could note the scale value !
592. 000000 1 0 ! from the SQLDA and take it into account in their !
593. 000000 1 0 ! computations. !
594. 000000 1 0 ! !
595. 000000 1 0 ! Although TAL does support scaled values in FIXED !
596. 000000 1 0 ! variables, there are no convenient formatting !
597. 000000 1 0 ! procedures for FIXED values, so this program does !
598. 000000 1 0 ! not used FIXED data. !
599. 000000 1 0 ! !
600. 000000 1 0 !*******************************************************!
601. 000000 1 0
602. 000000 1 0 STRUCT .ext sqlda (sqlda^type); ! IN -- pointer to the SQLDA
603. 000000 1 0
604. 000000 1 0 BEGIN
605. 000000 1 1 INT i;
606. 000000 1 1
607. 000000 1 1 FOR i := 0 TO sqlda.num^entries-1 DO
608. 000003 1 1 BEGIN
609. 000003 1 2 CASE sqlda.sqlvar[i].data^type OF
610. 000016 1 2 BEGIN
611. 000016 1 3 _SQLDT_16BIT_S, ! SMALLINT
612. 000016 1 3 _SQLDT_16BIT_U, ! UNSIGNED SMALLINT
613. 000016 1 3 _SQLDT_32BIT_S, ! INTEGER
614. 000016 1 3 _SQLDT_32BIT_U -> ! UNSIGNED INTEGER
615. 000016 1 3 ! set scale to 0
616. 000016 1 3 sqlda.sqlvar[i].data^len.<0:7> := 0;
617. 000031 1 3
618. 000031 1 3 _SQLDT_64BIT_S -> ! LARGEINT
619. 000032 1 3 ! set scale to 0 and change type to 32-bit integer
620. 000032 1 3 sqlda.sqlvar[i].data^len.<0:7> := 0;
621. 000045 1 3 sqlda.sqlvar[i].data^type := _SQLDT_32BIT_S;
622. 000060 1 3 sqlda.sqlvar[i].data^len.<8:15> := 4; ! length
of 32 bits
623. 000074 1 3
624. 000074 1 3 _SQLDT_DEC_U, ! DECIMAL unsigned
625. 000075 1 3 _SQLDT_DEC_LSS, ! DECIMAL LSS