Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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