
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for C—429847-008
10-54
Detailed Dynamic SQL Program
603 /* ********************************************************** */
604 /* FUNCTION get_string */
605 /* This function reads from the standard input, a character */
606 /* string, into the data_array */
607 /* Tha data_array will be null terminated, or blank padded, */
608 /* as requested. The reading stops when 'terminator' char is */
609 /* read or if array_size number of characters have been read, */
610 /* whichever comes first */
611 /* */
612 /* For multi-line input, all white space characters are */
613 /* replaced by blanks */
614 /* */
615 /* Return: +ve integer, if successful; = the number of chars */
616 /* read from the input (minus the terminator char) */
617 /* -1 if entered data is too long for data_array */
618 /* (if no room for the null terminator (if reqsted) */
619 /* (if array_size not enough for entire input, ie */
620 /* until the semicolon ) */
621 /* ********************************************************** */
622
623 short get_string( char *data_array, /* array to read data into */
624 short array_size, /* max #bytes in array */
625 short nullit, /* if != 0, terminate */
626 /* data_array on return, */
627 /* else blank pad array */
628 char terminator ) /* terminator character */
629
630 { /* begin get_string */
631
632 char c;
633 short ix; /* next available slot */
634 /* also return code */
635 short i; /* loop index */
636
637 /* sanity check */
638 if (array_size == 0) /* buffer no good */
639 return (-1);
640
641 ix = 0;
642 while ( (c = getchar()) != terminator )
643 {
644 if ( c == '\t' || c == '\n' )
645 *(data ix) = ' '; /* replace by blank */
646 else
647 *(data ix) = c;
648
649 if (++ix >= array_size) /* no more room in array */
650 { if (nullit == 0) /* blankpadding requested */
651 { if ( (c = getchar()) == terminator )
652 { /* the next char was the terminator anyway. */
653 /* just made it. also consume extra input */
654 /* at while-loop exit */
655 break;
656 }
657 else
658 { while ( (c = getchar()) != '\n' )
659 { /* consume the input */ }
660 return (-1); /* array too small */
661 }
662 }
663 else /* null termination rqsted */
Example 10-8. Detailed Dynamic SQL Program
(page 11 of 22)
Содержание NonStop SQL/MP
Страница 4: ......
Страница 14: ...Contents HP NonStop SQL MP Programming Manual for C 429847 008 x ...
Страница 34: ...Introduction HP NonStop SQL MP Programming Manual for C 429847 008 1 8 SQL MP Version Management ...
Страница 60: ...Host Variables HP NonStop SQL MP Programming Manual for C 429847 008 2 26 VARCHAR Data Type ...
Страница 68: ...SQL MP Statements and Directives HP NonStop SQL MP Programming Manual for C 429847 008 3 8 Finding Information ...
Страница 156: ...Explicit Program Compilation HP NonStop SQL MP Programming Manual for C 429847 008 6 40 SQL Program Files ...
Страница 264: ...Dynamic SQL Operations HP NonStop SQL MP Programming Manual for C 429847 008 10 66 Detailed Dynamic SQL Program ...
Страница 294: ...SQL MP Sample Database HP NonStop SQL MP Programming Manual for C 429847 008 A 6 ...
Страница 300: ...Memory Considerations HP NonStop SQL MP Programming Manual for C 429847 008 B 6 Avoiding Memory Stack Overflows ...
Страница 304: ...Maximizing Local Autonomy HP NonStop SQL MP Programming Manual for C 429847 008 C 4 Skipping Unavailable Partitions ...