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_content_json.asp
5
'       Ajax support for table of SDK Content
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 sdktag_id : sdktag_id = Request("sdktag_id")
5052 dpurdie 28
Dim sdk_statefilter : sdk_statefilter = Request("sdk_statefilter")
5050 dpurdie 29
 
30
' Init the output JSON class
31
'   Operations can add data
32
'   Default data will be added at the end
33
Dim oJSON :Set oJSON = New aspJSON
34
Dim newitem
35
 
36
'
37
' Determine the size of the record set
38
'   Gives bad results when searching
39
Dim MaxCount : MaxCount = 0
40
 
41
SqlQry = "select count(*) as count from SDK_CONTENT skc where SDKTAG_ID = '" & sdktag_id &"'"
42
 
43
On Error Resume Next
44
objEH.ErrorRedirect = FALSE
45
objEH.TryORA ( OraSession )
46
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
47
objEH.CatchORA ( OraSession )
48
    If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
49
        MaxCount = rsQry("COUNT")
50
    End If
51
rsQry.Close
52
Set rsQry = Nothing
53
 
54
' Basic Header
55
'   iTotalRecords = total records without any filtering/limits
56
'   iTotalDisplayRecords = filtered result count
57
 
58
oJSON.data("sEcho") = CInt(Request.QueryString("sEcho"))
59
oJSON.data("iTotalRecords") = MaxCount
60
oJSON.data("iTotalDisplayRecords") = MaxCount
61
 
62
' Assist in debug
63
oJSON.data("iReqDisplayStart") = CInt(Request.QueryString("iDisplayStart"))
64
oJSON.data("iReqDisplayLength") = CInt(Request.QueryString("iDisplayLength"))
65
 
66
Dim vName
67
for each vName in Request.QueryString
68
    oJSON.data("sReq_" & vName) = Request.QueryString(vName)
69
next
70
 
71
' Extract selected range
72
result = 0
73
dim firstRow,lastRow
74
firstRow = CInt(Request.QueryString("iDisplayStart"))
75
lastRow = firstRow + CInt(Request.QueryString("iDisplayLength"))
76
 
77
' Define the data items to extract from the database
78
' An array of items to extract
79
'
80
Dim dataCols: dataCols = Array ( _ 
81
        "sc.pv_id", _
82
        "p.pkg_name", _
83
        "pv.pkg_version", _
84
        "sc.sdkpkg_state" )
85
 
86
'   Define array of colums to sort by
87
'       Must match user sort column request
88
Dim sortCols: sortCols = Array ( _
89
        "sc.pv_id", _
90
        "UPPER(p.pkg_name)", _
91
        "UPPER(pv.pkg_version)", _
92
        "UPPER(sc.sdkpkg_state)" )
93
 
94
' Dim determine sorting options
95
'On Error goto 0
96
'Response.Write "<pre>"
97
Dim sortString
98
If Request.QueryString("iSortCol_0") <> "" Then
99
    sortString = " ORDER BY " & sortCols(CInt(Request.QueryString("iSortCol_0")))
100
    sortString = sortString & " " & Request.QueryString("sSortDir_0")
5052 dpurdie 101
    sortString = sortString & "," & sortCols(CInt(1)) & " asc"
5050 dpurdie 102
Else
103
    sortString = " ORDER BY " & sortCols(CInt(1)) & " asc"
104
End If
105
 
106
' Filter (search )
5052 dpurdie 107
Dim searchString : searchString = ""
5050 dpurdie 108
If Request.QueryString("sSearch") <> "" Then
5052 dpurdie 109
    searchString = " AND upper(pkg_name) || '_' || UPPER(pv.pkg_version) LIKE upper('%" & Request.QueryString("sSearch") & "%')" 
5050 dpurdie 110
End If
111
 
5052 dpurdie 112
If sdk_statefilter Then
113
    searchString = searchString & " AND sc.sdkpkg_state in ('E')"
114
End If
115
 
5050 dpurdie 116
' Create a list of cols that we need. Avoids ambiguity in selections
117
Dim x,colList,colListJoin
118
For x = Lbound(dataCols) to Ubound(dataCols)
119
    colList = colList & colListJoin & dataCols(x)
120
    colListJoin = ","
121
Next
122
 
123
Dim whereString
124
Dim BasicSql
125
BasicSql = "select " & colList &_
126
            " FROM SDK_CONTENT SC , PACKAGE_VERSIONS pv, PACKAGES p " &_
127
            " where sc.sdktag_id = "&sdktag_id&" AND pv.pv_id = sc.pv_id AND p.pkg_id = pv.pkg_id " &_
128
            whereString &_
129
            searchString &_
130
            sortString
131
 
132
SqlQry = "select * from ( "&_
133
            "select a.*, ROWNUM rnum from (" & BasicSql &_
134
                ") a where ROWNUM <= " & lastRow &_
135
            ") where rnum >= " & firstRow
136
 
137
' Assist in debug
138
oJSON.data("BasicSql") = BasicSql
139
'oJSON.data("SqlQry") = SqlQry
140
 
141
' Perform the database query
142
Set oJSON.data("aaData") = oJSON.Collection()
143
On Error Resume Next
144
objEH.ErrorRedirect = FALSE
145
objEH.TryORA ( OraSession )
146
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
147
objEH.CatchORA ( OraSession )
148
' Process each row and return required fields to the user
149
If objEH.Finally Then
150
On Error goto 0
151
 
152
    While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
153
        Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
154
        Dim ii
155
        for ii = 0 to rsQry.Fields.Count - 2
156
            newitem (rsQry.FieldName(ii)) = rsQry.Fields(ii)
157
            'newitem (ii) = rsQry.Fields(ii)
158
        Next
159
       rsQry.MoveNext
160
    Wend
161
End IF
162
 
163
rsQry.Close
164
Set rsQry = Nothing
165
 
166
'
167
' SQL error detection and reporting
168
If objEH.LastOraFailed Then
169
    oJSON.data("error") = 1
170
 
171
    oJSON.data("emsgSummary") = objEH.MessageSummary
172
    oJSON.data("emsgDetails") = objEH.MessageDetails
173
    oJSON.data("SqlQry") = SqlQry
174
End If
175
 
176
'Return the object
177
Response.Write oJSON.JSONoutput()
178
'OraSession.Dispose()
179
%>