Subversion Repositories DevTools

Rev

Blame | Last modification | View Log | RSS feed

<%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'       view_snapshots_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"
%>
<!--#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 = -1
Dim SqlQry
Dim rsQry
Dim parRtagId : parRtagId = Request("rtag_id")

' 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 = ""

' Filter (search )
Dim searchString
If Request.QueryString("search[value]") <> "" Then
    searchString = " AND upper(rt.rtag_name || '_' || TO_CHAR(rt.created_stamp,'DD-Mon-YYYY hh24:mi:ss') || '_' ||  rt.description) 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 RELEASE_TAGS rt " &_
            " WHERE rt.parent_rtag_id = " & parRtagId &_
            " AND OFFICIAL = 'S'" &_
            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 ( _
        "rt.rtag_id", _
        "rt.rtag_name", _
        "TO_CHAR(rt.created_stamp,'DD-Mon-YYYY hh24:mi:ss') AS created_stamp", _
        "rt.description", _
        "rt.s3Manifest", _
        "rt.s3Manifest_Done" )

'   Define array of colums to sort by
'       Must match user sort column request
Dim sortCols: sortCols = Array ( _
        "rt.rtag_id",_
        "UPPER(rt.rtag_name)",_
        "rt.created_stamp",_
        "UPPER(rt.description)",_
        "rt.s3Manifest",_
        "rt.s3Manifest_Done" )

' Dim determine sorting options
'On Error goto 0
'Response.Write "<pre>"

' 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 RELEASE_TAGS rt " &_
            " WHERE rt.parent_rtag_id = " & parRtagId &_
            " AND OFFICIAL = 'S'" &_
            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 rtag_id         : rtag_id = fields(0)
        Dim rtag_name       : rtag_name = fields(1)
        Dim created_stamp   : created_stamp = fields(2)
        Dim description     : description = CleanUpJson(Server.HTMLEncode(fields(3)))
        Dim s3Manifest      : s3Manifest = fields(4)
        Dim s3Manifest_Done : s3Manifest_Done = fields(5)

        Set fields = nothing

        newitem(0) = rtag_id
        newitem(1) = rtag_name
        newitem(2) = created_stamp
        newitem(3) = description
        newitem(4) = s3Manifest
        newitem(5) = s3Manifest_Done

        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
%>