UnitTest( xls.asp )

Output

Total records: 3360

Sources

/axe-ut/xls.unit.test.asp

<!--#include virtual="/lib/unit-tests.asp"-->
<!--#include virtual="/lib/axe/classes/Parsers/json2.asp"-->
<!--#include virtual="/lib/json-streamify.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
    <head>
        <title>AXE - Unit Test - XLS</title>
        <!--// meta tags //-->
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <!--// link tags //-->
        <link rel="stylesheet" type="text/css" media="screen" href="/lib/unit-tests.css" />
    </head>
    <body>
        <div id="container">
            <div id="container-hd">
                <h1>UnitTest( xls.asp )</h1>
            </div>
            <div id="container-bd">

<h2>Output</h2>
<div class="code"><pre><%

Server.scriptTimeOut = 3600

dim Conn, Cmd, Rs _
  , sheet1, i _
  , Ds, Entry

set Ds = JSON.parse("[]")

set Conn = Server.createObject("ADODB.Connection")
Conn.open( strsubstitute( "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""", Server.mapPath("db.xls") ) )

with Conn.openSchema(adSchemaTables, array(empty, empty, empty, "TABLE"))
    sheet1 = .Fields("TABLE_NAME").value
end with

set Cmd = Server.createObject("ADODB.Command")
set Cmd.activeConnection = Conn
Cmd.commandType = adCmdText
Cmd.commandText = "SELECT * FROM [" & sheet1 & "]"

set Rs = nothing

set Rs = Server.createObject("ADODB.Recordset")
Rs.cursorType = adOpenStatic
Rs.lockType   = adLockPessimistic
Rs.open(Cmd)

while(not Rs.eof)
    set Entry = JSON.parse("{}")
    for i = 0 to Rs.Fields.count - 1
        Entry.set map_key(i, Rs(i).name), map_val( i, Rs(i).value )
    next
    Ds.push(Entry)
    set Entry = nothing
    Rs.moveNext()
wend

Rs.close()
set Rs = nothing

set Cmd.activeConnection = nothing
set Cmd = nothing

Conn.close()
set Conn = nothing

Response.write( strsubstitute("Total records: {0}", Ds.length) )

dim t0

if( Request.QueryString("speedtest")() = "true" ) then
    Response.write vbNewline
    t0 = timer()
    Response.write JSON.stringify(Ds)
    Response.write vbNewline
    Response.write strsubstitute("stringify required {0} seconds", timer() - t0)

    Response.write vbNewline
    t0 = timer()
    Response.write JSON.streamify(Ds)
    Response.write vbNewline
    Response.write strsubstitute("streamify required {0} seconds", timer() - t0)
end if

set Ds = nothing

function map_key(byVal i, byVal key)
    select case i
        case 0
            map_key = "ref"

        case 1
            map_key = "desc"

        case 2
            map_key = "un"

        case 3
            map_key = "price"

        case 4
            map_key = "aliq_ipi"

        case else
            map_key = key
    end select
end function

function map_val(byVal i, byVal val)
    select case i
        case 1
            map_val = trim(val)

        case 2
            map_val = trim(val)

        case else
            map_val = val
    end select
end function

%></pre></div>

            </div>
            <div id="container-ft">
                <h2>Sources</h2>
                <h3><%= Request.ServerVariables("SCRIPT_NAME") %></h3>
                <div class="code"><%= geshify( loadTextFile( Server.mapPath( Request.ServerVariables("SCRIPT_NAME") ) ), "asp" ) %></div>
            </div>
        </div>
        <!--// javascript tags //-->
    </body>
</html>