sqlparser/statements.cpp
// Oracle, PostgreSQL RAISE statement; Informix RAISE EXCEPTION 
Oracle, PostgreSQL RAISE statement; Informix RAISE EXCEPTION
Oracle PostgreSQL RAISE statement ; Informix RAISE EXCEPTION
bool SqlParser::ParseRaiseStatement(Token *raise)
{
	if(raise == NULL)
		return false;
    STATS_DECL
	STATS_SET_DESC(PLSQL_STMT_RAISE_DESC)
	PL_STMS_STATS(raise);
	Token *notice = GetNextWordToken("NOTICE", L"NOTICE", 6);
	Token *exception = NULL;
	if(notice == NULL)
		exception = GetNextWordToken("EXCEPTION", L"EXCEPTION", 9);
	if(notice == NULL && exception == NULL)
	{
		Token *name = GetNextToken();
		if(_target_app == APP_JAVA)
		{
			TOKEN_CHANGE_NOFMT(raise, "throw new ");
			APPEND_NOFMT(name, "()");
		}
		else
		if(_target == SQL_NETEZZA)
			Append(raise, " EXCEPTION ''", L" EXCEPTION ''", 13);
		return true;
	}
	Token *format = NULL;
	ListW params;
	Token *error_code = NULL;
	Token *isam_error = NULL;
	Token *text = NULL;
	if(_source == SQL_POSTGRESQL)
		format = GetNextToken();
	else
	if(_source == SQL_INFORMIX)
	{
		error_code = GetNextToken();
		Token *comma = GetNextCharToken(',', L',');
		if(comma != NULL)
			isam_error = GetNextToken();
		comma = GetNextCharToken(',', L',');
		if(comma != NULL)
			text = GetNextToken();
	}
	if(format != NULL && format->type == TOKEN_STRING)
	{
		while(true)
		{
			Token *comma = GetNextCharToken(',', L',');
			if(comma == NULL)
				break;
			Token *exp = GetNextToken();
			if(exp == NULL)
				break;
			ParseExpression(exp);
			params.Add(exp);
			if(_target == SQL_ORACLE)
				Token::Remove(comma);
		}
	}
	if(notice != NULL)
	{
		if(_target == SQL_ORACLE)
		{
			Token::Change(raise, "DBMS_OUTPUT.PUT_LINE(", L"DBMS_OUTPUT.PUT_LINE(", 21);
			Token::Remove(notice);
			PostgresFormatToConcat(format, params);
			AppendNoFormat(GetLastToken(), ")", L")", 1);
		}
	}	
	else
	if(exception != NULL)
	{
		if(_target == SQL_ORACLE)
		{
			Token::Change(raise, "RAISE_APPLICATION_ERROR(", L"RAISE_APPLICATION_ERROR(", 24);
			Token::Remove(exception);
			AppendNoFormat(GetLastToken(), ")", L")", 1);
		}
	}
	return true;
}
bool SqlParser :: ParseRaiseStatement ( Token * raise ) { if ( raise == NULL ) return false ; STATS_DECL STATS_SET_DESC ( PLSQL_STMT_RAISE_DESC ) PL_STMS_STATS ( raise ) ; Token * notice = GetNextWordToken ( " " , L" " , 6 ) ; Token * exception = NULL ; if ( notice == NULL ) exception = GetNextWordToken ( " " , L" " , 9 ) ; if ( notice == NULL && exception == NULL ) { Token * name = GetNextToken ( ) ; if ( _target_app == APP_JAVA ) { TOKEN_CHANGE_NOFMT ( raise , " " ) ; APPEND_NOFMT ( name , " " ) ; } else if ( _target == SQL_NETEZZA ) Append ( raise , " " , L" " , 13 ) ; return true ; } Token * format = NULL ; ListW params ; Token * error_code = NULL ; Token * isam_error = NULL ; Token * text = NULL ; if ( _source == SQL_POSTGRESQL ) format = GetNextToken ( ) ; else if ( _source == SQL_INFORMIX ) { error_code = GetNextToken ( ) ; Token * comma = GetNextCharToken ( ' ' , L' ' ) ; if ( comma != NULL ) isam_error = GetNextToken ( ) ; comma = GetNextCharToken ( ' ' , L' ' ) ; if ( comma != NULL ) text = GetNextToken ( ) ; } if ( format != NULL && format -> type == TOKEN_STRING ) { while ( true ) { Token * comma = GetNextCharToken ( ' ' , L' ' ) ; if ( comma == NULL ) break ; Token * exp = GetNextToken ( ) ; if ( exp == NULL ) break ; ParseExpression ( exp ) ; params . Add ( exp ) ; if ( _target == SQL_ORACLE ) Token :: Remove ( comma ) ; } } if ( notice != NULL ) { if ( _target == SQL_ORACLE ) { Token :: Change ( raise , " " , L" " , 21 ) ; Token :: Remove ( notice ) ; PostgresFormatToConcat ( format , params ) ; AppendNoFormat ( GetLastToken ( ) , " " , L" " , 1 ) ; } } else if ( exception != NULL ) { if ( _target == SQL_ORACLE ) { Token :: Change ( raise , " " , L" " , 24 ) ; Token :: Remove ( exception ) ; AppendNoFormat ( GetLastToken ( ) , " " , L" " , 1 ) ; } } return true ; }
Oracle, PostgreSQL RAISE statement; Informix RAISE EXCEPTION
Oracle PostgreSQL RAISE statement ; Informix RAISE EXCEPTION
// EXCEPTION, NOTICE etc. // Standalone RAISE // Exception name in Oracle // Netezza does not support standalone RAISE // Format and parameters in PostgreSQL // Error code, isam error variable and text message in Informix // ISAM error is optional // Message text is optional // String literal representing format in PostgreSQL // Parse parameters // No parameters anymore // Remove comma for Oracle as expressions will be concatenated // RAISE NOTICE // DBMS_OUTPUT.PUT_LINE() in Oracle // Transform format string with parameters to concatenation expression // RAISE EXCEPTION // Use RAISE_APPLICATION_ERROR in Oracle