option explicit
' Test case for bug#30520
'
' Copyright 2007 - MySQL AB

' VBS doesn't have an "include" mechanism, and
' ScriptUnit doesn't like WSH files, so we're left with this
' hack for now...
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
Dim f: Set f = fso.OpenTextFile("../common/adovbs.inc", 1)
Dim s: s = f.ReadAll()
ExecuteGlobal s
f.Close
Set f = Nothing

Set f = fso.OpenTextFile("../common/mysql-common.inc", 1)   
s = f.ReadAll()  
ExecuteGlobal s
f.Close
Set f = Nothing


Sub setup()
        Dim connection1, strSQL
        Set connection1 = CreateObject("ADODB.Connection")
        
        ' get rid of test table if it's there
        strSQL = "DROP TABLE IF EXISTS ado_test"
        connection1.ConnectionString = connstr
        connection1.Open
        connection1.Execute(strSQL)

        ' Create new test table
        strSQL = "CREATE TABLE ado_test (test_int int, test_text text)"
        connection1.Execute(strSQL)
        
        ' Add records to table
        strSQL = "INSERT INTO ado_test (test_int, test_text) VALUES ('42', 'test text')"
        connection1.Execute(strSQL)
        connection1.Close
        Set connection1 = Nothing
End Sub

Sub teardown()
        Dim connection1, strSQL
        Set connection1 = CreateObject("ADODB.Connection")
        
        ' get rid of test table
        strSQL = "DROP TABLE ado_test"
        connection1.ConnectionString = connstr
        connection1.Open
        connection1.Execute(strSQL)
        connection1.Close
        Set connection1 = Nothing
End Sub

Sub Cleanup(conn, recset)
        recset.Close
        Set recset = Nothing
        conn.Close
        Set conn = Nothing
End Sub 


Sub TestExecuteValid()
        'On Error Resume Next
        Dim connection1, recset1, strSQL, lock, iTemp
        Set connection1 = CreateObject("ADODB.Connection")
        Set recset1 = CreateObject("ADODB.RecordSet")
        strSQL = "SELECT * FROM ado_test"
        connection1.ConnectionString = connstr

        ' open connection
        connection1.Open

        ' create the recordset
        Set recset1 = connection1.Execute(strSQL)
        while not recset1.eof
                If strComp(recset1("test_int"), "42") <> 0 Then
                        On Error Goto 0
                        Assert.Failure "Result wanished first read of int"
                end if

                If strComp(recset1("test_text"), "test text") <> 0 Then
                        On Error Goto 0
                        Assert.Failure "Result wanished first read of text"
                end if

                If strComp(recset1("test_int"), "42") <> 0 Then
                        On Error Goto 0
                        Assert.Failure "Result wanished second read of int"
                end if

                If strComp(recset1("test_text"), "test text") <> 0 Then
                        On Error Goto 0
                        Assert.Failure "Result wanished second read of text"
                end if

                recset1.movenext
        wend
        connection1.Close
        f.close
End Sub
