-
Notifications
You must be signed in to change notification settings - Fork 1
/
ROOKTUI.m
107 lines (105 loc) · 2.38 KB
/
ROOKTUI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
ROOKTUI
Q
;
REPL(ARGS)
;
; SUBROUTINE DATA
;
N SQLSTMT,RETURN,RESULT,USERNAME,PASSWORD,RCNT,QTIME
I $G(ARGS)="" N ARGS S ARGS=""
;
; WRITE BANNER
;
U $P:NOWRAP
W !,!,"ROOK Enterprise Server",!
W " Copyright (C) 2013 Coherent Logic Development LLC",!,!
S USERNAME=$$GETARG(ARGS,"u"),PASSWORD=$$GETARG(ARGS,"p")
REAUTH
I USERNAME="" R "login: ",USERNAME
I PASSWORD="" W !,"password: " U $P:NOECHO R PASSWORD U $P:ECHO
S RETURN=$$CONNECT^ROOK(USERNAME,PASSWORD,"Q",.RESULT)
I 'RETURN D ERRMSG(.RESULT) G REAUTH
GC
S (RKRESULT,RETURN)=1 K RESULT
R !,"ROOK> ",SQLSTMT
I $$UCASE^ROOKSQL(SQLSTMT)="QUIT" HALT
S RETURN=$$EXEC^ROOKSQL(SQLSTMT,.RESULT)
I 'RETURN D
. D ERRMSG(.RESULT)
E D
. S RCNT=RESULT("RECORDCOUNT"),QTIME=RESULT("QUERYTIME")
. I RCNT>0 D DISPLAY(.RESULT)
. D MSG("Query OK. "_RCNT_" rows in set ("_QTIME_" sec)")
G GC
Q
DISPLAY(RESULT)
N EMBR,EGG,ENUM,EMBRYOS,VAL,LEN,MAXLEN,SCOLS,CCOL
S (EMBR,EGG,ENUM)=""
S MAXLEN=0,CCOL=1
;
; GET LIST OF EMBRYOS
;
F S EGG=$O(RESULT("DATA",EGG)) Q:EGG="" D
. S ENUM=""
. F S ENUM=$O(RESULT("DATA",EGG,ENUM)) Q:ENUM="" D
. . S EMBR=""
. . F S EMBR=$O(RESULT("DATA",EGG,ENUM,EMBR)) Q:EMBR="" D
. . . S VAL=RESULT("DATA",EGG,ENUM,EMBR)
. . . S EMBRYOS(EMBR,ENUM)=$L(VAL)
. . . S MAXLEN(EMBR)=$L(EMBR)
;
; GET THE MAX LENGTH FOR EACH ONE
;
S EMBR=""
F S EMBR=$O(EMBRYOS(EMBR)) Q:EMBR="" D
. S ENUM=""
. F S ENUM=$O(EMBRYOS(EMBR,ENUM)) Q:ENUM="" D
. . I EMBRYOS(EMBR,ENUM)>MAXLEN(EMBR) S MAXLEN(EMBR)=EMBRYOS(EMBR,ENUM)
;
; DETERMINE THE START COLUMN FOR EACH
;
W !,!
S EMBR=""
F S EMBR=$O(MAXLEN(EMBR)) Q:EMBR="" D
. W $J(EMBR,MAXLEN(EMBR))," | "
W !
;
S EGG=""
F S EGG=$O(RESULT("DATA",EGG)) Q:EGG="" D
. S ENUM=""
. F S ENUM=$O(RESULT("DATA",EGG,ENUM)) Q:ENUM="" D
. . S EMBR=""
. . F S EMBR=$O(MAXLEN(EMBR)) Q:EMBR="" D
. . . W $J(RESULT("DATA",EGG,ENUM,EMBR),MAXLEN(EMBR))," | "
. . W !
W !,!
;BREAK
;
;
;
Q
;
ERRMSG(RESULT)
D MSG("ERROR "_RESULT("ERROR","CODE")_": "_RESULT("ERROR","MESSAGE"))
Q
;
MSG(MSG)
W !,MSG,!
Q
;
GETARG(ARGS,ARG)
N RET,ARGFLG,ARGL,ARGEX,ARGEND
S RET=""
S ARGFLG="-"_ARG
S ARGL=$L(ARGS,ARGFLG)
S ARGEX=$S(ARGL=2:1,ARGL<2:0)
I ARGEX=1 D
. S ARGEND=$P(ARGS,ARGFLG,2)
. I $L(ARGEND," ")>1 D
. . S RET=$P(ARGEND," ",1)
. I $L(ARGEND," ")<2 D
. . I $L(ARGEND,"-")>1 D
. . . S RET=$P(ARGEND,"-",1)
. . I $L(ARGEND,"-")<2 D
. . . S RET=ARGEND
Q RET