SQL Programming Manual for Pascal

Examples of Dynamic NonStop SQL Programs
HP NonStop SQL Programming Manual for Pascal528614-001
C-18
Detailed Dynamic SQL Program
410 0 {**********************************************************}
411 0 {* SAME_CMD : Compare the input string (or a substring prefix)
*}
412 0 {* with a known command string to decide whether they *}
413 0 {* are the same. Return TRUE if equal, FALSE otherwise. *}
414 0 {**********************************************************}
415 0 function same_cmd(var cmd : CMND_BUF; cancmd_typ : integer)
416 1 : boolean;
417 1 var
418 1 i : integer := 1; { loop index }
419 1 cmd_len : integer; { input cmd string length }
420 1 cancmd_len : integer; { length of canned command }
421 1 cancmd_str : CMND_BUF; { buffer for canned command }
422 1 begin
423 2 case cancmd_typ of { what kind of a cmd is it? }
424 3 CMD_PREV_TYP :
425 3 begin
426 4 cancmd_str := CMD_PREV_STR;
427 4 cancmd_len := CMD_PREV_LEN;
428 4 end;
429 3 CMD_STOP_TYP :
430 3 begin
431 4 cancmd_str := CMD_STOP_STR;
432 4 cancmd_len := CMD_STOP_LEN;
433 4 end;
434 3 end; { end of CASE }
435 2
436 2 cmd_len := length(cmd);
437 2 if (cmd_len > cancmd_len) then { trivial check ! }
438 3 begin
439 4 same_cmd := FALSE; { they are different }
440 4 return;
441 4 end;
442 2 cmd_len := min(cmd_len,cancmd_len); { cmd could be abbreviated
}
443 2
444 2 { Convert each character in cmd to uppercase for the comparison
}
445 2 while (i <= cmd_len) and
446 3 ( ord(cancmd_str[i]) = upcase(cmd[i]) ) do
447 3 i := i + 1;
448 2 if (i > cmd_len) then
449 3 same_cmd := TRUE { they are the same }
450 3 else same_cmd := FALSE; { not the same }
451 2 end; { of proc same_cmd }
452 0
453 0 {**********************************************************}
454 0 {* VALID_CMD : If the first character in the command string *}
455 0 {* belongs to the alphabet the command will be *}
456 0 {* treated to be a valid command. *}
457 0 {**********************************************************}
458 0 function valid_cmd(cmdch : char) : boolean;
459 1 var
460 1 firstch : integer;
461 1 begin
462 2 firstch := upcase(cmdch);
463 2 if (firstch >= ord('A')) and (firstch <= ord('Z')) then
464 3 valid_cmd := true
465 3 else valid_cmd := false;
466 2 end; { of procedure valid_cmd }
467 0