%@LANGUAGE="VBSCRIPT"%> <% '===================================================== ' inManifest_state_json '===================================================== %> <% 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 SqlQry Dim rsQry Dim parRtagId : parRtagId = Request("rtag_id") Dim parShow : parShow = Request("show") Dim parShowImg : parShowImg = Request("showImg") ' 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 ' ' Global Filter ' Dim showHideFilter : showHideFilter = "" If parShow = "true" Then showHideFilter = showHideFilter & " AND rc.IN_MANIFEST = 'Y'" End If If parShowImg = "true" Then showHideFilter = showHideFilter & " AND NVL2(s3.PV_ID, 1, 0) = 1" End If ' Filter (search ) Dim searchString If Request.QueryString("search[value]") <> "" Then searchString = " AND upper(p.PKG_NAME || '_' || pv.PKG_VERSION ) LIKE upper('%" & Request.QueryString("search[value]") & "%')" End If ' ' Determine the size of the record set ' Gives bad results when searching Dim MaxCount : MaxCount = 0 SqlQry = "select count(*) as count " &_ " FROM package_versions pv, " &_ " RELEASE_CONTENT rc, " &_ " PACKAGES p, " &_ " (select rcp.* from release_components rcp, release_content rc where rc.rtag_id = "& parRtagId &" and rc.pv_id = rcp.pv_id AND RCP.FILE_NAME = 's3Transfer.json' AND RCP.FILE_PATH IS NULL ) s3 " &_ " WHERE rc.rtag_id = " & parRtagId &_ " AND rc.pv_id = pv.pv_id " &_ " AND p.PKG_ID = pv.pkg_id " &_ " AND s3.pv_id(+) = rc.pv_id " &_ searchString &_ showHideFilter oJSON.data("CountSqlQry") = SqlQry 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 ' iTotalRecords = total records without any filtering/limits ' iTotalDisplayRecords = filtered result count oJSON.data("draw") = CLng(Request.QueryString("draw")) oJSON.data("recordsTotal") = MaxCount oJSON.data("recordsFiltered") = MaxCount Dim vName for each vName in Request.QueryString oJSON.data("sReq_" & vName) = Request.QueryString(vName) next ' Extract selected range result = 0 dim firstRow,lastRow firstRow = CLng(Request.QueryString("start")) lastRow = firstRow + CLng(Request.QueryString("length")) ' Define the data items to extract from the database ' An array of items to extract ' Dim dataCols: dataCols = Array ( _ "pv.pv_id", _ "pv.pkg_id", _ "p.PKG_NAME", _ "pv.PKG_VERSION", _ "pv.PV_DESCRIPTION", _ "pv.v_ext", _ "rc.IN_MANIFEST", _ "pv.COMMENTS" ) ' Define array of colums to sort by ' Must match user sort column request Dim sortCols: sortCols = Array ( _ "pv.pv_id",_ "UPPER(p.PKG_NAME)",_ "UPPER(pv.PKG_VERSION)",_ "UPPER(pv.v_ext)",_ "UPPER(pv.PV_DESCRIPTION)",_ "UPPER(rc.IN_MANIFEST)" ) ' Dim determine sorting options 'On Error goto 0 'Response.Write "
"
' Dim determine sorting options
' Secondary sort by package name Entry(1)
Dim sortString
Dim sortColumn : sortColumn = CInt(Request.QueryString("order[0][column]"))
Dim sortDir : sortDir = Request.QueryString("order[0][dir]")
If sortColumn <> "" Then
sortString = " ORDER BY " & sortCols(sortColumn) & " " & sortDir
If sortColumn <> "1" Then
sortString = sortString & ", " & sortCols(CInt(1)) & " " & sortDir
End If
Else
sortString = " ORDER BY " & sortCols(CInt(1)) & " asc"
End If
' Create a list of cols that we need. Avoids ambiguity in selections
Dim x,colList,colListJoin
For x = Lbound(dataCols) to Ubound(dataCols)
colList = colList & colListJoin & dataCols(x)
colListJoin = ","
Next
Dim BasicSql
BasicSql = "select " & colList &_
" FROM package_versions pv, " &_
" RELEASE_CONTENT rc, " &_
" PACKAGES p, " &_
" (select rcp.* from release_components rcp, release_content rc where rc.rtag_id = "& parRtagId &" and rc.pv_id = rcp.pv_id AND RCP.FILE_NAME = 's3Transfer.json' AND RCP.FILE_PATH IS NULL ) s3 " &_
" WHERE rc.rtag_id = " & parRtagId &_
" AND rc.pv_id = pv.pv_id " &_
" AND p.PKG_ID = pv.pkg_id " &_
" AND s3.pv_id(+) = rc.pv_id " &_
searchString &_
showHideFilter &_
sortString
SqlQry = "select * from ( "&_
"select a.*, ROWNUM rnum from (" & BasicSql &_
") a where ROWNUM <= " & lastRow &_
") where rnum >= " & firstRow
' Assist in debug
oJSON.data("BasicSql") = BasicSql
oJSON.data("SqlQry") = SqlQry
' 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 to the 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 pkg_id : pkg_id = fields(1)
Dim pkg_name : pkg_name = fields(2)
Dim pkg_version : pkg_version = fields(3)
Dim description : description = Server.HTMLEncode(fields(4))
Dim v_ext : v_ext = fields(5)
Dim state : state = fields(6)
Dim comments : comments = CleanUpJson(Server.HTMLEncode(fields(7)))
Set fields = nothing
newitem(0) = pv_id
newitem(1) = "" & pkg_name & ""
newitem(2) = "" & pkg_version & ""
newitem(3) = v_ext
newitem(4) = description
newitem(5) = state
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
%>