18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

indexOf on a SQL select result

TSissonCredTSissonCred Members
edited October 2013 in Sahi Pro
I have a SQL select statement that returns a one dimensional list of results to an array: $ar. When I execute: $ar.length() I get the expected result which matches my result in SQL. However, when I try to do an $ar.indexOf("SomeText"); I keep getting -1 as if the value isn't in the array.

When I iterate through the array using a for loop and dumping out to _log, I see the value I'm looking for. There are no extra spaces on the results. Now, when I create a simple array: var $ar = ["Banana", "Orange", "Apple", "Mango"]; and then do an $ar.indexOf("Apple"); I get a "2" as expected.

What is different about a SQL select result set? I've looked here on the forums and in the documentation but I can't find anything that would point to why this behavior is occurring.

Best Answer

  • Hi,
    Your select query returns resultset which is different from an array.
    Also, resultset.indexof requires a Record type of argument and not a String type.
    This is probably the reason for the '-1' that you are getting.
    The workaround where you convert it into an array will work perfectly.

    Regards.

Answers

  • TSissonCredTSissonCred Members
    edited October 2013
    For now I have the following workaround but I would love to know why a db select would break the indexOf() method:
    $array = $db.select("select column from table");
    $array.indexOf("SomeText");  // returns -1
    $string = $array.toString();
    $arrayNew = $string.split(",");
    $arrayNew.indexOf("SomeText");  //returns the expected value.
    
  • Thank you. I had forgotten the .select method returned a recordset but figured it out shortly thereafter.
This discussion has been closed.