Iterate through current Row of EnsLib.SQL.Snapshot
I am using a JDBC connection to MS SQL server to execute a stored procedure to select data and bring it into InterSystems as a EnsLib.SQL.Snapshot. I loop through the EnsLib.SQL.Snapshot using a while loop, but I also want to iterate through the Columns within that Row to do logic.
Is there a way to iterate through the Columns of the current Row of the EnsLib.SQL.Snapshot so I can apply logic/rules for further processing?
Thanks
Scott
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:7.2.0-1.r1]
Are you doing this in ObjectScript or in a DTL?
You can use GetColumnCount, use a for loop to iterate through the column numbers, and request the data for each column using GetData, or get the column name using GetColumnName.
I already use Get("<column>") to pull the values, I was just looking for an easier way like with a Foreach loop
Yeah, so something like this:
EnsLib.SQL.Snapshot has a GetData() method that takes the column number as its first argument (the second takes a row number but defaults to the current row). So that in conjunction with GetColumnCount() should allow you to iterate across columns.
Edit: And of course Marc beat me to it ... 😁