Subversion Repositories DevTools

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5050 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
4
'       sdk_versions_json.asp.asp
5
'       Ajax support for table of SDK Versions
6
'       Designed to be driven by the jquery tablescroller
7
'=====================================================
8
%>
9
<%
10
Option explicit
11
' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK)
12
Response.ContentType = "text/html"
13
Response.AddHeader "Content-Type", "text/html;charset=UTF-8"
14
Response.CodePage = 65001
15
Response.CharSet = "UTF-8"
16
%>
17
<!--#include file="common/conf.asp"-->
18
<!--#include file="common/globals.asp"-->
19
<!--#include file="common/qstr.asp"-->
20
<!--#include file="common/common_subs.asp"-->
21
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
22
<%
23
'------------ Variable Definition -------------
24
Dim result : result = -1
25
Dim SqlQry
26
Dim rsQry
27
Dim sdk_id : sdk_id = Request("sdk_id")
28
 
29
' Init the output JSON class
30
'   Operations can add data
31
'   Default data will be added at the end
32
Dim oJSON :Set oJSON = New aspJSON
33
Dim newitem
34
 
35
'
36
' Determine the size of the record set
37
'   Gives bad results when searching
38
Dim MaxCount : MaxCount = 0
39
 
40
SqlQry = "select count(*) as count from SDK_TAGS st where sdk_id = '" & sdk_id &"'"
41
 
42
On Error Resume Next
43
objEH.ErrorRedirect = FALSE
44
objEH.TryORA ( OraSession )
45
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
46
objEH.CatchORA ( OraSession )
47
    If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
48
        MaxCount = rsQry("COUNT")
49
    End If
50
rsQry.Close
51
Set rsQry = Nothing
52
 
53
' Basic Header
54
'   iTotalRecords = total records without any filtering/limits
55
'   iTotalDisplayRecords = filtered result count
56
 
5055 dpurdie 57
oJSON.data("draw") = CInt(Request.QueryString("draw"))
58
oJSON.data("recordsTotal") = MaxCount
59
oJSON.data("recordsFiltered") = MaxCount
5050 dpurdie 60
 
61
Dim vName
62
for each vName in Request.QueryString
63
    oJSON.data("sReq_" & vName) = Request.QueryString(vName)
64
next
65
 
66
' Extract selected range
67
result = 0
68
dim firstRow,lastRow
5055 dpurdie 69
firstRow = CInt(Request.QueryString("start"))
70
lastRow = firstRow + CInt(Request.QueryString("length"))
5050 dpurdie 71
 
72
' Define the data items to extract from the database
73
' An array of items to extract
74
'
75
Dim dataCols: dataCols = Array ( _ 
76
                "SDKTAG_ID" ,_
77
                "SDKTAG_NAME" ,_
78
                "DESCRIPTION" ,_
5055 dpurdie 79
                "TO_CHAR(CREATED_STAMP, 'Dy DD-Mon-YYYY HH24:MI:SS') as CREATED_STAMP_TXT" ,_
80
                "USER_NAME as CREATOR_NAME" ,_
5050 dpurdie 81
                "SDK_STATE" )
82
 
83
'   Define array of colums to sort by
84
'       Must match user sort column request
85
Dim sortCols: sortCols = Array ( _
86
                "SDKTAG_ID" ,_
87
                "UPPER(SDKTAG_NAME)" ,_
88
                "UPPER(DESCRIPTION)" ,_
5055 dpurdie 89
                "CREATED_STAMP" ,_
90
                "UPPER(CREATOR_NAME)" ,_
5050 dpurdie 91
                "UPPER(SDK_STATE)" )
92
 
93
' Dim determine sorting options
94
Dim sortString
5055 dpurdie 95
If Request.QueryString("order[0][column]") <> "" Then
96
    sortString = " ORDER BY " & sortCols(CInt(Request.QueryString("order[0][column]")))
97
    sortString = sortString & " " & Request.QueryString("order[0][dir]")
5050 dpurdie 98
Else
99
    sortString = " ORDER BY " & sortCols(CInt(1)) & " asc"
100
End If
101
 
102
' Filter (search )
103
Dim searchString
5055 dpurdie 104
If Request.QueryString("search[value]") <> "" Then
105
    searchString = " AND upper(pkg_name) LIKE upper('%" & Request.QueryString("search[value]") & "%')" 
5050 dpurdie 106
End If
107
 
108
' Create a list of cols that we need. Avoids ambiguity in selections
109
Dim x,colList,colListJoin
110
For x = Lbound(dataCols) to Ubound(dataCols)
111
    colList = colList & colListJoin & dataCols(x)
112
    colListJoin = ","
113
Next
114
 
115
Dim whereString
116
Dim BasicSql
117
BasicSql = "select " & colList &_
5055 dpurdie 118
            " FROM SDK_TAGS st, USERS u " &_
5050 dpurdie 119
            " where sdk_id = "&sdk_id &_
5055 dpurdie 120
            " AND st.CREATOR_ID = u.USER_ID(+)" &_
5050 dpurdie 121
            whereString &_
122
            searchString &_
123
            sortString
124
 
125
SqlQry = "select * from ( "&_
126
            "select a.*, ROWNUM rnum from (" & BasicSql &_
127
                ") a where ROWNUM <= " & lastRow &_
128
            ") where rnum >= " & firstRow
129
 
130
' Assist in debug
131
oJSON.data("BasicSql") = BasicSql
132
'oJSON.data("SqlQry") = SqlQry
133
 
134
' Perform the database query
135
Set oJSON.data("aaData") = oJSON.Collection()
136
On Error Resume Next
137
objEH.ErrorRedirect = FALSE
138
objEH.TryORA ( OraSession )
139
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
140
objEH.CatchORA ( OraSession )
141
' Process each row and return required fields to the user
142
If objEH.Finally Then
143
On Error goto 0
144
 
145
    While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
146
        Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
147
        Dim ii
148
        for ii = 0 to rsQry.Fields.Count - 2
149
            newitem (rsQry.FieldName(ii)) = rsQry.Fields(ii)
150
            'newitem (ii) = rsQry.Fields(ii)
151
        Next
152
       rsQry.MoveNext
153
    Wend
154
End IF
155
 
156
rsQry.Close
157
Set rsQry = Nothing
158
 
159
'
160
' SQL error detection and reporting
5055 dpurdie 161
'   The content of 'error' will be dsplayed to the user.
5050 dpurdie 162
If objEH.LastOraFailed Then
5055 dpurdie 163
    oJSON.data("error") = objEH.MessageSummary
5050 dpurdie 164
    oJSON.data("emsgDetails") = objEH.MessageDetails
165
    oJSON.data("SqlQry") = SqlQry
166
End If
167
 
168
'Return the object
169
Response.Write oJSON.JSONoutput()
170
'OraSession.Dispose()
171
%>