sqlparser/functions.cpp
// TRIM in Oracle, DB2, Sybase ASA
TRIM in Oracle, DB2, Sybase ASA
TRIM in Oracle DB2 Sybase ASA
bool SqlParser::ParseFunctionTrim(Token *name, Token* )
{
	if(name == NULL)
		return false;
	STATS_DECL
	STATS_SET_DESC(SQL_FUNC_TRIM_DESC)
	Token *type = GetNextToken();
	if(Token::Compare(type, "LEADING", L"LEADING", 7) == false &&
		Token::Compare(type, "TRAILING", L"TRAILING", 8) == false &&
		Token::Compare(type, "BOTH", L"BOTH", 4) == false &&
		Token::Compare(type, "L", L"L", 1) == false &&
		Token::Compare(type, "T", L"T", 1) == false &&
		Token::Compare(type, "B", L"B", 1) == false)
	{
		PushBack(type);
		type = NULL;
	}
	Token *trim = GetNextToken();
	Token *from = NULL;
	if(Token::Compare(trim, "FROM", L"FROM", 4))
	{
		from = trim;
		trim = NULL;
	}
	else
		ParseExpression(trim);
	if(from == NULL)
		from = GetNextWordToken("FROM", L"FROM", 4);
	Token *string = NULL;
	if(from == NULL)
	{
		string = trim;
		trim = NULL;
	}
	if(string == NULL)
		string = GetNextToken();
	if(string == NULL)
		return false;
	ParseExpression(string);
	Token *close = GetNextCharToken(')', L')');
	if(_target == SQL_SQL_SERVER)
	{
		Token::Change(name, "RTRIM(LTRIM", L"LTRIM(RTRIM", 11);
		Append(close, ")", L")", 1);
	}
	else
	if(_target == SQL_ORACLE)
	{
		if(Token::Compare(type, "L", L"L", 1))
			Token::Change(type, "LEADING", L"LEADING", 7);
		else
		if(Token::Compare(type, "T", L"T", 1))
			Token::Change(type, "TRAILING", L"TRAILING", 8);
		else
		if(Token::Compare(type, "B", L"B", 1))
			Token::Change(type, "BOTH", L"BOTH", 4);
	}
	STATS_SET_CONV_NO_NEED(true)
	FUNC_STATS(name);
	return true;
}
bool SqlParser :: ParseFunctionTrim ( Token * name , Token * ) { if ( name == NULL ) return false ; STATS_DECL STATS_SET_DESC ( SQL_FUNC_TRIM_DESC ) Token * type = GetNextToken ( ) ; if ( Token :: Compare ( type , " " , L" " , 7 ) == false && Token :: Compare ( type , " " , L" " , 8 ) == false && Token :: Compare ( type , " " , L" " , 4 ) == false && Token :: Compare ( type , " " , L" " , 1 ) == false && Token :: Compare ( type , " " , L" " , 1 ) == false && Token :: Compare ( type , " " , L" " , 1 ) == false ) { PushBack ( type ) ; type = NULL ; } Token * trim = GetNextToken ( ) ; Token * from = NULL ; if ( Token :: Compare ( trim , " " , L" " , 4 ) ) { from = trim ; trim = NULL ; } else ParseExpression ( trim ) ; if ( from == NULL ) from = GetNextWordToken ( " " , L" " , 4 ) ; Token * string = NULL ; if ( from == NULL ) { string = trim ; trim = NULL ; } if ( string == NULL ) string = GetNextToken ( ) ; if ( string == NULL ) return false ; ParseExpression ( string ) ; Token * close = GetNextCharToken ( ' ' , L' ' ) ; if ( _target == SQL_SQL_SERVER ) { Token :: Change ( name , " " , L" " , 11 ) ; Append ( close , " " , L" " , 1 ) ; } else if ( _target == SQL_ORACLE ) { if ( Token :: Compare ( type , " " , L" " , 1 ) ) Token :: Change ( type , " " , L" " , 7 ) ; else if ( Token :: Compare ( type , " " , L" " , 1 ) ) Token :: Change ( type , " " , L" " , 8 ) ; else if ( Token :: Compare ( type , " " , L" " , 1 ) ) Token :: Change ( type , " " , L" " , 4 ) ; } STATS_SET_CONV_NO_NEED ( true ) FUNC_STATS ( name ) ; return true ; }
TRIM in Oracle, DB2, Sybase ASA
TRIM in Oracle DB2 Sybase ASA
/*open*/ // Type is optional in Oracle, DB2 // Parse trim in Oracle, DB2 // If FROM is not set then trim is also not set in Oracle, DB2 // Parse string // Use LTRIM and RTRIM functions in SQL Server // Oracle does not support L, T, and B types