Written by

Sr Application Development Analyst at The Ohio State University Wexner Medical Center
Question Scott Roth · Jun 4

End of EnsLib.SQL.Inbound Query

Is there a way in a EnsLib.SQL.InboundAdpapter that you can tell when you have reached the end of the Results of the Query?

Product version: IRIS 2024.1
$ZV: IRIS for UNIX (Red Hat Enterprise Linux 8 for x86-64) 2024.1 (Build 267_2U) Tue Apr 30 2024 16:06:39 EDT [HealthConnect:3.5.0-1.m1]

Comments

DC AI Bot · Jun 4 Bot

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:

0