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
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" ,_
94
        "DECODE(bi.state, 'B', 'Buiding', 'C', 'Complete', 'E', 'Error', 'S', 'SysErr', 'Unknown') as STATE" )
95
 
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)",_
106
        "UPPER(bi.state)" )
107
 
108
' Dim determine sorting options
109
'On Error goto 0
110
'Response.Write "<pre>"
111
Dim sortString
112
If Request.QueryString("iSortCol_0") <> "" Then
113
    sortString = " ORDER BY " & sortCols(CInt(Request.QueryString("iSortCol_0")))
114
    sortString = sortString & " " & Request.QueryString("sSortDir_0")
115
End If
116
 
117
' Filter (search )
118
Dim searchString
119
If Request.QueryString("sSearch") <> "" Then
120
    searchString = " AND upper(p.PKG_NAME) LIKE upper('%" & Request.QueryString("sSearch") & "%')" 
121
End If
122
 
123
' Create a list of cols that we need. Avoids ambiguity in selections
124
Dim x,colList,colListJoin
125
For x = Lbound(dataCols) to Ubound(dataCols)
126
    colList = colList & colListJoin & dataCols(x)
127
    colListJoin = ","
128
Next
129
 
130
Dim whereString
131
If parRtagId <> "" Then
132
    whereString = " AND bi.rtag_id = " &  parRtagId
133
End If
134
 
135
Dim BasicSql
136
BasicSql = "select " & colList &_
137
            " from BUILD_INSTANCES bi, " &_
138
            "     projects pj, " &_
139
            "     RELEASE_TAGS rt, " &_
140
            "     packages p, " &_
141
            "     PACKAGE_VERSIONS pv" &_
142
            " where bi.PV_ID = pv.pv_id " &_
143
            "  and pv.PKG_ID = p.PKG_ID" &_
144
            "  and bi.RTAG_ID = rt.RTAG_ID" &_
145
            "  and rt.proj_id = pj.proj_id" &_
146
            whereString &_
147
            searchString &_
148
            sortString
149
 
150
SqlQry = "select * from ( "&_
151
            "select a.*, ROWNUM rnum from (" & BasicSql &_
152
                ") a where ROWNUM <= " & lastRow &_
153
            ") where rnum >= " & firstRow
154
 
155
' Assist in debug
156
oJSON.data("BasicSql") = BasicSql
157
'oJSON.data("SqlQry") = SqlQry
158
 
159
' Perform the database query
160
Set oJSON.data("aaData") = oJSON.Collection()
161
On Error Resume Next
162
objEH.ErrorRedirect = FALSE
163
objEH.TryORA ( OraSession )
164
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
165
objEH.CatchORA ( OraSession )
166
' Process each row and return required fields to the user
167
If objEH.Finally Then
168
   While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
169
       Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
170
 
171
       ' Attempt to speed up access tot he data
172
       '    Extract all fields for the row
173
       '    Access fields by index
174
       Dim fields
175
       Set fields = rsQry.Fields
176
       Dim proj_name    : proj_name = fields(3)
177
       Dim proj_id      : proj_id = fields(4)
178
       Dim rtag_name    : rtag_name = fields(5)
179
       Dim pkg_name     : pkg_name = fields(6)
180
       Dim pkg_id       : pkg_id = fields(2)
181
       Dim v_ext        : v_ext = fields(10)
182
       Dim description  : description = Server.HTMLEncode(fields(8))
183
       Dim pv_id        : pv_id = fields(0)
184
       Dim rtag_id      : rtag_id = fields(1)
185
       Dim comments     : comments = Server.HTMLEncode(fields(9))
186
       Dim pkg_version  : pkg_version = fields(7)
187
       Dim timestamp    : timestamp = fields(11)
188
       Dim reason       : reason = fields(12)
189
       Dim state        : state = fields(13)
190
 
191
       Set fields = nothing
192
 
193
        newitem(0) = "<a href='rtree.asp?proj_id=" & proj_id & "'>" & proj_name & "</a>"
194
        newitem(1) = rtag_name
195
        newitem(2) = "<a href=view_by_version.asp?pkg_id=" & pkg_id & "&fpkgversion=*" & v_ext & " title=""" & description & """>" & pkg_name & "</a>"
196
        newitem(3) =  "<a href='dependencies.asp?pv_id=" & pv_id & "&rtag_id=" & rtag_id &"' title=""" & comments & """>" & pkg_version & "</a>"
197
        newitem(4) = timestamp
198
        newitem(5) = reason
199
        newitem(6) = state
200
 
201
       rsQry.MoveNext
202
   Wend
203
End IF
204
 
205
rsQry.Close
206
Set rsQry = Nothing
207
 
208
'
209
' SQL error detection and reporting
210
If objEH.LastOraFailed Then
211
    oJSON.data("error") = 1
212
 
213
    oJSON.data("emsgSummary") = objEH.MessageSummary
214
    oJSON.data("emsgDetails") = objEH.MessageDetails
215
    oJSON.data("SqlQry") = SqlQry
216
End If
217
 
218
'Return the object
219
Response.Write oJSON.JSONoutput()
220
'OraSession.Dispose()
221
%>