Subversion Repositories DevTools

Rev

Rev 5057 | Rev 5957 | Go to most recent revision | Details | Compare with Previous | 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
 
5057 dpurdie 108
' Filter (state)
109
If Request.QueryString("sdkstateFilter") <> "" Then
110
    searchString = " AND UPPER(SDK_STATE) in (" & Request.QueryString("sdkstateFilter") & ")" 
111
End If
112
 
5050 dpurdie 113
' Create a list of cols that we need. Avoids ambiguity in selections
114
Dim x,colList,colListJoin
115
For x = Lbound(dataCols) to Ubound(dataCols)
116
    colList = colList & colListJoin & dataCols(x)
117
    colListJoin = ","
118
Next
119
 
120
Dim whereString
121
Dim BasicSql
122
BasicSql = "select " & colList &_
5055 dpurdie 123
            " FROM SDK_TAGS st, USERS u " &_
5050 dpurdie 124
            " where sdk_id = "&sdk_id &_
5055 dpurdie 125
            " AND st.CREATOR_ID = u.USER_ID(+)" &_
5050 dpurdie 126
            whereString &_
127
            searchString &_
128
            sortString
129
 
130
SqlQry = "select * from ( "&_
131
            "select a.*, ROWNUM rnum from (" & BasicSql &_
132
                ") a where ROWNUM <= " & lastRow &_
133
            ") where rnum >= " & firstRow
134
 
135
' Assist in debug
136
oJSON.data("BasicSql") = BasicSql
137
'oJSON.data("SqlQry") = SqlQry
138
 
139
' Perform the database query
140
Set oJSON.data("aaData") = oJSON.Collection()
141
On Error Resume Next
142
objEH.ErrorRedirect = FALSE
143
objEH.TryORA ( OraSession )
144
Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )
145
objEH.CatchORA ( OraSession )
146
' Process each row and return required fields to the user
147
If objEH.Finally Then
148
On Error goto 0
149
 
150
    While (NOT rsQry.BOF) AND (NOT rsQry.EOF)
151
        Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))
152
        Dim ii
153
        for ii = 0 to rsQry.Fields.Count - 2
154
            newitem (rsQry.FieldName(ii)) = rsQry.Fields(ii)
155
            'newitem (ii) = rsQry.Fields(ii)
156
        Next
157
       rsQry.MoveNext
158
    Wend
159
End IF
160
 
161
rsQry.Close
162
Set rsQry = Nothing
163
 
164
'
165
' SQL error detection and reporting
5055 dpurdie 166
'   The content of 'error' will be dsplayed to the user.
5050 dpurdie 167
If objEH.LastOraFailed Then
5055 dpurdie 168
    oJSON.data("error") = objEH.MessageSummary
5050 dpurdie 169
    oJSON.data("emsgDetails") = objEH.MessageDetails
170
    oJSON.data("SqlQry") = SqlQry
171
End If
172
 
173
'Return the object
174
Response.Write oJSON.JSONoutput()
175
'OraSession.Dispose()
176
%>