Blame | Last modification | View Log | RSS feed
<%@LANGUAGE="VBSCRIPT"%><%'=====================================================' sdk_names_json.asp' Ajax support for table of SDK names' Designed to be driven by the jquery tablescroller'=====================================================%><%Option explicit' Essential to get UTF through all the hoops. ie: VÄSTTRAFIK (VTK)Response.ContentType = "text/html"Response.AddHeader "Content-Type", "text/html;charset=UTF-8"Response.CodePage = 65001Response.CharSet = "UTF-8"%><!--#include file="common/conf.asp"--><!--#include file="common/globals.asp"--><!--#include file="common/qstr.asp"--><!--#include file="common/common_subs.asp"--><SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT><%'------------ Variable Definition -------------Dim result : result = -1Dim SqlQryDim rsQry' Init the output JSON class' Operations can add data' Default data will be added at the endDim oJSON :Set oJSON = New aspJSONDim newitem'' Determine the size of the record set' Gives bad results when searchingDim MaxCount : MaxCount = 0SqlQry = "select count(*) as count from SDK_NAMES skn"On Error Resume NextobjEH.ErrorRedirect = FALSEobjEH.TryORA ( OraSession )Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )objEH.CatchORA ( OraSession )If ((NOT rsQry.BOF) AND (NOT rsQry.EOF)) ThenMaxCount = rsQry("COUNT")End IfrsQry.CloseSet rsQry = Nothing' Basic Header' iTotalRecords = total records without any filtering/limits' iTotalDisplayRecords = filtered result countoJSON.data("sEcho") = CInt(Request.QueryString("sEcho"))oJSON.data("iTotalRecords") = MaxCountoJSON.data("iTotalDisplayRecords") = MaxCount' Assist in debugoJSON.data("iReqDisplayStart") = CInt(Request.QueryString("iDisplayStart"))oJSON.data("iReqDisplayLength") = CInt(Request.QueryString("iDisplayLength"))Dim vNamefor each vName in Request.QueryStringoJSON.data("sReq_" & vName) = Request.QueryString(vName)next' Extract selected rangeresult = 0dim firstRow,lastRowfirstRow = CInt(Request.QueryString("iDisplayStart"))lastRow = firstRow + CInt(Request.QueryString("iDisplayLength"))' Define the data items to extract from the database' An array of items to extract'Dim dataCols: dataCols = Array ( _"sdk_id", _"sdk_name", _"sdk_comment" )' Define array of colums to sort by' Must match user sort column requestDim sortCols: sortCols = Array ( _"sdk_id",_"UPPER(sdk_name)",_"UPPER(sdk_comment)" )' Dim determine sorting options'On Error goto 0'Response.Write "<pre>"Dim sortStringIf Request.QueryString("iSortCol_0") <> "" ThensortString = " ORDER BY " & sortCols(CInt(Request.QueryString("iSortCol_0")))sortString = sortString & " " & Request.QueryString("sSortDir_0")ElsesortString = " ORDER BY " & sortCols(CInt(1)) & "asc"End If' Filter (search )Dim searchStringIf Request.QueryString("sSearch") <> "" ThensearchString = " AND upper(sdk_name) LIKE upper('%" & Request.QueryString("sSearch") & "%')"End If' Create a list of cols that we need. Avoids ambiguity in selectionsDim x,colList,colListJoinFor x = Lbound(dataCols) to Ubound(dataCols)colList = colList & colListJoin & dataCols(x)colListJoin = ","NextDim whereStringDim BasicSqlBasicSql = "select " & colList &_" from SDK_NAMES skn " &_whereString &_searchString &_sortStringSqlQry = "select * from ( "&_"select a.*, ROWNUM rnum from (" & BasicSql &_") a where ROWNUM <= " & lastRow &_") where rnum >= " & firstRow' Assist in debugoJSON.data("BasicSql") = BasicSql'oJSON.data("SqlQry") = SqlQry' Perform the database querySet oJSON.data("aaData") = oJSON.Collection()On Error Resume NextobjEH.ErrorRedirect = FALSEobjEH.TryORA ( OraSession )Set rsQry = OraDatabase.DbCreateDynaset( SqlQry, ORADYN_DEFAULT )objEH.CatchORA ( OraSession )' Process each row and return required fields to the userIf objEH.Finally ThenOn Error goto 0While (NOT rsQry.BOF) AND (NOT rsQry.EOF)Set newitem = oJSON.AddToCollection(oJSON.data("aaData"))' Attempt to speed up access tot he data' Extract all fields for the row' Access fields by indexDim fieldsSet fields = rsQry.FieldsDim sdk_id : sdk_id = fields(0)Dim sdk_name : sdk_name = fields(1)Dim sdk_comment : sdk_comment = fields(2)Set fields = nothingnewitem(0) = sdk_idnewitem(1) = sdk_namenewitem(2) = sdk_commentnewitem(3) = "<button class=rmbutton onclick='editSdkEntry("& sdk_id &");'>Edit</button>"rsQry.MoveNextWendEnd IFrsQry.CloseSet rsQry = Nothing'' SQL error detection and reportingIf objEH.LastOraFailed ThenoJSON.data("error") = 1oJSON.data("emsgSummary") = objEH.MessageSummaryoJSON.data("emsgDetails") = objEH.MessageDetailsoJSON.data("SqlQry") = SqlQryEnd If'Return the objectResponse.Write oJSON.JSONoutput()'OraSession.Dispose()%>