Forum Discussion
Nassim,
As far as I understand, you need to perform two "count" queries (these queries return numbers) and then check if the difference between these numbers is 1.
You can do this by using the following code snippet. I don't know which language you use in your project, so I wrote it in VBScript. You will need to change the connection string. Please read about this below.
Here is the code --
Sub DBTest
' Define connection. You need to change connection string in your tests
Set connection = ADO.CreateConnection
connection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb"
' Open connection
connection.Open
' Execute the first query
Set query1 = ADO.CreateRecordset
query1.Open "select count(*) from YOUR_TABLE_NAME_1", connection, -1, -1, adCmdText
' Execute another query
Set query2 = ADO.CreateRecordset
query2.Open "select count(*) from YOUR_TABLE_NAME_2", connection, -1, -1, adCmdText
' Get results
' The count query returns a recordset with one row and one column,
' so you can address it by index
Number1 = query1.Fields.Item(0).Value
Number2 = query2.Fields.Item(0).Value
' Get the difference
Diff = Number1 - Number2
' Process the result
If Diff <> 1 Then
' If the difference is not 1, output error info to the test log
Log.Error "Error! Diff <> 1", _
"Result1 = " + CStr(Number1) + Chr(13) + Chr(10) + _
"Result2 = " + CStr(Number2) + Chr(13) + Chr(10) + _
"Diff = " + CStr(Diff)
Else
' Else, post a success message
Log.Message "Success. Diff = 1"
End If
' Close the recordsets and the connection
query1.Close
query2.Close
connection.Close
End Sub
NOTE: This code works for a database that resides on local hard drive. To work with your SQL database, you need to specify another connection string. I'm not a database programming guru, and I don't know which connection strings are used for HeidiSQL. Most likely, it will look like this --
Driver ={MySQL ODBC 3.51 Driver}; Server =myServerAddress; Database =myDataBase; User =myUsername; Password =myPassword; Option =3;
If possible, ask your developers to assist you with the connection string.
Related Content
- 12 years agomaheshwari_a
Recent Discussions
- 11 hours agoSvetaG