%@LANGUAGE="VBSCRIPT"%> <% '===================================================== ' build_release_log_json.asp '===================================================== %> <% Option explicit ' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK) Response.ContentType = "text/html" Response.AddHeader "Content-Type", "text/html;charset=UTF-8" Response.CodePage = 65001 Response.CharSet = "UTF-8" %> <% '------------ Variable Definition ------------- Dim result : result = -1 Dim joiner Dim SqlQry Dim rsQry Dim parRtagId : parRtagId = Request.Form("rtag_id") Dim parReason : parReason = Request.Form("fReason") Dim parResult : parResult = Request.Form("fResult") ' Init the output JSON class ' Operations can add data ' Default data will be added at the end Dim oJSON :Set oJSON = New aspJSON Dim newitem ' Filter Results and Reason Dim sResult : sResult = "" If parResult <> "" Then joiner = "" If InStr(parResult, "C") <> 0 Then sResult = sResult & "'C'" : joiner = "," If InStr(parResult, "E") <> 0 Then sResult = sResult & joiner & "'E'" : joiner = "," If InStr(parResult, "O") <> 0 Then sResult = sResult & joiner & "'B'," & "'S'" If sResult <> "" Then sResult = " AND bi.state in (" & sResult & ")" End If End If Dim sReason : sReason = "" If parReason <> "" Then joiner = "" If InStr(parReason, "N") <> 0 Then sReason = sReason & joiner & "'N'" : joiner = "," If InStr(parReason, "R") <> 0 Then sReason = sReason & joiner & "'R'" : joiner = "," If InStr(parReason, "T") <> 0 Then sReason = sReason & joiner & "'T'" : joiner = "," If InStr(parReason, "P") <> 0 Then sReason = sReason & joiner & "'P'" : joiner = "," If InStr(parReason, "F") <> 0 Then sReason = sReason & joiner & "'F'" : joiner = "," If sReason <> "" Then sReason = " AND bi.reason in (" & sReason & ")" End If End If ' ' Determine the size of the record set ' Gives bad results when searching Dim MaxCount : MaxCount = 0 SqlQry = "select count(*) as count from BUILD_INSTANCES bi WHERE bi.state is not null " & sResult & sReason If parRtagId <> "" Then SqlQry = SqlQry + " AND rtag_id = " & parRtagId End If On Error Resume Next objEH.ErrorRedirect = FALSE objEH.TryORA ( OraSession ) Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT ) objEH.CatchORA ( OraSession ) If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then MaxCount = rsQry("COUNT") End If rsQry.Close Set rsQry = Nothing ' Basic Header ' recordsTotal = total records without any filtering/limits ' recordsFiltered = filtered result count oJSON.data("draw") = CLng(Request.Form("draw")) oJSON.data("recordsTotal") = CLng(MaxCount) oJSON.data("recordsFiltered") = CLng(MaxCount) ' Assist in debug oJSON.data("start") = CLng(Request.Form("start")) oJSON.data("length") = CLng(Request.Form("length")) oJSON.data("iSql") = SqlQry 'Dim vName 'for each vName in Request.QueryString ' oJSON.data("sReq_" & vName) = Request(vName) 'next 'For Each vName In Request.Form ' oJSON.data("sFrm_" & vName) = Request(vName) 'Next ' Extract selected range result = 0 dim firstRow,lastRow,noBuildTime firstRow = CLng(Request.Form("start")) lastRow = firstRow + CLng(Request.Form("length")) ' Define array of colums to sort by ' Must match user sort column request Dim sortCols: sortCols = Array ( _ "UPPER(pj.PROJ_NAME)",_ "UPPER(rt.RTAG_NAME),build_id",_ "UPPER(p.PKG_NAME),build_id",_ "UPPER(p.PKG_NAME),UPPER(pv.PKG_VERSION)",_ "bi.BUILD_ID",_ "UPPER(bi.reason),build_id",_ "build_time,build_id,NOBUILDTIME",_ "UPPER(bi.state),build_id",_ "build_id" ) ' Dim determine sorting options 'On Error goto 0 'Response.Write "
"
Dim sortString
If Request.Form("order[0][column]") <> "" Then
Dim sortCol : sortCol = CInt(Request.Form("order[0][column]"))
Dim sortDir : sortDir = " " & Request.Form("order[0][dir]")
Dim splitArg: splitArg = Split( sortCols(sortCol), "," )
Dim splitItem
joiner = ""
for each splitItem in splitArg
If splitItem = "NOBUILDTIME" Then
noBuildTime = " AND PV.BUILD_TIME is not null"
Else
sortString = sortString & joiner & splitItem & " " & sortDir
joiner = ","
End If
next
sortString = " ORDER BY " & sortString
End If
' Filter (search )
Dim searchString
If Request.Form("search[value]") <> "" Then
searchString = " AND upper(p.PKG_NAME) LIKE upper('%" & Request.Form("search[value]") & "%')"
End If
Dim whereString
If parRtagId <> "" Then
whereString = " AND bi.rtag_id = " & parRtagId
End If
Dim BasicSql
BasicSql = "SELECT bi.PV_ID, " &_
" bi.RTAG_ID, " &_
" pv.pkg_id, " &_
" pj.PROJ_NAME, " &_
" pj.PROJ_ID, " &_
" RTAG_NAME, " &_
" p.PKG_NAME, " &_
" NVL(pv.V_EXT, '') AS V_EXT, " &_
" TO_CHAR(bi.TIMESTAMP, 'Dy DD-Mon-YYYY HH24:MI:SS') AS TIMESTAMPTXT, " &_
" DECODE(bi.reason, 'N', 'New Version', 'R', 'Ripple', 'T', 'Test', 'P', 'Restored', 'F', 'ForcedRipple', 'Unknown') AS REASON, " &_
" DECODE(bi.state, 'B', 'Buiding', 'C', 'Complete', 'E', 'Error', 'S', 'SysErr', 'Unknown') AS STATE, " &_
" bi.build_id, " &_
" bi.build_ref " &_
"FROM BUILD_INSTANCES bi, " &_
" projects pj, " &_
" RELEASE_TAGS rt, " &_
" packages p, " &_
" PACKAGE_VERSIONS pv " &_
"WHERE bi.PV_ID = pv.pv_id " &_
"AND pv.PKG_ID = p.PKG_ID " &_
"AND bi.RTAG_ID = rt.RTAG_ID " &_
"AND rt.proj_id = pj.proj_id " &_
sResult & sReason &_
noBuildTime &_
whereString &_
searchString &_
sortString
SqlQry = "Select z.*," &_
"(SELECT COUNT(*) FROM TEST_RUN tr WHERE tr.build_id = z.build_id ) AS test_count, " &_
"(SELECT PKG_VERSION FROM PACKAGE_VERSIONS pv1 WHERE pv1.pv_id = z.pv_id ) AS PKG_VERSION, " &_
"(SELECT PV_DESCRIPTION FROM PACKAGE_VERSIONS pv1 WHERE pv1.pv_id = z.pv_id ) AS PV_DESCRIPTION, " &_
"(SELECT COMMENTS FROM PACKAGE_VERSIONS pv1 WHERE pv1.pv_id = z.pv_id ) AS COMMENTS, " &_
"(SELECT BUILD_TIME FROM PACKAGE_VERSIONS pv1 WHERE pv1.pv_id = z.pv_id ) AS BUILD_TIME" &_
" from (select * from ( "&_
"select /*+ FIRST_ROWS("& lastRow &") */ a.*, ROWNUM rnum from (" & BasicSql &_
") a where ROWNUM <= " & lastRow &_
") where rnum >= " & firstRow & ") z"
' Assist in debug
oJSON.data("BasicSql") = BasicSql
oJSON.data("SqlQry") = SqlQry
oJSON.data("sqlFilter") = sResult & sReason
' Perform the database query
Set oJSON.data("data") = oJSON.Collection()
On Error Resume Next
objEH.ErrorRedirect = FALSE
objEH.TryORA ( OraSession )
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
objEH.CatchORA ( OraSession )
' Process each row and return required fields to the user
If objEH.Finally Then
While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
Set newitem = oJSON.AddToCollection(oJSON.data("data"))
' Attempt to speed up access tot he data
' Extract all fields for the row
' Access fields by index
Dim fields
Set fields = rsQry.Fields
Dim pv_id : pv_id = fields(0)
Dim rtag_id : rtag_id = fields(1)
Dim pkg_id : pkg_id = fields(2)
Dim proj_name : proj_name = fields(3)
Dim proj_id : proj_id = fields(4)
Dim rtag_name : rtag_name = fields(5)
Dim pkg_name : pkg_name = fields(6)
Dim v_ext : v_ext = fields(7)
Dim timestamp : timestamp = fields(8)
Dim reason : reason = fields(9)
Dim state : state = fields(10)
Dim buildId : buildId = fields(11)
Dim buildRef : buildRef = fields(12)
Dim tcount : tcount = fields(14)
Dim pkg_version : pkg_version = fields(15)
Dim description : description = CleanUpJson(Server.HTMLEncode(fields(16)))
Dim comments : comments = CleanUpJson(Server.HTMLEncode(fields(17)))
Dim buildTime : buildTime = Server.HTMLEncode(fields(18))
Dim buildLog : buildLog = ""
Set fields = nothing
If buildTime <= 0 Then buildTime = ""
If tcount <= 0 Then tcount = ""
If buildRef <> "" Then
BuildLog = ""
Else
BuildLog = ""
End If
newitem(0) = "" & proj_name &""
newitem(1) = "" & rtag_name & ""
newitem(2) = "" & pkg_name & ""
newitem(3) = "" & pkg_version & ""
newitem(4) = timestamp
newitem(5) = reason
newitem(6) = buildTime
newitem(7) = "" & state & ""
newitem(8) = tcount
newitem(9) = BuildLog
rsQry.MoveNext
Wend
End IF
rsQry.Close
Set rsQry = Nothing
'
' SQL error detection and reporting
If objEH.LastOraFailed Then
oJSON.data("error") = 1
oJSON.data("emsgSummary") = objEH.MessageSummary
oJSON.data("emsgDetails") = objEH.MessageDetails
oJSON.data("SqlQry") = SqlQry
End If
'Return the object
Response.Write oJSON.JSONoutput()
Set oJSON = Nothing
Call Destroy_All_Objects
%>