source: BMXNET_RPMS_dotNET_UTILITIES-BMX/trunk/m/BMXPRS.m@ 1592

Last change on this file since 1592 was 1209, checked in by Sam Habiel, 13 years ago

BMXMON fix; updated all routines to v 2.31

File size: 2.2 KB
RevLine 
[645]1BMXPRS ; IHS/OIT/HMW - BMX WINDOWS UTILS ;
[1209]2 ;;2.31;BMX;;Jul 25, 2011
[645]3 ;
4 ;
5PARSE(X) ;EP-Parse SQL Statement into array
6 ;Input SQL statement as X
7 ;Returns BMXTK() array
8 ;Errors returned in BMXERR
9 ;
10 D PRE
11 Q:$D(BMXERR)
12 D POST
13 Q
14 ;
15POST2 ;EP - Remove commas from BMXTK
16 N J,K
17 S J=0 F S J=$O(BMXTK(J)) Q:'+J D
18 . S K=$O(BMXTK(J))
19 . I +K,","=$G(BMXTK(K)) D
20 . . K BMXTK(K)
21 . . D PACK(J)
22 . . Q
23 . Q
24 Q
25 ;
26POST ;
27 ;Combine multi-character operators
28 N J
29 S J=0 F S J=$O(BMXTK(J)) Q:'+J D
30 . I ">"=BMXTK(J) D Q
31 . . I "="[$G(BMXTK(J+1)) D Q
32 . . . S BMXTK(J)=BMXTK(J)_"="
33 . . . K BMXTK(J+1)
34 . . . D PACK(J)
35 . . I "<"[$G(BMXTK(J+1)) D Q
36 . . . S BMXTK(J)="<"_BMXTK(J)
37 . . . K BMXTK(J+1)
38 . . . D PACK(J)
39 . I "<"=BMXTK(J) D Q
40 . . I "=>"[$G(BMXTK(J+1)) D
41 . . . S BMXTK(J)=BMXTK(J)_BMXTK(J+1)
42 . . . K BMXTK(J+1)
43 . . . D PACK(J)
44 . I "="=BMXTK(J) D Q
45 . . I "<>"[$G(BMXTK(J+1)) D
46 . . . S BMXTK(J)=BMXTK(J+1)_BMXTK(J)
47 . . . K BMXTK(J+1)
48 . . . D PACK(J)
49 Q
50 ;
51PACK(J) ;
52 F S J=$O(BMXTK(J)) Q:'+J D
53 . S BMXTK(J-1)=BMXTK(J)
54 . K BMXTK(J)
55 Q
56 ;
57PRE N P,T,Q,Q1,A,B S (P,T,Q)=0,BMXTK="",A=0
58START S A=A+1
59 S B=$E(X,A)
60 I B="" G B5
61 I 'Q G QUOTE
62 I B=$C(39) G QUOTE
63 S BMXTK=BMXTK_B G START
64QUOTE I B'=$C(39) G SPACE
65 I Q G QUOTE2
66 ;S Q=1,BMXTK=B G START
67 S Q=1,BMXTK=BMXTK_B G START
68QUOTE2 S Q1=B,A=A+1,B=$E(X,A)
69 I B']"" G QUOTE3
70 I B'=$C(39) G QUOTE3
71 S BMXTK=BMXTK_Q1_B G START
72QUOTE3 S A=A-1,B=Q1,BMXTK=BMXTK_B,Q=0 G START
73SPACE I B'=" " G OP
74 I BMXTK]"" S T=T+1,BMXTK(T)=BMXTK,BMXTK=""
75 G START
76OP I "=><"'[B G OPAREN
77 I BMXTK]"" S T=T+1,BMXTK(T)=BMXTK,BMXTK=""
78 S T=T+1,BMXTK(T)=B,BMXTK=""
79 G START
80OPAREN I B'="(" G CPAREN
81 S P=P+1
82 I BMXTK]"" S T=T+1,BMXTK(T)=BMXTK,BMXTK=""
83 S T=T+1,BMXTK(T)=B G START
84CPAREN I B'=")" G B2
85 I P G B1
86 G B0
87 ;
88B0 S BMXERR="SQL SYNTAX ERROR" D ERROR G B5
89B1 S P=P-1
90 I BMXTK]"" S T=T+1,BMXTK(T)=BMXTK,BMXTK=""
91 S T=T+1,BMXTK(T)=B G START
92B2 I B'="," G B3
93 S T=T+1,BMXTK(T)=BMXTK,T=T+1,BMXTK(T)=",",BMXTK="" G START
94B3 S BMXTK=BMXTK_B
95B4 G START
96B5 I BMXTK]"" S T=T+1,BMXTK(T)=BMXTK
97 I $D(BMXERR) G B6
98 I P S BMXERR="SQL SYNTAX ERROR: MATCHING PARENTHESIS NOT FOUND" D ERROR
99 E I Q S BMXERR="SQL SYNTAX ERROR: MATCHING QUOTE NOT FOUND" D ERROR
100 I P>0 G START
101B6 Q
102 ;
103ERROR ;W !,"ERROR=",BMXERR,! Q
104 Q
Note: See TracBrowser for help on using the repository browser.