%@LANGUAGE="VBSCRIPT"%> <% '===================================================== ' view_by_files_json.asp ' ' Provide dataTable information for pages that search for files ' 1) Global (no rtagId) ' 2) Within a Release (With rtagId and envtab) '===================================================== %> <% Option explicit ' Some searches may take a while Server.ScriptTimeout=400 ' 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, parEnvTab, parEnvTable parRtagId = Request("rtag_id") Dim parFileName parFileName = Request.Form("columns[1][search][value]") If parFileName = "" Then parFileName = Request("filename") End If ' Calculate the table to be used when limiting search to a EnvTab If parRtagId <> "" Then parEnvTab = Request("envtab") Select Case parEnvTab Case "0" : parEnvTable = "work_in_progress" Case "1" : parEnvTable = "planned" Case "3" : parEnvTable = "environment_view" Case Else : parEnvTable = "release_content" End Select End If ' 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 'On Error Resume Next ' ' Assist in debug oJSON.data("start") = CLng(Request.Form("start")) oJSON.data("length") = CLng(Request.Form("length")) '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 ( _ "pv.pv_id", _ "UPPER(art.file_name)",_ "UPPER(art.file_path)",_ "UPPER(pkg.pkg_name)",_ "UPPER(pv.pkg_version)",_ "UPPER(art.crc_cksum)" ) ' Dim determine sorting options 'On Error goto 0 'Response.Write "
"
Dim sortString
Dim sortJoin : sortJoin = " ORDER BY "
If Request.Form("order[0][column]") <> "" Then
Dim sortCol : sortCol = CInt(Request.Form("order[0][column]"))
Dim sortDir : sortDir = " " & Request.Form("order[0][dir]")
sortString = sortJoin & sortCols(sortCol)
sortString = sortString & sortDir
sortJoin = ","
Else
sortString = sortJoin & sortCols(CInt(1)) & " asc"
End If
' Filter (search )
' Support multicolumn filters
'
Dim searchString : searchString = ""
Dim maxCols :maxCols = 5 ' 0 .. maxCols
Dim colIdx, colData
For colIdx = 0 to maxCols
colData = Request.Form("columns["&colIdx&"][search][value]")
If colData <> "" Then
searchString = searchString + " AND " + sortCols(colIdx) + " LIKE UPPER('" + colData + "')"
End If
Next
If searchString = "" Then
searchString = "AND UPPER (art.file_name) LIKE UPPER ('"&parFileName&"') "
End If
Dim BasicSql, FromSql, WhereSql
FromSql = " FROM RELEASE_COMPONENTS art, " &_
" packages pkg, " &_
" PACKAGE_VERSIONS pv "
If parRtagId <> "" Then
FromSql = FromSql & "," & parEnvTable & " rc "
End If
WhereSql = " WHERE pv.PKG_ID = pkg.PKG_ID " &_
" AND art.pv_id = pv.pv_id " &_
" AND art.file_name is not null "
If parRtagId <> "" Then
WhereSql = WhereSql & " AND rc.rtag_id = "& parRtagId &" AND art.pv_id = rc.pv_id "
End If
BasicSql = "SELECT pv.pv_id, "&_
" art.file_name, " &_
" art.file_path, " &_
" pkg.pkg_name, " &_
" pv.pkg_version, " &_
" art.crc_cksum " &_
FromSql &_
WhereSql &_
searchString &_
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
' First query is to determine the overall size of the dataset
'
Dim SizeSql
Dim MaxCount : MaxCount = 0
SizeSql = "select count(*) as count " & FromSql & WhereSql & searchString
oJSON.data("iSql") = SizeSql
objEH.ErrorRedirect = FALSE
objEH.TryORA ( OraSession )
Set rsQry = OraDatabase.DbCreateDynaset( SizeSql, 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)
' Perform the full database query with pagination support
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
newitem(0) = fields(0) ' pvId
newitem(1) = fields(1) ' fileName
newitem(2) = fields(2) ' filePath
newitem(3) = fields(3) ' pkgName
newitem(4) = fields(4) ' pkgVersion
newitem(5) = fields(5) ' chkSum
Set fields = nothing
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()
' Cleanup
Set oJSON = Nothing
Call Destroy_All_Objects
%>