sqlparser/select.cpp
// Join clause in FROM clause of SELECT statement 
Join clause in FROM clause of SELECT statement
Join clause in FROM clause of SELECT statement
bool SqlParser::ParseJoinClause(Token *first, Token *second, bool first_is_subquery, ListWM *from_table_end)
{
	if(second == NULL)
		return false;
	bool exists = false;
	Token *left_right_full = NULL;
	Token *outer_inner = NULL;
	Token *join = NULL;
	Token *on = NULL;
	exists = GetJoinKeywords(second, &left_right_full, &outer_inner, &join);
	if(exists == false)
	{
		if(!first_is_subquery && from_table_end != NULL)
			from_table_end->Add(second, first);
		Token *token = GetNext();
		exists = GetJoinKeywords(token, &left_right_full, &outer_inner, &join);
		if(!exists)
			PushBack(token);
	}
	if(join == NULL)
		return false;
	Token *third = GetNextToken();
	if(third == NULL)
		return false;
	if(third->Compare('(', L'(') == true)
	{
		Token *select = GetNextSelectStartKeyword();
		if(select != NULL)
			ParseSelectStatement(select, 0, SQL_SEL_JOIN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
		 (void) GetNextCharToken(')', ')');
	}
	Token *fourth = NULL;
	on = GetNextWordToken("ON", L"ON", 2);
	if(on == NULL)
	{
		fourth = GetNextIdentToken();
		on = GetNextWordToken("ON", L"ON", 2);
	}
	if(on != NULL)
		ParseBooleanExpression(SQL_BOOL_JOIN_ON, NULL, NULL);
	Token *next = GetNextToken();
	if(ParseJoinClause(NULL, next, false, NULL) == false)
		PushBack(next);
	return true;
}
bool SqlParser :: ParseJoinClause ( Token * first , Token * second , bool first_is_subquery , ListWM * from_table_end ) { if ( second == NULL ) return false ; bool exists = false ; Token * left_right_full = NULL ; Token * outer_inner = NULL ; Token * join = NULL ; Token * on = NULL ; exists = GetJoinKeywords ( second , & left_right_full , & outer_inner , & join ) ; if ( exists == false ) { if ( ! first_is_subquery && from_table_end != NULL ) from_table_end -> Add ( second , first ) ; Token * token = GetNext ( ) ; exists = GetJoinKeywords ( token , & left_right_full , & outer_inner , & join ) ; if ( ! exists ) PushBack ( token ) ; } if ( join == NULL ) return false ; Token * third = GetNextToken ( ) ; if ( third == NULL ) return false ; if ( third -> Compare ( ' ' , L' ' ) == true ) { Token * select = GetNextSelectStartKeyword ( ) ; if ( select != NULL ) ParseSelectStatement ( select , 0 , SQL_SEL_JOIN , NULL , NULL , NULL , NULL , NULL , NULL , NULL , NULL ) ; ( void ) GetNextCharToken ( ' ' , ' ' ) ; } Token * fourth = NULL ; on = GetNextWordToken ( " " , L" " , 2 ) ; if ( on == NULL ) { fourth = GetNextIdentToken ( ) ; on = GetNextWordToken ( " " , L" " , 2 ) ; } if ( on != NULL ) ParseBooleanExpression ( SQL_BOOL_JOIN_ON , NULL , NULL ) ; Token * next = GetNextToken ( ) ; if ( ParseJoinClause ( NULL , next , false , NULL ) == false ) PushBack ( next ) ; return true ; }
Join clause in FROM clause of SELECT statement
Join clause in FROM clause of SELECT statement
// Second points to alias, try to get the first join keyword // Second table name, or (SELECT ...) // Check for nested SELECT /*Token *close */ // If ON does not follows, it means optional alias for the second table in join // Alias // Parse join condition // List of join conditions can be specified JOIN ON ... JOIN ON ...