GenericDbmsSupport implements IDbmsSupport { protected List<String> splitQuery(String query) { List<String> splittedQueries = new ArrayList<>(); if (!query.contains(";")) { splittedQueries.add(query); } else { int i = 0; int j = 0; while (j < query.length()) { if (query.charAt(j) == ';') { String line = query.substring(i, j + 1); int countApos = StringUtils.countMatches(line, "'"); int countBegin = Misc.countRegex(line.toUpperCase().replaceAll("\\s+", " "), "\\sBEGIN\\s"); int countEnd = Misc.countRegex(line.toUpperCase().replaceAll(";", "; "), "\\sEND;"); if ((countApos == 0 || (countApos & 1) == 0) && countBegin==countEnd) { splittedQueries.add(line.trim()); i = j + 1; } } j++; } if (j > i) splittedQueries.add(query.substring(i, j).trim()); } return splittedQueries; }  @Override String getDbmsName(); @Override Dbms getDbms(); @Override boolean isParameterTypeMatchRequired(); @Override boolean hasSkipLockedFunctionality(); @Override String getSysDate(); @Override String getDateAndOffset(String dateValue, int daysOffset); @Override String getNumericKeyFieldType(); @Override String getFromForTablelessSelect(); @Override String getAutoIncrementKeyFieldType(); @Override boolean autoIncrementKeyMustBeInserted(); @Override String autoIncrementInsertValue(String sequenceName); @Override boolean autoIncrementUsesSequenceObject(); @Override String getInsertedAutoIncrementValueQuery(String sequenceName); @Override String getIbisStoreSummaryQuery(); @Override String getTimestampFieldType(); @Override String getDatetimeLiteral(Date date); @Override String getTimestampAsDate(String columnName); @Override String getClobFieldType(); @Override boolean mustInsertEmptyClobBeforeData(); @Override String getUpdateClobQuery(String table, String clobField, String keyField); @Override String emptyClobValue(); @Override Object getClobUpdateHandle(ResultSet rs, int column); @Override Object getClobUpdateHandle(ResultSet rs, String column); @Override Writer getClobWriter(ResultSet rs, int column, Object clobUpdateHandle); @Override Writer getClobWriter(ResultSet rs, String column, Object clobUpdateHandle); @Override void updateClob(ResultSet rs, int column, Object clobUpdateHandle); @Override void updateClob(ResultSet rs, String column, Object clobUpdateHandle); @Override Reader getClobReader(ResultSet rs, int column); @Override Reader getClobReader(ResultSet rs, String column); @Override String getBlobFieldType(); @Override boolean mustInsertEmptyBlobBeforeData(); @Override String getUpdateBlobQuery(String table, String blobField, String keyField); @Override String emptyBlobValue(); @Override Object getBlobUpdateHandle(ResultSet rs, int column); @Override Object getBlobUpdateHandle(ResultSet rs, String column); @Override OutputStream getBlobOutputStream(ResultSet rs, int column, Object blobUpdateHandle); @Override OutputStream getBlobOutputStream(ResultSet rs, String column, Object blobUpdateHandle); @Override void updateBlob(ResultSet rs, int column, Object blobUpdateHandle); @Override void updateBlob(ResultSet rs, String column, Object blobUpdateHandle); @Override InputStream getBlobInputStream(ResultSet rs, int column); @Override InputStream getBlobInputStream(ResultSet rs, String column); @Override String getTextFieldType(); @Override String prepareQueryTextForWorkQueueReading(int batchSize, String selectQuery); @Override String prepareQueryTextForWorkQueueReading(int batchSize, String selectQuery, int wait); @Override String prepareQueryTextForWorkQueuePeeking(int batchSize, String selectQuery); @Override String prepareQueryTextForWorkQueuePeeking(int batchSize, String selectQuery, int wait); @Override String getFirstRecordQuery(String tableName); @Override String prepareQueryTextForNonLockingRead(String selectQuery); @Override JdbcSession prepareSessionForNonLockingRead(Connection conn); @Override String provideIndexHintAfterFirstKeyword(String tableName, String indexName); @Override String provideFirstRowsHintAfterFirstKeyword(int rowCount); @Override String provideTrailingFirstRowsHint(int rowCount); @Override String getSchema(Connection conn); @Override boolean isTablePresent(Connection conn, String tableName); @Override boolean isTablePresent(Connection conn, String schemaName, String tableName); @Override boolean isColumnPresent(Connection conn, String tableName, String columnName); @Override boolean isColumnPresent(Connection conn, String schemaName, String tableName, String columnName); @Override boolean isIndexPresent(Connection conn, String schemaOwner, String tableName, String indexName); @Override boolean isSequencePresent(Connection conn, String schemaOwner, String tableName, String sequenceName); @Override boolean isIndexColumnPresent(Connection conn, String schemaOwner, String tableName, String indexName, String columnName); @Override int getIndexColumnPosition(Connection conn, String schemaOwner, String tableName, String indexName, String columnName); @Override boolean hasIndexOnColumn(Connection conn, String schemaOwner, String tableName, String columnName); @Override boolean hasIndexOnColumns(Connection conn, String schemaOwner, String tableName, List<String> columns); @Override String getSchemaOwner(Connection conn); @Override boolean isUniqueConstraintViolation(SQLException e); @Override String getRowNumber(String order, String sort); @Override String getRowNumberShortName(); @Override String getLength(String column); @Override String getBooleanFieldType(); @Override String getBooleanValue(boolean value); @Override void convertQuery(QueryExecutionContext queryExecutionContext, String sqlDialectFrom);  }
@Test public void testSplitQuery() throws JdbcException, SQLException { String query1 = "select count(*) from ibisstore;"; String query2 = "delete from temp where tvarchar='t;st';"; String query3 = "update temp set tvarchar='new' where tvarchar2='old';"; String query4 = "ooo BEGIN BEGIN ooo; IF (ooo) THEN ooo; END IF; ooo; IF (ooo) THEN ooo; END IF; END;END;"; List<String> result = (new GenericDbmsSupport()).splitQuery(query1 + query2 + query3 + query4); assertEquals(4, result.size()); assertEquals(query1, result.get(0)); assertEquals(query2, result.get(1)); assertEquals(query3, result.get(2)); assertEquals(query4, result.get(3)); }