[#579] SQL syntax error when using Factory.selectOne() in a subquery - first implementation attempt

This commit is contained in:
Lukas Eder 2011-07-31 20:32:04 +00:00
parent 094f63393d
commit d190cc7b60
3 changed files with 24 additions and 1 deletions

View File

@ -3544,7 +3544,7 @@ public abstract class jOOQAbstractTest<
assertEquals(Arrays.asList(1, 2, 3, 4), books.getValues(b_ID));
}
// @Test TODO [#579] re-enable this test when fixing this bug
// @Test // TODO [#579] re-enable this test when fixing this bug
public void testUnaliasedSubqueryProjections() throws Exception {
// Test whether unaliased literals in subquery projections are correctly
// handled

View File

@ -47,6 +47,18 @@ package org.jooq;
*/
public interface RenderContext extends Context<RenderContext> {
/**
* Peek the next alias that will be generated by {@link #nextAlias()}
*/
String peekAlias();
/**
* Return a new alias that is unique for the scope of one query. These
* aliases are sometimes needed when unaliased projections are defined in
* subqueries, which can lead to syntax errors.
*/
String nextAlias();
/**
* Render the context's underlying SQL statement
*/

View File

@ -52,6 +52,7 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren
private final StringBuilder sql;
private boolean inline;
private int alias;
DefaultRenderContext(Configuration configuration) {
super(configuration);
@ -71,6 +72,16 @@ class DefaultRenderContext extends AbstractContext<RenderContext> implements Ren
// RenderContext API
// ------------------------------------------------------------------------
@Override
public final String peekAlias() {
return "alias_" + (alias + 1);
}
@Override
public final String nextAlias() {
return "alias_" + (++alias);
}
@Override
public final String render() {
return sql.toString();