Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5018 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'       JSON test and play
5
'=====================================================
6
%>
7
<%
8
Option explicit
9
' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK)
10
Response.ContentType = "text/html"
11
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
12
Response.CodePage = 65001
13
Response.CharSet = "UTF-8"
14
%>
15
<!--#include file="common/conf.asp"-->
16
<!--#include file="common/globals.asp"-->
17
<!--#include file="common/qstr.asp"-->
18
<!--#include file="common/common_subs.asp"-->
19
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
20
<%
21
'------------ Variable Definition -------------
22
Dim result : result = -1
23
Dim SqlQry
24
Dim rsQry
25
Dim parRtagId : parRtagId = Request("rtag_id")
26
 
27
' Init the output JSON class
28
'   Operations can add data
29
'   Default data will be added at the end
30
Dim oJSON :Set oJSON = New aspJSON
31
Dim newitem
32
 
33
'
34
' Determine the size of the record set
35
'   Gives bad results when searching
36
Dim MaxCount : MaxCount = 0
37
 
38
SqlQry = "select count(*) as count from BUILD_INSTANCES bi"
39
If parRtagId <> "" Then
40
    SqlQry = SqlQry + " WHERE rtag_id = " &  parRtagId
41
End If
42
 
43
On Error Resume Next
44
objEH.ErrorRedirect = FALSE
45
objEH.TryORA ( OraSession )
46
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
47
objEH.CatchORA ( OraSession )
48
    If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
49
        MaxCount = rsQry("COUNT")
50
    End If
51
rsQry.Close
52
Set rsQry = Nothing
53
 
54
' Basic Header
55
oJSON.data("sEcho") = CInt(Request.QueryString("sEcho"))
56
oJSON.data("iTotalRecords") = MaxCount
57
oJSON.data("iTotalDisplayRecords") = MaxCount
58
 
59
' Assist in debug
60
oJSON.data("iReqDisplayStart") = CInt(Request.QueryString("iDisplayStart"))
61
oJSON.data("iReqDisplayLength") = CInt(Request.QueryString("iDisplayLength"))
62
 
63
Dim vName
64
for each vName in Request.QueryString
65
    oJSON.data("sReq_" & vName) = Request.QueryString(vName)
66
next
67
 
68
' Extract selected range
69
result = 0
70
dim firstRow,lastRow
71
firstRow = CInt(Request.QueryString("iDisplayStart"))
72
lastRow = firstRow + CInt(Request.QueryString("iDisplayLength"))
73
 
74
' Define the data items to extract from the database
75
' An array of items to extract
76
'
77
Dim dataCols: dataCols = Array ( _
78
        "bi.PV_ID", _
79
        "bi.RTAG_ID" ,_
80
        "pv.pkg_id", _
81
        "pj.PROJ_NAME", _
82
        "pj.PROJ_ID", _
83
        "RTAG_NAME", _
84
        "p.PKG_NAME", _
85
        "pv.PKG_VERSION", _
86
        "pv.PV_DESCRIPTION", _
87
        "pv.COMMENTS", _
88
        "NVL(pv.V_EXT, '') as V_EXT", _
89
        "TO_CHAR(bi.TIMESTAMP, 'Dy DD-Mon-YYYY HH24:MI:SS') as TIMESTAMPTXT", _
90
        "DECODE(bi.reason, 'N', 'New Version', 'R', 'Ripple', 'T', 'Test', 'P', 'Restored', 'Unknown') as REASON" ,_
91
        "DECODE(bi.state, 'B', 'Buiding', 'C', 'Complete', 'E', 'Error', 'S', 'SysErr', 'Unknown') as STATE" )
92
 
93
 
94
'   Define array of colums to sort by
95
'       Must match user sort column request
96
Dim sortCols: sortCols = Array ( _
97
        "UPPER(pj.PROJ_NAME)",_
98
        "UPPER(rt.RTAG_NAME)",_
99
        "UPPER(p.PKG_NAME)",_
100
        "UPPER(pv.PKG_VERSION)",_
101
        "bi.BUILD_ID",_
102
        "UPPER(bi.reason)",_
103
        "UPPER(bi.state)" )
104
 
105
' Dim determine sorting options
106
'On Error goto 0
107
'Response.Write "<pre>"
108
Dim sortString
109
If Request.QueryString("iSortCol_0") <> "" Then
110
    sortString = " ORDER BY " & sortCols(CInt(Request.QueryString("iSortCol_0")))
111
    sortString = sortString & " " & Request.QueryString("sSortDir_0")
