| 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
|
| 5019 |
dpurdie |
55 |
' iTotalRecords = total records without any filtering/limits
|
|
|
56 |
' iTotalDisplayRecords = filtered result count
|
|
|
57 |
|
| 5018 |
dpurdie |
58 |
oJSON.data("sEcho") = CInt(Request.QueryString("sEcho"))
|
|
|
59 |
oJSON.data("iTotalRecords") = MaxCount
|
|
|
60 |
oJSON.data("iTotalDisplayRecords") = MaxCount
|
|
|
61 |
|
|
|
62 |
' Assist in debug
|
|
|
63 |
oJSON.data("iReqDisplayStart") = CInt(Request.QueryString("iDisplayStart"))
|
|
|
64 |
oJSON.data("iReqDisplayLength") = CInt(Request.QueryString("iDisplayLength"))
|
|
|
65 |
|
|
|
66 |
Dim vName
|
|
|
67 |
for each vName in Request.QueryString
|
|
|
68 |
oJSON.data("sReq_" & vName) = Request.QueryString(vName)
|
|
|
69 |
next
|
|
|
70 |
|
|
|
71 |
' Extract selected range
|
|
|
72 |
result = 0
|
|
|
73 |
dim firstRow,lastRow
|
|
|
74 |
firstRow = CInt(Request.QueryString("iDisplayStart"))
|
|
|
75 |
lastRow = firstRow + CInt(Request.QueryString("iDisplayLength"))
|
|
|
76 |
|
|
|
77 |
' Define the data items to extract from the database
|
|
|
78 |
' An array of items to extract
|
|
|
79 |
'
|
|
|
80 |
Dim dataCols: dataCols = Array ( _
|
|
|
81 |
"bi.PV_ID", _
|
|
|
82 |
"bi.RTAG_ID" ,_
|
|
|
83 |
"pv.pkg_id", _
|
|
|
84 |
"pj.PROJ_NAME", _
|
|
|
85 |
"pj.PROJ_ID", _
|
|
|
86 |
"RTAG_NAME", _
|
|
|
87 |
"p.PKG_NAME", _
|
|
|
88 |
"pv.PKG_VERSION", _
|
|
|
89 |
"pv.PV_DESCRIPTION", _
|
|
|
90 |
"pv.COMMENTS", _
|
|
|
91 |
"NVL(pv.V_EXT, '') as V_EXT", _
|
|
|
92 |
"TO_CHAR(bi.TIMESTAMP, 'Dy DD-Mon-YYYY HH24:MI:SS') as TIMESTAMPTXT", _
|
|
|
93 |
"DECODE(bi.reason, 'N', 'New Version', 'R', 'Ripple', 'T', 'Test', 'P', 'Restored', 'Unknown') as REASON" ,_
|
| 5044 |
dpurdie |
94 |
"DECODE(bi.state, 'B', 'Buiding', 'C', 'Complete', 'E', 'Error', 'S', 'SysErr', 'Unknown') as STATE" ,_
|
|
|
95 |
"(SELECT COUNT(*) from TEST_RUN tr WHERE tr.build_id = bi.build_id) AS test_count" )
|
| 5018 |
dpurdie |
96 |
|
|
|
97 |
' Define array of colums to sort by
|
|
|
98 |
' Must match user sort column request
|
|
|
99 |
Dim sortCols: sortCols = Array ( _
|
|
|
100 |
"UPPER(pj.PROJ_NAME)",_
|
|
|
101 |
"UPPER(rt.RTAG_NAME)",_
|
|
|
102 |
"UPPER(p.PKG_NAME)",_
|
|
|
103 |
"UPPER(pv.PKG_VERSION)",_
|
|
|
104 |
"bi.BUILD_ID",_
|
|
|
105 |
"UPPER(bi.reason)",_
|
| 5044 |
dpurdie |
106 |
"UPPER(bi.state)",_
|
|
|
107 |
"test_count" )
|
| 5018 |
dpurdie |
108 |
|
|
|
109 |
' Dim determine sorting options
|
|
|
110 |
'On Error goto 0
|
|
|
111 |
'Response.Write "<pre>"
|
|
|
112 |
Dim sortString
|
|
|
113 |
If Request.QueryString("iSortCol_0") <> "" Then
|
|
|
114 |
sortString = " ORDER BY " & sortCols(CInt(Request.QueryString("iSortCol_0")))
|
|
|
115 |
sortString = sortString & " " & Request.QueryString("sSortDir_0")
|
|
|
116 |
End If
|
|
|
117 |
|
|
|
118 |
' Filter (search )
|
|
|
119 |
Dim searchString
|
|
|
120 |
If Request.QueryString("sSearch") <> "" Then
|
|
|
121 |
searchString = " AND upper(p.PKG_NAME) LIKE upper('%" & Request.QueryString("sSearch") & "%')"
|
|
|
122 |
End If
|
|
|
123 |
|
|
|
124 |
' Create a list of cols that we need. Avoids ambiguity in selections
|
|
|
125 |
Dim x,colList,colListJoin
|
|
|
126 |
For x = Lbound(dataCols) to Ubound(dataCols)
|
|
|
127 |
colList = colList & colListJoin & dataCols(x)
|
|
|
128 |
colListJoin = ","
|
|
|
129 |
Next
|
|
|
130 |
|
|
|
131 |
Dim whereString
|
|
|
132 |
If parRtagId <> "" Then
|
|
|
133 |
whereString = " AND bi.rtag_id = " & parRtagId
|
|
|
134 |
End If
|
|
|
135 |
|
|
|
136 |
Dim BasicSql
|
|
|
137 |
BasicSql = "select " & colList &_
|
|
|
138 |
" from BUILD_INSTANCES bi, " &_
|
|
|
139 |
" projects pj, " &_
|
|
|
140 |
" RELEASE_TAGS rt, " &_
|
|
|
141 |
" packages p, " &_
|
|
|
142 |
" PACKAGE_VERSIONS pv" &_
|
|
|
143 |
" where bi.PV_ID = pv.pv_id " &_
|
|
|
144 |
" and pv.PKG_ID = p.PKG_ID" &_
|
|
|
145 |
" and bi.RTAG_ID = rt.RTAG_ID" &_
|
|
|
146 |
" and rt.proj_id = pj.proj_id" &_
|
|
|
147 |
whereString &_
|
|
|
148 |
searchString &_
|
|
|
149 |
sortString
|
|
|
150 |
|
|
|
151 |
SqlQry = "select * from ( "&_
|
|
|
152 |
"select a.*, ROWNUM rnum from (" & BasicSql &_
|
|
|
153 |
") a where ROWNUM <= " & lastRow &_
|
|
|
154 |
") where rnum >= " & firstRow
|
|
|
155 |
|
|
|
156 |
' Assist in debug
|
|
|
157 |
oJSON.data("BasicSql") = BasicSql
|
|
|
158 |
'oJSON.data("SqlQry") = SqlQry
|
|
|
159 |
|
|
|
160 |
' Perform the database query
|
|
|
161 |
Set oJSON.data("aaData") = oJSON.Collection()
|
|
|
162 |
On Error Resume Next
|
|
|
163 |
objEH.ErrorRedirect = FALSE
|
|
|
164 |
objEH.TryORA ( OraSession )
|
|
|
165 |
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
|
|
|
166 |
objEH.CatchORA ( OraSession )
|
|
|
167 |
' Process each row and return required fields to the user
|
|
|
168 |
If objEH.Finally Then
|
|
|
169 |
While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
|
|
|
170 |
Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
|
|
|
171 |
|
|
|
172 |
' Attempt to speed up access tot he data
|
|
|
173 |
' Extract all fields for the row
|
|
|
174 |
' Access fields by index
|
|
|
175 |
Dim fields
|
|
|
176 |
Set fields = rsQry.Fields
|
|
|
177 |
Dim proj_name : proj_name = fields(3)
|
|
|
178 |
Dim proj_id : proj_id = fields(4)
|
|
|
179 |
Dim rtag_name : rtag_name = fields(5)
|
|
|
180 |
Dim pkg_name : pkg_name = fields(6)
|
|
|
181 |
Dim pkg_id : pkg_id = fields(2)
|
|
|
182 |
Dim v_ext : v_ext = fields(10)
|
|
|
183 |
Dim description : description = Server.HTMLEncode(fields(8))
|
|
|
184 |
Dim pv_id : pv_id = fields(0)
|
|
|
185 |
Dim rtag_id : rtag_id = fields(1)
|
|
|
186 |
Dim comments : comments = Server.HTMLEncode(fields(9))
|
|
|
187 |
Dim pkg_version : pkg_version = fields(7)
|
|
|
188 |
Dim timestamp : timestamp = fields(11)
|
|
|
189 |
Dim reason : reason = fields(12)
|
|
|
190 |
Dim state : state = fields(13)
|
| 5044 |
dpurdie |
191 |
Dim tcount : tcount = fields(14)
|
| 5018 |
dpurdie |
192 |
|
|
|
193 |
Set fields = nothing
|
|
|
194 |
|
|
|
195 |
newitem(0) = "<a href='rtree.asp?proj_id=" & proj_id & "'>" & proj_name & "</a>"
|
|
|
196 |
newitem(1) = rtag_name
|
|
|
197 |
newitem(2) = "<a href=view_by_version.asp?pkg_id=" & pkg_id & "&fpkgversion=*" & v_ext & " title=""" & description & """>" & pkg_name & "</a>"
|
|
|
198 |
newitem(3) = "<a href='dependencies.asp?pv_id=" & pv_id & "&rtag_id=" & rtag_id &"' title=""" & comments & """>" & pkg_version & "</a>"
|
|
|
199 |
newitem(4) = timestamp
|
|
|
200 |
newitem(5) = reason
|
|
|
201 |
newitem(6) = state
|
| 5044 |
dpurdie |
202 |
If tcount <= 0 Then tcount = ""
|
|
|
203 |
newitem(7) = tcount
|
| 5018 |
dpurdie |
204 |
|
|
|
205 |
rsQry.MoveNext
|
|
|
206 |
Wend
|
|
|
207 |
End IF
|
|
|
208 |
|
|
|
209 |
rsQry.Close
|
|
|
210 |
Set rsQry = Nothing
|
|
|
211 |
|
|
|
212 |
'
|
|
|
213 |
' SQL error detection and reporting
|
|
|
214 |
If objEH.LastOraFailed Then
|
|
|
215 |
oJSON.data("error") = 1
|
|
|
216 |
|
|
|
217 |
oJSON.data("emsgSummary") = objEH.MessageSummary
|
|
|
218 |
oJSON.data("emsgDetails") = objEH.MessageDetails
|
|
|
219 |
oJSON.data("SqlQry") = SqlQry
|
|
|
220 |
End If
|
|
|
221 |
|
|
|
222 |
'Return the object
|
|
|
223 |
Response.Write oJSON.JSONoutput()
|
|
|
224 |
'OraSession.Dispose()
|
|
|
225 |
%>
|