Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions models/Grammars/OracleGrammar.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ component extends="qb.models.Grammars.BaseGrammar" singleton {
return "FROM DUAL";
}

var fullTable = arguments.tableName;
if ( query.getAlias() != "" ) {
fullTable &= " #query.getAlias()#";
}
return "FROM " & wrapTable( fullTable );
return "FROM " & wrapQueryTable( arguments.query );
}

/**
Expand Down
1 change: 1 addition & 0 deletions models/Query/QueryBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ component displayname="QueryBuilder" accessors="true" extends="qb.models.Query.J

// generate the derived table SQL
this.fromRaw( getGrammar().wrapTable( "(#arguments.input.toSQL()#) AS #arguments.alias#" ) );
variables.alias = arguments.alias;
variables.grammarCompiledFrom = true;
addBindings( arguments.input.getBindings(), "from" );
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ component extends="tests.resources.querybuilder.AbstractQueryBuilderSubselectSpe
.where( "age", ">=", "21" );

builder.fromSub( "u", derivedTable );
expect( builder.getAlias() ).toBe( "u" );
}, fromDerivedTable() );
} );

Expand All @@ -60,6 +61,7 @@ component extends="tests.resources.querybuilder.AbstractQueryBuilderSubselectSpe
.from( "users" )
.where( "age", ">=", "21" );
} );
expect( builder.getAlias() ).toBe( "u" );
}, fromDerivedTable() );
} );

Expand Down
8 changes: 8 additions & 0 deletions tests/specs/Query/Abstract/BuilderSelectSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,14 @@ component extends="testbox.system.BaseSpec" {
} );

describe( "setGrammar()", function() {
it( "tracks a derived table alias", function() {
query.fromSub( "active_users", function( subquery ) {
subquery.from( "users" );
} );

expect( query.getAlias() ).toBe( "active_users" );
} );

it( "rejects grammar changes after compiling a derived table", function() {
query.fromSub( "active_users", function( subquery ) {
subquery.from( "users" );
Expand Down
Loading