Discussion (3)3
Log in or sign up to continue

You can determine when you've reached the end of the results in an EnsLib.SQL.InboundAdapter by using the following approaches:

  1. OnTask Method Extension: Extend the SQL inbound adapter and override the OnTask method. This method is triggered after all rows are processed. For example:

    Class Project.Ens.Adapter.SQLInbound Extends EnsLib.SQL.InboundAdapter {
       Method OnTask() As %Status {
           Set sc = ##super()
           If '$IsObject(..%CurrResultSet) {
               // Logic indicating the last row processed
               Set ^dbg($i(^dbg)) = "Last row"
           }
           Quit sc
       }
    }
    

    This logic ensures your custom logic runs after all rows from the query are processed [1].

  2. Adding COUNT() to Query: Modify your SQL query to include a count of rows. You can create a mechanism that tracks the current row being processed and compares it with the total rows (from COUNT). When the current row matches the total rows, it signifies you are on the last row:

    • Add a ROWCOUNT column in the query.
    • Increment a custom CurrentROW property during each call to OnProcessInput.
    • When ROWCOUNT equals CurrentROW, trigger any logic meant for the last row [1].
  3. Injecting Dummy Row or Marker: If modifying the SQL query isn’t an issue, you could add a dummy row or marker at the query’s end. This marker indicates the end of the result set [1].

These approaches allow you to handle custom processing when reaching the end of the query's result set.

Sources: