I am working on a SqlHawk Java based OSS application which, as one of its functions, should run sql update scripts against the server.
Microsoft made an agreement to split the script into batches using GO , which is a good idea, but just asks for false matches in the string.
At the moment I have a very rudimentary:
// split where GO on its own on a line Pattern batchSplitter = Pattern.compile("^GO", Pattern.MULTILINE); ... String[] splitSql = batchSplitter.split(definition); ...
which works, but is prone to being encouraged by things like quoted GO instructions or indentation issues.
I think the only way to make this truly reliable is to have an SQL parser in the application, but I donβt know how to do this, or whether it can actually be less reliable (especially if this tool supports several DBMSs).
How can I solve this problem? Code examples would be very helpful for me here.
Relevant sqlHawk code on github.
Jtds is currently used to execute packages found in scripts.
source share