sqlparser/language.cpp
// IF expression in Sybase ASA, IF function in MySQL
IF expression in Sybase ASA, IF function in MySQL
IF expression in Sybase ASA IF function in MySQL
bool SqlParser::ParseIfExpression(Token *first)
{
	if(first == NULL || Token::Compare(first, "IF", L"IF", 2) == false)
		return false;
	Token *open = NULL;
	if(_source == SQL_MYSQL)
		open = GetNext('(', L'(');
	ParseBooleanExpression(SQL_BOOL_IF_EXP);
	Token *then = GetNext("THEN", L"THEN", 4);
	Token *comma_then = NULL;
	if(then == NULL)
		comma_then = GetNext(',', L',');
	if(then == NULL && comma_then == NULL)
		return false;
	Token *true_exp = GetNextToken();
	if(true_exp == NULL)
		return false;
	ParseExpression(true_exp);
	Token *else_ = GetNextWordToken("ELSE", L"ELSE", 4);
	Token *comma_else = NULL;
	if(else_ == NULL)
		comma_else = GetNext(',', L',');
	if(else_ != NULL || comma_else != NULL)
	{
		Token *false_exp = GetNextToken();
		ParseExpression(false_exp);
	}
	Token *endif = GetNextWordToken("ENDIF", L"ENDIF", 5);
	Token *close = GetNext(open, ')', L')');
	if(_target != SQL_SYBASE_ASA)
	{
		Token::Change(first, "CASE WHEN", L"CASE WHEN", 9);
		if(endif != NULL)
			Token::Change(endif, "END", L"END", 3);
		else
			Append(close, " END", L" END", 4, first);
		Token::Change(comma_then, " THEN ", L" THEN ", 6, first);
		Token::Change(comma_else, " ELSE ", L" ELSE ", 6, first);
		Token::Change(open, " ", L" ", 1);
		Token::Remove(close);
	}
	return true;
}
bool SqlParser :: ParseIfExpression ( Token * first ) { if ( first == NULL || Token :: Compare ( first , " " , L" " , 2 ) == false ) return false ; Token * open = NULL ; if ( _source == SQL_MYSQL ) open = GetNext ( ' ' , L' ' ) ; ParseBooleanExpression ( SQL_BOOL_IF_EXP ) ; Token * then = GetNext ( " " , L" " , 4 ) ; Token * comma_then = NULL ; if ( then == NULL ) comma_then = GetNext ( ' ' , L' ' ) ; if ( then == NULL && comma_then == NULL ) return false ; Token * true_exp = GetNextToken ( ) ; if ( true_exp == NULL ) return false ; ParseExpression ( true_exp ) ; Token * else_ = GetNextWordToken ( " " , L" " , 4 ) ; Token * comma_else = NULL ; if ( else_ == NULL ) comma_else = GetNext ( ' ' , L' ' ) ; if ( else_ != NULL || comma_else != NULL ) { Token * false_exp = GetNextToken ( ) ; ParseExpression ( false_exp ) ; } Token * endif = GetNextWordToken ( " " , L" " , 5 ) ; Token * close = GetNext ( open , ' ' , L' ' ) ; if ( _target != SQL_SYBASE_ASA ) { Token :: Change ( first , " " , L" " , 9 ) ; if ( endif != NULL ) Token :: Change ( endif , " " , L" " , 3 ) ; else Append ( close , " " , L" " , 4 , first ) ; Token :: Change ( comma_then , " " , L" " , 6 , first ) ; Token :: Change ( comma_else , " " , L" " , 6 , first ) ; Token :: Change ( open , " " , L" " , 1 ) ; Token :: Remove ( close ) ; } return true ; }
IF expression in Sybase ASA, IF function in MySQL
IF expression in Sybase ASA IF function in MySQL
// ( in MySQL, do not take optional ( before boolean expression in Sybase ASA // Comma in MySQL // TRUE expression // Optional ELSE expression // ELSE expression is mandatory in IF function in MySQL // FALSE expression // ENDIF in  Sybase ASA // ) in MySQL // CASE WHEN expression for other databases