Forum Discussion

rmnrdi's avatar
rmnrdi
Contributor
6 years ago
Solved

Driver.ColumnCount only works when debugging

Here's my code:

function testve()
{
  var csvPath = "C:\\TestData\\FrameFields.csv";
  QueryCSVByID(csvPath,"FrameFields.csv",1);
}

function QueryCSVByID(csvPath,csvName,testID)
{  
  let colCount = 0;
  let Driver = DDT.CSVDriver(csvPath); 
    
  if (testID == -1)
  {
    //var queryAll = `Select * from JobEntryData.csv`;
    var queryAll = 'Select * from ' + csvName + '';
    Driver.ADOCommandObject.CommandText = queryAll;
  }
  else
  {
    var queryByID = 'SELECT * FROM ' + csvName  + ' WHERE  TestID =' + '"' + testID + '"' + '';
    Driver.ADOCommandObject.CommandText = queryByID;
    //aqUtils.Delay(10000)
  }
  //aqUtils.Delay(10000);
  colCount = Driver.ColumnCount;<-Fails at runtime, unless I'm debugging.

  while(!Driver. EOF())
  {
      for(var i = 0; i < colCount - 1 ;i++)
      {
        Log.Message("Column " + i + " name is " + Driver.ColumnName(i) + " and it's value is " + Driver.Value(i));
      }  
    Driver.Next();   
    Log.Message("---------------------------- ROW --------------------------------------------") ;
  }  
}

Driver.ColumnCount gets the following error at runtime:

Driver.ColumnCount error

Unless I'm in debug mode. Then it works fine.

I tried adding 10 second delays because I wasn't sure if it was just taking time to get the results. Didn't work.

 

Thoughts anyone? 

  • OK, first of all, if TestID is -1, you don't need to declare the SQL query.. the assumption is that, if you don't alter the command text, it's always going to be a select all.  So, I'd simply do an if then to check if TestID != -1... if that returns true, set the query, otherwise, do nothing but continue with your test.

    So... my guess is that, in debugging, TestID is -1... so, you never set your SQL query to the queryByID SQL statement.  Hence, you'll not get the error... because my guess is that you're running an SQL query for a column called TestID that is an integer and not a string... so, that's the type mismatch.  Try the following code:

    function testve()
    {
      var csvPath = "C:\\TestData\\FrameFields.csv";
      QueryCSVByID(csvPath,"FrameFields.csv",1);
    }
    
    function QueryCSVByID(csvPath,csvName,testID)
    {  
      let colCount = 0;
      let Driver = DDT.CSVDriver(csvPath); 
        
      if (testID != -1)
      {
        var queryByID = 'SELECT * FROM ' + csvName  + ' WHERE  TestID = ' + testID + ';
        Driver.ADOCommandObject.CommandText = queryByID;
        //aqUtils.Delay(10000)
      }
      //aqUtils.Delay(10000);
      colCount = Driver.ColumnCount;<-Fails at runtime, unless I'm debugging.
    
      while(!Driver. EOF())
      {
          for(var i = 0; i < colCount - 1 ;i++)
          {
            Log.Message("Column " + i + " name is " + Driver.ColumnName(i) + " and it's value is " + Driver.Value(i));
          }  
        Driver.Next();   
        Log.Message("---------------------------- ROW --------------------------------------------") ;
      }  
    }

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    OK, first of all, if TestID is -1, you don't need to declare the SQL query.. the assumption is that, if you don't alter the command text, it's always going to be a select all.  So, I'd simply do an if then to check if TestID != -1... if that returns true, set the query, otherwise, do nothing but continue with your test.

    So... my guess is that, in debugging, TestID is -1... so, you never set your SQL query to the queryByID SQL statement.  Hence, you'll not get the error... because my guess is that you're running an SQL query for a column called TestID that is an integer and not a string... so, that's the type mismatch.  Try the following code:

    function testve()
    {
      var csvPath = "C:\\TestData\\FrameFields.csv";
      QueryCSVByID(csvPath,"FrameFields.csv",1);
    }
    
    function QueryCSVByID(csvPath,csvName,testID)
    {  
      let colCount = 0;
      let Driver = DDT.CSVDriver(csvPath); 
        
      if (testID != -1)
      {
        var queryByID = 'SELECT * FROM ' + csvName  + ' WHERE  TestID = ' + testID + ';
        Driver.ADOCommandObject.CommandText = queryByID;
        //aqUtils.Delay(10000)
      }
      //aqUtils.Delay(10000);
      colCount = Driver.ColumnCount;<-Fails at runtime, unless I'm debugging.
    
      while(!Driver. EOF())
      {
          for(var i = 0; i < colCount - 1 ;i++)
          {
            Log.Message("Column " + i + " name is " + Driver.ColumnName(i) + " and it's value is " + Driver.Value(i));
          }  
        Driver.Next();   
        Log.Message("---------------------------- ROW --------------------------------------------") ;
      }  
    }
    • rmnrdi's avatar
      rmnrdi
      Contributor

      Wow. So that worked. I would have taken me a long time to catch that. Thanks.

       

      The only thing I notice now, is that the select by id takes a long time. lIke 5 full seconds.

       

      UPDATE: 

      If I get all rows with this query: "SELECT * FROM FrameFields.csv" the function takes 0.96 seconds to execute 9 rows of the csv.

       

      If I add in the where clause, it takes 14.65 seconds to execute 9 rows.

       

      ANOTHER UPDATE:

      I think I solved it. It didn't like how I was shutting down the DDT driver.