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
 
57
oJSON.data("sEcho") = CInt(Request.QueryString("sEcho"))
58
oJSON.data("iTotalRecords") = MaxCount
59
oJSON.data("iTotalDisplayRecords") = MaxCount
60
 
61
' Assist in debug
62
oJSON.data("iReqDisplayStart") = CInt(Request.QueryString("iDisplayStart"))
63
oJSON.data("iReqDisplayLength") = CInt(Request.QueryString("iDisplayLength"))
64
 
65
Dim vName
66
for each vName in Request.QueryString
67
    oJSON.data("sReq_" & vName) = Request.QueryString(vName)
68
next
69
 
70
' Extract selected range
71
result = 0
72
dim firstRow,lastRow
73
firstRow = CInt(Request.QueryString("iDisplayStart"))
74
lastRow = firstRow + CInt(Request.QueryString("iDisplayLength"))
75
 
76
' Define the data items to extract from the database
77
' An array of items to extract
78
'
79
Dim dataCols: dataCols = Array ( _ 
80
                "SDKTAG_ID" ,_
81
                "SDKTAG_NAME" ,_
82
                "DESCRIPTION" ,_
83
                "SDK_STATE" )
84
 
85
'   Define array of colums to sort by
86
'       Must match user sort column request
87
Dim sortCols: sortCols = Array ( _
88
                "SDKTAG_ID" ,_
89
                "UPPER(SDKTAG_NAME)" ,_
90
                "UPPER(DESCRIPTION)" ,_
91
                "UPPER(SDK_STATE)" )
92
 
93
' Dim determine sorting options
94
'On Error goto 0
95
'Response.Write "<pre>"
96
Dim sortString
97
If Request.QueryString("iSortCol_0") <> "" Then
98
    sortString = " ORDER BY " & sortCols(CInt(Request.QueryString("iSortCol_0")))
99
    sortString = sortString & " " & Request.QueryString("sSortDir_0")
100
Else
101
    sortString = " ORDER BY " & sortCols(CInt(1)) & " asc"
102
End If
103
 
104
' Filter (search )
105
Dim searchString
106
If Request.QueryString("sSearch") <> "" Then
107
    searchString = " AND upper(pkg_name) LIKE upper('%" & Request.QueryString("sSearch") & "%')" 
108
End If
109
 
110
' Create a list of cols that we need. Avoids ambiguity in selections
111
Dim x,colList,colListJoin
112
For x = Lbound(dataCols) to Ubound(dataCols)
113
    colList = colList & colListJoin & dataCols(x)
114
    colListJoin = ","
115
Next
116
 
117
Dim whereString
118
Dim BasicSql
119
BasicSql = "select " & colList &_
120
            " FROM SDK_TAGS " &_
121
            " where sdk_id = "&sdk_id &_
122
            whereString &_
123
            searchString &_
124
            sortString
125
 
126
SqlQry = "select * from ( "&_
127
            "select a.*, ROWNUM rnum from (" & BasicSql &_
128
                ") a where ROWNUM <= " & lastRow &_
129
            ") where rnum >= " & firstRow
130
 
131
' Assist in debug
132
oJSON.data("BasicSql") = BasicSql
133
'oJSON.data("SqlQry") = SqlQry
134
 
135
' Perform the database query
136
Set oJSON.data("aaData") = oJSON.Collection()
137
On Error Resume Next
138
objEH.ErrorRedirect = FALSE
139
objEH.TryORA ( OraSession )
140
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
141
objEH.CatchORA ( OraSession )
142
' Process each row and return required fields to the user
143
If objEH.Finally Then
144
On Error goto 0
145
 
146
    While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
147
        Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
148
        Dim ii
149
        for ii = 0 to rsQry.Fields.Count - 2
150
            newitem (rsQry.FieldName(ii)) = rsQry.Fields(ii)
151
            'newitem (ii) = rsQry.Fields(ii)
152
        Next
153
       rsQry.MoveNext
154
    Wend
155
End IF
156
 
157
rsQry.Close
158
Set rsQry = Nothing
159
 
160
'
161
' SQL error detection and reporting
162
If objEH.LastOraFailed Then
163
    oJSON.data("error") = 1
164
 
165
    oJSON.data("emsgSummary") = objEH.MessageSummary
166
    oJSON.data("emsgDetails") = objEH.MessageDetails
167
    oJSON.data("SqlQry") = SqlQry
168
End If
169
 
170
'Return the object
171
Response.Write oJSON.JSONoutput()
172
'OraSession.Dispose()
173
%>