You can also create a snapshot from static data, without having a connection to a DSN. To do so, use any of the following techniques:
The following list provides the details for these methods, all of which are in the EnsLib.SQL.Shapshot class:
Example
Consider a file that has the following contents:
col1,col2,col3
value A1,value A2,value A3
value B1, value B2 ,value B3
The following code reads this file, uses it to create a snapshot, and writes simple comments to the Terminal. Notice that the only arguments used are the filename and the column separator:
set filename="c:/demo.txt"
set snap=##class(EnsLib.SQL.Snapshot).%New()
do snap.ImportFile(filename,,",")
d show
quit
show
w "number of rows in snapshot=",snap.RowCount,!
while snap.Next()
{
w "current row=",snap.%CurrentRow,!
w "data in first column=",snap.GetData(1),!
w "data in second column=",snap.GetData(2),!
w "data in third column=",snap.GetData(3),!
}
quit
The output from this routine is as follows:
number of rows in snapshot=3
current row=1
data in first column=col1
data in second column=col2
data in third column=col3
current row=2
data in first column=value A1
data in second column=value A2
data in third column=value A3
current row=3
data in first column=value B1
data in second column=value B2
data in third column=value B3
Notice that line feeds are used by default as row separators. Also notice that by default, leading and trailing spaces are removed from each field.