sqlparser/language.cpp
// String concatenation operator || in Oracle
String concatenation operator || in Oracle
String concatenation operator || in Oracle
bool SqlParser::ParseStringConcatenation(Token *first, int prev_operator)
{
	if(first == NULL)
		return false;
	Token *first_end = GetLastToken();
	Token *bar = GetNextCharToken('|', L'|');
	if(bar == NULL)
		return false;
	Token *bar2 = GetNextCharToken('|', L'|');
	if(bar2 == NULL)
		return false;
	Token *second = GetNextToken();
	if(second == NULL)
		return false;
	ParseExpression(second, SQL_OPERATOR_CONCAT);
	if(_target == SQL_SQL_SERVER)
	{
		Token::Change(bar, "+", L"+", 1);
		Token::Remove(bar2);
		if(first->nullable == true)
		{
			Prepend(first, "ISNULL(", L"ISNULL(", 7);
			Append(first_end, ", '')", L", '')", 5);
			first->nullable = false;
		}
		if(second->nullable == true)
		{
			Prepend(second, "ISNULL(", L"ISNULL(", 7);
			Append(GetLastToken(), ", '')", L", '')", 5);
		}
	}
	else
	if(Target(SQL_MARIADB, SQL_MYSQL))
	{
		if(prev_operator != SQL_OPERATOR_CONCAT)
			Prepend(first, "CONCAT(", L"CONCAT(", 7);
		Token::Change(bar, ",", L",", 1);
		Token::Remove(bar2);
		if(first->nullable == true)
		{
			Prepend(first, "IFNULL(", L"IFNULL(", 7);
			Append(first_end, ", '')", L", '')", 5);
			first->nullable = false;
		}
		if(second->nullable == true)
		{
			Prepend(second, "IFNULL(", L"IFNULL(", 7);
			Append(GetLastToken(), ", '')", L", '')", 5);
		}
		if(prev_operator != SQL_OPERATOR_CONCAT)
			Append(GetLastToken(), ")", L")", 1);
	}
	return true;
}
bool SqlParser :: ParseStringConcatenation ( Token * first , int prev_operator ) { if ( first == NULL ) return false ; Token * first_end = GetLastToken ( ) ; Token * bar = GetNextCharToken ( ' ' , L' ' ) ; if ( bar == NULL ) return false ; Token * bar2 = GetNextCharToken ( ' ' , L' ' ) ; if ( bar2 == NULL ) return false ; Token * second = GetNextToken ( ) ; if ( second == NULL ) return false ; ParseExpression ( second , SQL_OPERATOR_CONCAT ) ; if ( _target == SQL_SQL_SERVER ) { Token :: Change ( bar , " " , L" " , 1 ) ; Token :: Remove ( bar2 ) ; if ( first -> nullable == true ) { Prepend ( first , " " , L" " , 7 ) ; Append ( first_end , " " , L" " , 5 ) ; first -> nullable = false ; } if ( second -> nullable == true ) { Prepend ( second , " " , L" " , 7 ) ; Append ( GetLastToken ( ) , " " , L" " , 5 ) ; } } else if ( Target ( SQL_MARIADB , SQL_MYSQL ) ) { if ( prev_operator != SQL_OPERATOR_CONCAT ) Prepend ( first , " " , L" " , 7 ) ; Token :: Change ( bar , " " , L" " , 1 ) ; Token :: Remove ( bar2 ) ; if ( first -> nullable == true ) { Prepend ( first , " " , L" " , 7 ) ; Append ( first_end , " " , L" " , 5 ) ; first -> nullable = false ; } if ( second -> nullable == true ) { Prepend ( second , " " , L" " , 7 ) ; Append ( GetLastToken ( ) , " " , L" " , 5 ) ; } if ( prev_operator != SQL_OPERATOR_CONCAT ) Append ( GetLastToken ( ) , " " , L" " , 1 ) ; } return true ; }
String concatenation operator || in Oracle
String concatenation operator || in Oracle
// Parse the second and other expressions recursively // Change to + in SQL Server // If the first expression is nullable, around with ISNULL // Set not null to first token to avoid nested ISNULL when multiple concatenations specified // If the second expression is nullable, around with ISNULL // Change to CONCAT function in MySQL // If it is first expression add CONCAT( before  // If the first expression is nullable, around with IFNULL // Set not null to first token to avoid nested IFNULL when multiple concatenations specified // If the second expression is nullable, around with IFNULL // If it is first expression add ) to close CONCAT function