-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSON.FORMAT
96 lines (88 loc) · 2.67 KB
/
JSON.FORMAT
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
SUBROUTINE JSON.FORMAT
* Return the data from PQL as JSON
*$Copyright (c) 2010 TO 2012 to 2008 mike.ryder@pwchest.com, All Rights Reserved
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* Written by Mike Ryder @pwchest.com 18 March 2012
$CATALOG
$MODE UV.LOCATE
$INCLUDE I_WEBCOMMON
$INCLUDE I_SCHEMA
* main *
GOSUB PROCESS
RETURN
***************
* end of main *
***************
* subroutines *
***************
PROCESS:
IF FATAL$ERROR THEN RETURN
* get some instructions
PAGENO = HTTPEXTRACT("page")
ROWNO = HTTPEXTRACT("rows")
FATAL$ERROR = WEBERROR('CLEAR')
LMSG = APPLICATION
IF PAGENO AND ROWNO THEN
START.COUNT = (PAGENO-1)*ROWNO+1
END.COUNT = START.COUNT + ROWNO - 1
LMSG := ' from ':START.COUNT:' to ':END.COUNT
END
ICOUNT = 0
COMI = EMPTY
CALL WEB4LOG("Forming JSON from : ":LMSG)
NO.FIELDS = DCOUNT(R.SCHEMA<DICT.NAME>,VM)
** SSELECT F.APPLICATION RIGHT.ALIGNED
** openqm are modifiying the syntax for a right justfied internal select
** probably from May 2012
** With the latest code you will be able to do an internal select which
** will be much more efficient - particularly on larger data sets
EXECUTE "SSELECT ":APPLICATION CAPTURING GARBAGE
TOTAL.ITEMS = @SELECTED
K = ''
COMI = '{"total":':TOTAL.ITEMS:',"rows":['
LOOP
READNEXT ID ELSE EXIT
ICOUNT += 1
BEGIN CASE
CASE NOT(START.COUNT) ; GOSUB DOFORMAT
CASE ICOUNT > END.COUNT ; EXIT
CASE ICOUNT < START.COUNT
CASE 1 ; GOSUB DOFORMAT
END CASE
REPEAT
CLEARSELECT
COMI := LF:']}'
*
RETURN
******
DOFORMAT:
READ R.APPLICATION FROM F.APPLICATION,ID ELSE RETURN
COMI := K
KLX = EMPTY
FOR IX = 1 TO NO.FIELDS
INTNAME = R.SCHEMA<WEB.NAME,IX>
LCONV = R.SCHEMA<FIELD.CONV,IX>
FPOS = IX -1
IF FPOS THEN
DLINE = R.APPLICATION<FPOS>
IF LCONV THEN
DLINE = OCONV(DLINE,LCONV)
END
END ELSE
DLINE = ID
END
KLX<-1> = DQUOTE(INTNAME):':':DQUOTE(DLINE)
NEXT IX
CONVERT FM TO ',' IN KLX
COMI := LF:'{':KLX:'}'
K = ','
RETURN
******
END