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...
  • tristaanogre's avatar
    6 years ago

    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 --------------------------------------------") ;
      }  
    }