Subversion Repositories DevTools

Rev

Rev 5957 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5050 dpurdie 1
<%@LANGUAGE="VBSCRIPT"%>
2
<%
3
'=====================================================
5957 dpurdie 4
'       sdk_versions_json.asp
5050 dpurdie 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
'
6581 dpurdie 36
' Determine the MAX size of the record set, without any filtering
5050 dpurdie 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 &"'"
6581 dpurdie 41
oJSON.data("CountQry") = SqlQry
5050 dpurdie 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
 
5055 dpurdie 58
oJSON.data("draw") = CInt(Request.QueryString("draw"))
59
oJSON.data("recordsTotal") = MaxCount
6581 dpurdie 60
'oJSON.data("recordsFiltered") = MaxCount
5050 dpurdie 61
 
62
Dim vName
63
for each vName in Request.QueryString
64
    oJSON.data("sReq_" & vName) = Request.QueryString(vName)
65
next
66
 
67
' Extract selected range
68
result = 0
69
dim firstRow,lastRow
5055 dpurdie 70
firstRow = CInt(Request.QueryString("start"))
71
lastRow = firstRow + CInt(Request.QueryString("length"))
5050 dpurdie 72
 
73
' Define the data items to extract from the database
74
' An array of items to extract
75
'
76
Dim dataCols: dataCols = Array ( _ 
77
                "SDKTAG_ID" ,_
78
                "SDKTAG_NAME" ,_
79
                "DESCRIPTION" ,_
5055 dpurdie 80
                "TO_CHAR(CREATED_STAMP, 'Dy DD-Mon-YYYY HH24:MI:SS') as CREATED_STAMP_TXT" ,_
81
                "USER_NAME as CREATOR_NAME" ,_
5050 dpurdie 82
                "SDK_STATE" )
83
 
84
'   Define array of colums to sort by
85
'       Must match user sort column request
86
Dim sortCols: sortCols = Array ( _
87
                "SDKTAG_ID" ,_
88
                "UPPER(SDKTAG_NAME)" ,_
89
                "UPPER(DESCRIPTION)" ,_
5055 dpurdie 90
                "CREATED_STAMP" ,_
91
                "UPPER(CREATOR_NAME)" ,_
5050 dpurdie 92
                "UPPER(SDK_STATE)" )
93
 
94
' Dim determine sorting options
95
Dim sortString
5055 dpurdie 96
If Request.QueryString("order[0][column]") <> "" Then
97
    sortString = " ORDER BY " & sortCols(CInt(Request.QueryString("order[0][column]")))
98
    sortString = sortString & " " & Request.QueryString("order[0][dir]")
5050 dpurdie 99
Else
100
    sortString = " ORDER BY " & sortCols(CInt(1)) & " asc"
101
End If
102
 
103
' Filter (search )
6581 dpurdie 104
Dim searchString : searchString = ""
5055 dpurdie 105
If Request.QueryString("search[value]") <> "" Then
6581 dpurdie 106
    searchString = searchString + " AND upper(SDKTAG_NAME) LIKE upper('%" & Request.QueryString("search[value]") & "%')" 
5050 dpurdie 107
End If
108
 
5057 dpurdie 109
' Filter (state)
110
If Request.QueryString("sdkstateFilter") <> "" Then
6581 dpurdie 111
    searchString = searchString + " AND UPPER(SDK_STATE) in (" & Request.QueryString("sdkstateFilter") & ")" 
5057 dpurdie 112
End If
113
 
5050 dpurdie 114
' Create a list of cols that we need. Avoids ambiguity in selections
115
Dim x,colList,colListJoin
116
For x = Lbound(dataCols) to Ubound(dataCols)
117
    colList = colList & colListJoin & dataCols(x)
118
    colListJoin = ","
119
Next
120
 
121
Dim whereString
122
Dim BasicSql
123
BasicSql = "select " & colList &_
5055 dpurdie 124
            " FROM SDK_TAGS st, USERS u " &_
5050 dpurdie 125
            " where sdk_id = "&sdk_id &_
5055 dpurdie 126
            " AND st.CREATOR_ID = u.USER_ID(+)" &_
5050 dpurdie 127
            whereString &_
128
            searchString &_
129
            sortString
130
 
131
SqlQry = "select * from ( "&_
132
            "select a.*, ROWNUM rnum from (" & BasicSql &_
133
                ") a where ROWNUM <= " & lastRow &_
134
            ") where rnum >= " & firstRow
135
 
6581 dpurdie 136
'
137
'   Perform a query without pagination
138
'   Assume the record set is small enough that it won't impact speed
139
'
140
'
141
' Determine the size of the record set
142
'   Gives bad results when searching
143
Dim SqlCount: SqlCount = "select count(*) as count from (" & BasicSql & ")"
144
On Error Resume Next
145
objEH.ErrorRedirect = FALSE
146
objEH.TryORA ( OraSession )
147
Set rsQry = OraDatabase.DbCreateDynaset( SqlCount, ORADYN_DEFAULT )
148
objEH.CatchORA ( OraSession )
149
    If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) Then
150
        MaxCount = rsQry("COUNT")
151
    End If
152
rsQry.Close
153
Set rsQry = Nothing
154
 
155
' Basic Header
156
'   iTotalRecords = total records without any filtering/limits
157
'   iTotalDisplayRecords = filtered result count
158
 
159
'oJSON.data("recordsTotal") = MaxCount
160
oJSON.data("recordsFiltered") = MaxCount
161
 
162
 
5050 dpurdie 163
' Assist in debug
164
oJSON.data("BasicSql") = BasicSql
165
'oJSON.data("SqlQry") = SqlQry
166
 
167
' Perform the database query
168
Set oJSON.data("aaData") = oJSON.Collection()
169
On Error Resume Next
170
objEH.ErrorRedirect = FALSE
171
objEH.TryORA ( OraSession )
172
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
173
objEH.CatchORA ( OraSession )
174
' Process each row and return required fields to the user
175
If objEH.Finally Then
176
On Error goto 0
177
 
178
    While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
179
        Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
180
        Dim ii
181
        for ii = 0 to rsQry.Fields.Count - 2
182
            newitem (rsQry.FieldName(ii)) = rsQry.Fields(ii)
183
            'newitem (ii) = rsQry.Fields(ii)
184
        Next
185
       rsQry.MoveNext
186
    Wend
187
End IF
188
 
189
rsQry.Close
190
Set rsQry = Nothing
191
 
192
'
193
' SQL error detection and reporting
5055 dpurdie 194
'   The content of 'error' will be dsplayed to the user.
5050 dpurdie 195
If objEH.LastOraFailed Then
5055 dpurdie 196
    oJSON.data("error") = objEH.MessageSummary
5050 dpurdie 197
    oJSON.data("emsgDetails") = objEH.MessageDetails
198
    oJSON.data("SqlQry") = SqlQry
199
End If
200
 
201
'Return the object
202
Response.Write oJSON.JSONoutput()
5957 dpurdie 203
Set oJSON = Nothing
204
Call Destroy_All_Objects
5050 dpurdie 205
%>