Forum Discussion

Al2's avatar
Al2
Occasional Contributor
5 years ago

How to get a Database table into an object (2D Array may be), and read the data

Hello,   I'm running a UI tests which fetches data continuously from a DB table. This table has 10000 rows and 20 columns. Test continuously fetches the data, and uses if for modifications, and ma...
  • BenoitB's avatar
    BenoitB
    5 years ago

    Ok, i'd done two posts because you asked about two things if i understood correctly.

     

    First post is about transforming linear data in 2D array.

    Use google translate to translate the documentation because i made effort to document then make the effort to translate  😁

    And getTokenBySeparator take a token from a string, using a separator to find tokens ... 😂

     

    Second post is about, root cause of your problem, speed.

    If you look the second post, the speed problem could be resolved simply, call the set.GetRows() instead of navigating into ADO result set, so it would be:

     

     

     

    let set         = conn.Execute_(exeQuery); 
    let elementList = [];        
    if ((set != null) && (set.RecordCount != 0))
      elementList = set.GetRows().toArray();
    return elementList;

     

     

    What you do was to browse Ado result set one by one to rebuild an array instead of fetching all data directly, so it's very slow.

     

    Some info on GetRows() is here:

    https://www.w3schools.com/asp/met_rs_getrows.asp

     

    BTW try to implement error management and connection established waiting as it is in my code. Your code will be robust and in case of errors you can know where and what.

     

    And don't put comment on trivial things (e.g. // Declare an array) or // Closing connection), comments are for advanced technical or algorithm points.

     

    I invite you to take a glance to this post about method writing:

    https://community.smartbear.com/t5/TestComplete-General-Discussions/Share-your-writing-guidelines-on-scripting-Focus-on-method/td-p/199479