### Question:
StringUtils { public static String[] splitSQL(String multiLineSQL, String endDelimiter) { if (endDelimiter == null) { endDelimiter = ";\\s*\n|;$|\n[gG][oO]\\s*\n|\n[Gg][oO]\\s*$"; } else { if (endDelimiter.equalsIgnoreCase("go")) { endDelimiter = "\n[gG][oO]\\s*\n|\n[Gg][oO]\\s*$"; } } String[] initialSplit = multiLineSQL.split(endDelimiter); List<String> strings = new ArrayList<String>(); for (String anInitialSplit : initialSplit) { String singleLineSQL = anInitialSplit.trim(); if (singleLineSQL.length() > 0) { strings.add(singleLineSQL); } } return strings.toArray(new String[strings.size()]); }  static String trimToEmpty(String string); static String trimToNull(String string); static String[] processMutliLineSQL(String multiLineSQL,boolean stripComments, boolean splitStatements, String endDelimiter); static String[] splitSQL(String multiLineSQL, String endDelimiter); static String stripComments(String multiLineSQL); static String join(String[] array, String delimiter); static String join(Collection<String> collection, String delimiter); static List<String> splitAndTrim(String s, String regex); static String repeat(String string, int times); static String join(Integer[] array, String delimiter); static String join(int[] array, String delimiter);  }### Answer:
@Test public void splitOngo() { String sql = "some sql\ngo\nmore sql"; String[] result = StringUtils.splitSQL(sql, null); assertEquals(2,result.length); assertEquals("some sql",result[0]); assertEquals("more sql",result[1]); }
@Test public void splitOnGO() { String sql = "some sql\nGO\nmore sql"; String[] result = StringUtils.splitSQL(sql, null); assertEquals(2,result.length); assertEquals("some sql",result[0]); assertEquals("more sql",result[1]); }
@Test public void splitWithGo() { String testString = "SELECT *\n" + " FROM sys.objects\n" + " WHERE object_id = OBJECT_ID(N'[test].[currval]')\n" + " AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')\n" + " )\n" + " DROP FUNCTION [test].[currval]\n" + "go\n" + " IF EXISTS\n" + " (\n" + " SELECT *\n" + " FROM sys.objects\n" + " WHERE object_id = OBJECT_ID(N'[test].[nextval]')\n" + " AND type in (N'P', N'PC')\n" + " )\n" + " DROP PROCEDURE [test].[nextval]:"; String[] strings = StringUtils.splitSQL(testString, null); assertEquals(2, strings.length); }
@Test public void splitWithX() { String testString = "insert into datatable (col) values ('a value with a ;') X\n"+ "insert into datatable (col) values ('another value with a ;') X"; String[] strings = StringUtils.splitSQL(testString, "X"); assertEquals(2, strings.length); assertEquals("insert into datatable (col) values ('a value with a ;')", strings[0]); assertEquals("insert into datatable (col) values ('another value with a ;')", strings[1]); }