Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-008
10-55
Detailed Dynamic SQL Program
664 { while ( (c = getchar()) != '\n' )
665 { /* consume the input */ }
666 return (-1); /* array too small */
667 }
668 }
669 } /* end: while loop */
670
671 /* out of while loop only at terminator char. */
672 /* consume the remainder of input line */
673 if (terminator != '\n')
674 while ( (c = getchar()) != '\n' )
675 { /* consume the input */ }
676
677 /* ix points to next available slot */
678 /* null terminate or blank pad, as requested */
679 if (nullit == 0)
680 { for (i = ix; i < array_size; i++)
681 *(data_array + i) = ' '; /* blank pad */
682 }
683 else
684 *(data_array + ix) = '\0';
685
686 return (ix);
687
688 } /* end: get_string */
689
690 /* ****************************************************** */
691 /* FUNCTION read_query */
692 /* This function reads from the standard input (terminal) */
693 /* the SQL query. A semicolon marks the end of the query. */
694 /* */
695 /* If the user types in END/end/E/e then the session is */
696 /* stopped. If the user types in SAME/same then the last */
697 /* user query is run. If the user types in an SQL */
698 /* query, the query is read in 'host1' array and a copy */
699 /* of it is made in 'host2' array */
700 /* */
701 /* Return: 0 if query read in or SAME case */
702 /* -1 if END case */
703 /* ****************************************************** */
704 int read_query ( void )
705 {
706 short query_len; /* length of query in bytes */
707
708 try_again:
709 printf ("\nEnter SQL statement or SAME to reuse last statement or
END:\n");
710 fflush (stdout);
711 printf (">> ");
712
713 if ( (query_len = get_string (host1, max_query_size,
714 0, QUERY_TERMINATOR)) < 0 )
715 { printf("**** Error: Input query is too long.\n");
716 fflush( stdout );
717 goto try_again;
718 }
719
720 if ( ( strncmp(host1, "E", 1) == 0 ) ||
721 ( strncmp(host1, "e", 1) == 0 ) )
722 return (-1);
723
Example 10-8. Detailed Dynamic SQL Program (page 12 of 22)