Loading the script into a TStringList
would work. looking for the word GO
on a line by itself (which avoids embedded text containing GO
) as the end of each block or the script itself.
You use the GO
line's index - 1 to mark the end of the prior block, and the GO
line index + 1 as the start of the next block. If the GO
index is equal to the StringList.Count - 1, you've reached then end of the script. You can start a transaction before processing the blocks, and roll that transaction back if an exception is raised.