Rev 5394 | Rev 6538 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
<%@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 = 65001Response.CharSet = "UTF-8"%><!--#include file="common/conf.asp"--><!--#include file="common/globals.asp"--><!--#include file="common/qstr.asp"--><!--#include file="common/common_subs.asp"--><SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT><%'------------ Variable Definition -------------Dim result : result = -1Dim SqlQryDim rsQryDim parRtagId : parRtagId = Request("rtag_id")' Init the output JSON class' Operations can add data' Default data will be added at the endDim oJSON :Set oJSON = New aspJSONDim newitem'' Determine the size of the record set' Gives bad results when searchingDim MaxCount : MaxCount = 0SqlQry = "select count(*) as count from BUILD_INSTANCES bi"If parRtagId <> "" ThenSqlQry = SqlQry + " WHERE rtag_id = " & parRtagIdEnd IfOn Error Resume NextobjEH.ErrorRedirect = FALSEobjEH.TryORA ( OraSession )Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )objEH.CatchORA ( OraSession )If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) ThenMaxCount = rsQry("COUNT")End IfrsQry.CloseSet rsQry = Nothing' Basic Header' iTotalRecords = total records without any filtering/limits' iTotalDisplayRecords = filtered result countoJSON.data("sEcho") = CLng(Request.QueryString("sEcho"))oJSON.data("iTotalRecords") = MaxCountoJSON.data("iTotalDisplayRecords") = MaxCount' Assist in debugoJSON.data("iReqDisplayStart") = CLng(Request.QueryString("iDisplayStart"))oJSON.data("iReqDisplayLength") = CLng(Request.QueryString("iDisplayLength"))Dim vNamefor each vName in Request.QueryStringoJSON.data("sReq_" & vName) = Request.QueryString(vName)next' Extract selected rangeresult = 0dim firstRow,lastRowfirstRow = CLng(Request.QueryString("iDisplayStart"))lastRow = firstRow + CLng(Request.QueryString("iDisplayLength"))' Define the data items to extract from the database' An array of items to extract'Dim dataCols: dataCols = Array ( _"bi.PV_ID", _"bi.RTAG_ID" ,_"pv.pkg_id", _"pj.PROJ_NAME", _"pj.PROJ_ID", _"RTAG_NAME", _"p.PKG_NAME", _"pv.PKG_VERSION", _"pv.PV_DESCRIPTION", _"pv.COMMENTS", _"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', 'Unknown') as REASON" ,_"DECODE(bi.state, 'B', 'Buiding', 'C', 'Complete', 'E', 'Error', 'S', 'SysErr', 'Unknown') as STATE",_"bi.build_id" )' Define array of colums to sort by' Must match user sort column requestDim sortCols: sortCols = Array ( _"UPPER(pj.PROJ_NAME)",_"UPPER(rt.RTAG_NAME)",_"UPPER(p.PKG_NAME)",_"UPPER(pv.PKG_VERSION)",_"bi.BUILD_ID",_"UPPER(bi.reason)",_"UPPER(bi.state)",_"build_id" )' Dim determine sorting options'On Error goto 0'Response.Write "<pre>"Dim sortStringIf Request.QueryString("iSortCol_0") <> "" ThensortString = " ORDER BY " & sortCols(CLng(Request.QueryString("iSortCol_0")))sortString = sortString & " " & Request.QueryString("sSortDir_0")End If' Filter (search )Dim searchStringIf Request.QueryString("sSearch") <> "" ThensearchString = " AND upper(p.PKG_NAME) LIKE upper('%" & Request.QueryString("sSearch") & "%')"End If' Create a list of cols that we need. Avoids ambiguity in selectionsDim x,colList,colListJoinFor x = Lbound(dataCols) to Ubound(dataCols)colList = colList & colListJoin & dataCols(x)colListJoin = ","NextDim whereStringIf parRtagId <> "" ThenwhereString = " AND bi.rtag_id = " & parRtagIdEnd IfDim BasicSqlBasicSql = "select " & colList &_" 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" &_whereString &_searchString &_sortStringSqlQry = "Select z.*, (SELECT COUNT(*) FROM TEST_RUN tr WHERE tr.build_id = z.build_id ) AS test_count from (select * from ( "&_"select /*+ FIRST_ROWS(n) */ a.*, ROWNUM rnum from (" & BasicSql &_") a where ROWNUM <= " & lastRow &_") where rnum >= " & firstRow & ") z"' Assist in debugoJSON.data("BasicSql") = BasicSqloJSON.data("SqlQry") = SqlQry' Perform the database querySet oJSON.data("aaData") = oJSON.Collection()On Error Resume NextobjEH.ErrorRedirect = FALSEobjEH.TryORA ( OraSession )Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )objEH.CatchORA ( OraSession )' Process each row and return required fields to the userIf objEH.Finally ThenWhile (NOT rsQry.BOF) AND (NOT rsQry.EOF)Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))' Attempt to speed up access tot he data' Extract all fields for the row' Access fields by indexDim fieldsSet fields = rsQry.FieldsDim 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 pkg_id : pkg_id = fields(2)Dim v_ext : v_ext = fields(10)Dim description : description = Server.HTMLEncode(fields(8))Dim pv_id : pv_id = fields(0)Dim rtag_id : rtag_id = fields(1)Dim comments : comments = Server.HTMLEncode(fields(9))Dim pkg_version : pkg_version = fields(7)Dim timestamp : timestamp = fields(11)Dim reason : reason = fields(12)Dim state : state = fields(13)Dim tcount : tcount = fields(16)Set fields = nothingnewitem(0) = "<a href='rtree.asp?proj_id=" & proj_id & "'>" & proj_name & "</a>"newitem(1) = "<a href='dependencies.asp?rtag_id=" & rtag_id & "'>" & rtag_name & "</a>"newitem(2) = "<a href=view_by_version.asp?pkg_id=" & pkg_id & "&fpkgversion=*" & v_ext & " title=""" & description & """>" & pkg_name & "</a>"newitem(3) = "<a href='dependencies.asp?pv_id=" & pv_id & "&rtag_id=" & rtag_id &"' title=""" & comments & """>" & pkg_version & "</a>"newitem(4) = timestampnewitem(5) = reasonnewitem(6) = "<a href='unit_test_log.asp?rtag_id=" & rtag_id & "&pv_id=" & pv_id & "'>" & state & "</a>"If tcount <= 0 Then tcount = ""newitem(7) = tcountrsQry.MoveNextWendEnd IFrsQry.CloseSet rsQry = Nothing'' SQL error detection and reportingIf objEH.LastOraFailed ThenoJSON.data("error") = 1oJSON.data("emsgSummary") = objEH.MessageSummaryoJSON.data("emsgDetails") = objEH.MessageDetailsoJSON.data("SqlQry") = SqlQryEnd If'Return the objectResponse.Write oJSON.JSONoutput()'OraSession.Dispose()%>