Written by

Enterprise Application Development Consultant at The Ohio State University Wexner Medical Center
MOD
Question Scott Roth · Nov 20, 2024

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]

Comments

Marc Mundt · Nov 20, 2024

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.

0
Scott Roth  Nov 20, 2024 to Marc Mundt

I already use Get("<column>") to pull the values, I was just looking for an easier way like with a Foreach loop

0
Marc Mundt  Nov 20, 2024 to Scott Roth

Yeah, so something like this:

for colnum=1:1:snapshot.GetColumnCount() {
    write snapshot.GetColumnName(colnum),"=",snapshot.GetData(colnum),!
}
0
Jeffrey Drumm · Nov 20, 2024

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 ... 😁

0