112
End If
113
 
114
' Filter (search )
115
Dim searchString
116
If Request.QueryString("sSearch") <> "" Then
117
    searchString = " AND upper(p.PKG_NAME) LIKE upper('%" & Request.QueryString("sSearch") & "%')" 
118
End If
119
 
120
' Create a list of cols that we need. Avoids ambiguity in selections
121
Dim x,colList,colListJoin
122
For x = Lbound(dataCols) to Ubound(dataCols)
123
    colList = colList & colListJoin & dataCols(x)
124
    colListJoin = ","
125
Next
126
 
127
Dim whereString
128
If parRtagId <> "" Then
129
    whereString = " AND bi.rtag_id = " &  parRtagId
130
End If
131
 
132
Dim BasicSql
133
BasicSql = "select " & colList &_
134
            " from BUILD_INSTANCES bi, " &_
135
            "     projects pj, " &_
136
            "     RELEASE_TAGS rt, " &_
137
            "     packages p, " &_
138
            "     PACKAGE_VERSIONS pv" &_
139
            " where bi.PV_ID = pv.pv_id " &_
140
            "  and pv.PKG_ID = p.PKG_ID" &_
141
            "  and bi.RTAG_ID = rt.RTAG_ID" &_
142
            "  and rt.proj_id = pj.proj_id" &_
143
            whereString &_
144
            searchString &_
145
            sortString
146
 
147
SqlQry = "select * from ( "&_
148
            "select a.*, ROWNUM rnum from (" & BasicSql &_
149
                ") a where ROWNUM <= " & lastRow &_
150
            ") where rnum >= " & firstRow
151
 
152
' Assist in debug
153
oJSON.data("BasicSql") = BasicSql
154
'oJSON.data("SqlQry") = SqlQry
155
 
156
' Perform the database query
157
Set oJSON.data("aaData") = oJSON.Collection()
158
On Error Resume Next
159
objEH.ErrorRedirect = FALSE
160
objEH.TryORA ( OraSession )
161
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
162
objEH.CatchORA ( OraSession )
163
' Process each row and return required fields to the user
164
If objEH.Finally Then
165
   While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
166
       Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
167
 
168
       ' Attempt to speed up access tot he data
169
       '    Extract all fields for the row
170
       '    Access fields by index
171
       Dim fields
172
       Set fields = rsQry.Fields
173
       Dim proj_name    : proj_name = fields(3)
174
       Dim proj_id      : proj_id = fields(4)
175
       Dim rtag_name    : rtag_name = fields(5)
176
       Dim pkg_name     : pkg_name = fields(6)
177
       Dim pkg_id       : pkg_id = fields(2)
178
       Dim v_ext        : v_ext = fields(10)
179
       Dim description  : description = Server.HTMLEncode(fields(8))
180
       Dim pv_id        : pv_id = fields(0)
181
       Dim rtag_id      : rtag_id = fields(1)
182
       Dim comments     : comments = Server.HTMLEncode(fields(9))
183
       Dim pkg_version  : pkg_version = fields(7)
184
       Dim timestamp    : timestamp = fields(11)
185
       Dim reason       : reason = fields(12)
186
       Dim state        : state = fields(13)
187
 
188
       Set fields = nothing
189
 
190
        newitem(0) = "<a href='rtree.asp?proj_id=" & proj_id & "'>" & proj_name & "</a>"
191
        newitem(1) = rtag_name
192
        newitem(2) = "<a href=view_by_version.asp?pkg_id=" & pkg_id & "&fpkgversion=*" & v_ext & " title=""" & description & """>" & pkg_name & "</a>"
193
        newitem(3) =  "<a href='dependencies.asp?pv_id=" & pv_id & "&rtag_id=" & rtag_id &"' title=""" & comments & """>" & pkg_version & "</a>"
194
        newitem(4) = timestamp
195
        newitem(5) = reason
196
        newitem(6) = state
197
 
198
       rsQry.MoveNext
199
   Wend
200
End IF
201
 
202
rsQry.Close
203
Set rsQry = Nothing
204
 
205
'
206
' SQL error detection and reporting
207
If objEH.LastOraFailed Then
208
    oJSON.data("error") = 1
209
 
210
    oJSON.data("emsgSummary") = objEH.MessageSummary
211
    oJSON.data("emsgDetails") = objEH.MessageDetails
212
    oJSON.data("SqlQry") = SqlQry
213
End If
214
 
215
'Return the object
216
Response.Write oJSON.JSONoutput()
217
'OraSession.Dispose()
218
%>