0

My script allows a user query from a sheet a SQL database. Before letting the script write in the sheet the select's result, how can I know the number of rows I am getting from that query?

Multiplying the count of rows by the count of columns I want to warn the user if the query result size is over 10.000 cells so he is aware of crashing the sheet.

The method getColumnCount() works perfect but not for rows. I tried some other ways but nothing worked... any advice?

    var columnsNumber = resultmetadata.getColumnCount();
    ui.alert(columnsNumber); //this works

    var rowsNumber = resultmetadata.getRowCount();
    ui.alert(rowsNumber);  //this doesn't work

Thanks, Gerónimo

1 Answers1

0

Through this post How do I get the size of a java.sql.ResultSet? thanks to Martin Hawksey, I made this and worked perfect:

  if (result.last()) {  //query result
    var rowsNumber = result.getRow();
    result.beforeFirst(); // not rs.first() because the rs.next() below will move on, missing the first element
  }
Community
  • 1
  • 1