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
Comments
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:
for colnum=1:1:snapshot.GetColumnCount() {
write snapshot.GetColumnName(colnum),"=",snapshot.GetData(colnum),!
}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 ... 😁