@Test public void testReadFromQueryWithValidSemicolon() throws Exception { String serversDirectory = new File(this.getClass().getClassLoader().getResource("servers").toURI()).getCanonicalPath(); context.getAdditionalConfigProps().put("pxf.config.server.directory", serversDirectory + File.separator + "test-server"); context.setDataSource("query:testquerywithvalidsemicolon"); ArgumentCaptor<String> queryPassed = ArgumentCaptor.forClass(String.class); when(mockStatement.executeQuery(queryPassed.capture())).thenReturn(mockResultSet); accessor.initialize(context); accessor.openForRead(); String expected = "SELECT FROM (SELECT dept.name, count(), max(emp.salary)\n" + "FROM dept JOIN emp\n" + "ON dept.id = emp.dept_id\n" + "WHERE dept.name LIKE '%;%'\n" + "GROUP BY dept.name) pxfsubquery"; assertEquals(expected, queryPassed.getValue()); }
@Override public boolean openForRead() throws SQLException, SQLTimeoutException, ParseException { if (statementRead != null && !statementRead.isClosed()) { return true; } Connection connection = super.getConnection(); SQLQueryBuilder sqlQueryBuilder = new SQLQueryBuilder(context, connection.getMetaData(), getQueryText()); if (quoteColumns == null) { sqlQueryBuilder.autoSetQuoteString(); } else if (quoteColumns) { sqlQueryBuilder.forceSetQuoteString(); } queryRead = sqlQueryBuilder.buildSelectQuery(); LOG.trace("Select query: {}", queryRead); statementRead = connection.createStatement(); statementRead.setFetchSize(fetchSize); if (queryTimeout != null) { LOG.debug("Setting query timeout to {} seconds", queryTimeout); statementRead.setQueryTimeout(queryTimeout); } resultSetRead = statementRead.executeQuery(queryRead); return true; }
JdbcAccessor extends JdbcBasePlugin implements Accessor { @Override public boolean openForRead() throws SQLException, SQLTimeoutException, ParseException { if (statementRead != null && !statementRead.isClosed()) { return true; } Connection connection = super.getConnection(); SQLQueryBuilder sqlQueryBuilder = new SQLQueryBuilder(context, connection.getMetaData(), getQueryText()); if (quoteColumns == null) { sqlQueryBuilder.autoSetQuoteString(); } else if (quoteColumns) { sqlQueryBuilder.forceSetQuoteString(); } queryRead = sqlQueryBuilder.buildSelectQuery(); LOG.trace("Select query: {}", queryRead); statementRead = connection.createStatement(); statementRead.setFetchSize(fetchSize); if (queryTimeout != null) { LOG.debug("Setting query timeout to {} seconds", queryTimeout); statementRead.setQueryTimeout(queryTimeout); } resultSetRead = statementRead.executeQuery(queryRead); return true; } }
JdbcAccessor extends JdbcBasePlugin implements Accessor { @Override public boolean openForRead() throws SQLException, SQLTimeoutException, ParseException { if (statementRead != null && !statementRead.isClosed()) { return true; } Connection connection = super.getConnection(); SQLQueryBuilder sqlQueryBuilder = new SQLQueryBuilder(context, connection.getMetaData(), getQueryText()); if (quoteColumns == null) { sqlQueryBuilder.autoSetQuoteString(); } else if (quoteColumns) { sqlQueryBuilder.forceSetQuoteString(); } queryRead = sqlQueryBuilder.buildSelectQuery(); LOG.trace("Select query: {}", queryRead); statementRead = connection.createStatement(); statementRead.setFetchSize(fetchSize); if (queryTimeout != null) { LOG.debug("Setting query timeout to {} seconds", queryTimeout); statementRead.setQueryTimeout(queryTimeout); } resultSetRead = statementRead.executeQuery(queryRead); return true; } JdbcAccessor();   JdbcAccessor(ConnectionManager connectionManager); }
JdbcAccessor extends JdbcBasePlugin implements Accessor { @Override public boolean openForRead() throws SQLException, SQLTimeoutException, ParseException { if (statementRead != null && !statementRead.isClosed()) { return true; } Connection connection = super.getConnection(); SQLQueryBuilder sqlQueryBuilder = new SQLQueryBuilder(context, connection.getMetaData(), getQueryText()); if (quoteColumns == null) { sqlQueryBuilder.autoSetQuoteString(); } else if (quoteColumns) { sqlQueryBuilder.forceSetQuoteString(); } queryRead = sqlQueryBuilder.buildSelectQuery(); LOG.trace("Select query: {}", queryRead); statementRead = connection.createStatement(); statementRead.setFetchSize(fetchSize); if (queryTimeout != null) { LOG.debug("Setting query timeout to {} seconds", queryTimeout); statementRead.setQueryTimeout(queryTimeout); } resultSetRead = statementRead.executeQuery(queryRead); return true; } JdbcAccessor();   JdbcAccessor(ConnectionManager connectionManager); @Override boolean openForRead(); @Override OneRow readNextObject(); @Override void closeForRead(); @Override boolean openForWrite(); @Override boolean writeNextObject(OneRow row); @Override void closeForWrite(); }
JdbcAccessor extends JdbcBasePlugin implements Accessor { @Override public boolean openForRead() throws SQLException, SQLTimeoutException, ParseException { if (statementRead != null && !statementRead.isClosed()) { return true; } Connection connection = super.getConnection(); SQLQueryBuilder sqlQueryBuilder = new SQLQueryBuilder(context, connection.getMetaData(), getQueryText()); if (quoteColumns == null) { sqlQueryBuilder.autoSetQuoteString(); } else if (quoteColumns) { sqlQueryBuilder.forceSetQuoteString(); } queryRead = sqlQueryBuilder.buildSelectQuery(); LOG.trace("Select query: {}", queryRead); statementRead = connection.createStatement(); statementRead.setFetchSize(fetchSize); if (queryTimeout != null) { LOG.debug("Setting query timeout to {} seconds", queryTimeout); statementRead.setQueryTimeout(queryTimeout); } resultSetRead = statementRead.executeQuery(queryRead); return true; } JdbcAccessor();   JdbcAccessor(ConnectionManager connectionManager); @Override boolean openForRead(); @Override OneRow readNextObject(); @Override void closeForRead(); @Override boolean openForWrite(); @Override boolean writeNextObject(OneRow row); @Override void closeForWrite();  }