Forum Discussion

S_Seydel's avatar
S_Seydel
Contributor
6 years ago
Solved

JScript to JavaScript conversion and adoDB delete

Greetings,

 

I currently work on converting the language of my scripts from JScript to JavaScript. So far Smartbear's documentations on this topic JavaScript for JScript Users and Converting Scripts From One Scripting Language To Another were very helpful.

However at this point I face a problem I was not able to find a solution for so far.

To delete tupils from a database I use the following funtion:

 

  /* 
   *  Delete tupels from a database table
   *  Value parameter can be datatype object with value null
   *
   *  @param table = mandatory; string; the database table to search;
   *  @param column = mandatory; string; the database table's column to search;
   *  @param value = mandatory; string; the value to search for in the database table's column;
   */   
  function adoDelete(table, column, value)
  {
    //  Open the database connection
    var connection = openDatabaseConnection();
    //  Open the recordset we need
    var recordset = openRecordset(connection, table);

    //  Iterate through the recordset and delete all appropriate tupels    
    recordset.MoveFirst;
    
    while(equal(recordset.EOF, false))
    {
      if (equal(recordset.Fields.Item(column).Value, value))
      {
        recordset.Delete;
      }
      recordset.MoveNext;
    }
  }

Using JScript this function ran fine for the last two years.

Using JavaScript all code lines are executed without producing an error message, but the tupil in the database is not deleted. Therefore the function runs for an infinite time, or until it is manually interrupted.

 

From debugging I know that the correct tupel was found when the if -block is executed.

 

Perhaps a kind community member has an idea, why the behaviour differs and how a solution could look like?

 

Thank you in advance

Sönke

  • Try this code, this may look crazy but worth a try

    function adoDelete(table, column, value)
      {
        //  Open the database connection
        var connection = openDatabaseConnection();
        //  Open the recordset we need
        var recordset = openRecordset(connection, table);
    
        //  Iterate through the recordset and delete all appropriate tupels    
        recordset.MoveFirst();
        
        while(equal(recordset.EOF, false))
        {
          if (equal(recordset.Fields.Item(column).Value, value))
          {
            recordset.Delete();
          }
          recordset.MoveNext();
        }
      

2 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Try this code, this may look crazy but worth a try

    function adoDelete(table, column, value)
      {
        //  Open the database connection
        var connection = openDatabaseConnection();
        //  Open the recordset we need
        var recordset = openRecordset(connection, table);
    
        //  Iterate through the recordset and delete all appropriate tupels    
        recordset.MoveFirst();
        
        while(equal(recordset.EOF, false))
        {
          if (equal(recordset.Fields.Item(column).Value, value))
          {
            recordset.Delete();
          }
          recordset.MoveNext();
        }
      
    • S_Seydel's avatar
      S_Seydel
      Contributor

      That did it.

      Thank you very much for the very fast reply.