sqlparser/statements.cpp
// DB2 SIGNAL statement; Sybase ASA SIGNAL exception_name
DB2 SIGNAL statement; Sybase ASA SIGNAL exception_name
DB2 SIGNAL statement ; Sybase ASA SIGNAL exception_name
bool SqlParser::ParseSignalStatement(Token *signal)
{
	if(signal == NULL)
		return false;
    STATS_DECL
	PL_STMS_STATS(signal);
	Token *sqlstate = GetNextWordToken("SQLSTATE", L"SQLSTATE", 8);
	Token *error = GetNextToken();
	Token *error_text = error;
	if(error == NULL)
		return false;
	if(error->type != TOKEN_STRING)
	{
		ListwmItem *i = Find(_spl_user_exceptions, error);
		if(i != NULL)
			error_text = (Token*)i->value2;
	}
	Token *open = GetNextCharToken('(', L'(');
	Token *message = NULL;
	Token *close = NULL;
	if(open != NULL)
	{
		message = GetNextToken();
		close = GetNextCharToken(')', L')');
	}
	Token *end = GetLastToken();
	if(_target == SQL_SQL_SERVER)
	{
		Token::Change(signal, "RAISERROR", L"RAISERROR", 9);
		if(signal->next != NULL && signal->next->IsBlank() == true)
			Token::Change(signal->next, "(", L"(", 1);
		else
			Append(signal, "(", L"(", 1);
		if(error != error_text)
			Token::Change(error, error_text);
		Append(end, ", 16, 1)", L", 16, 1)", 8);
	}
	else
	if(_target == SQL_ORACLE)
	{
		Token::Change(signal, "RAISE_APPLICATION_ERROR", L"RAISE_APPLICATION_ERROR", 23);
		Token::Remove(sqlstate);
		Token::Remove(error);
		TokenStr err("-20", L"-20", 3);
		err.Append(error_text, 3, 3);
		err.Append(", ", L", ", 2);
		AppendNoFormat(open, &err); 
	}
	return true;
}
bool SqlParser :: ParseSignalStatement ( Token * signal ) { if ( signal == NULL ) return false ; STATS_DECL PL_STMS_STATS ( signal ) ; Token * sqlstate = GetNextWordToken ( " " , L" " , 8 ) ; Token * error = GetNextToken ( ) ; Token * error_text = error ; if ( error == NULL ) return false ; if ( error -> type != TOKEN_STRING ) { ListwmItem * i = Find ( _spl_user_exceptions , error ) ; if ( i != NULL ) error_text = ( Token * ) i -> value2 ; } Token * open = GetNextCharToken ( ' ' , L' ' ) ; Token * message = NULL ; Token * close = NULL ; if ( open != NULL ) { message = GetNextToken ( ) ; close = GetNextCharToken ( ' ' , L' ' ) ; } Token * end = GetLastToken ( ) ; if ( _target == SQL_SQL_SERVER ) { Token :: Change ( signal , " " , L" " , 9 ) ; if ( signal -> next != NULL && signal -> next -> IsBlank ( ) == true ) Token :: Change ( signal -> next , " " , L" " , 1 ) ; else Append ( signal , " " , L" " , 1 ) ; if ( error != error_text ) Token :: Change ( error , error_text ) ; Append ( end , " " , L" " , 8 ) ; } else if ( _target == SQL_ORACLE ) { Token :: Change ( signal , " " , L" " , 23 ) ; Token :: Remove ( sqlstate ) ; Token :: Remove ( error ) ; TokenStr err ( " " , L" " , 3 ) ; err . Append ( error_text , 3 , 3 ) ; err . Append ( " " , L" " , 2 ) ; AppendNoFormat ( open , & err ) ; } return true ; }
DB2 SIGNAL statement; Sybase ASA SIGNAL exception_name
DB2 SIGNAL statement ; Sybase ASA SIGNAL exception_name
// SQLSTATE keyword in DB2 // Error code in single quotes in DB2; exception name in Sybase ASA // If error does not contain string literal (Sybase ASA), find error code // Exception/condition found // Message text ('message') in DB2 // RAISERROR(text, 16, 1) in SQL Server // Replace blank with ( // RAISE_APPLICATION(-error, 'message') in Oracle // Error number is negative and within -20000 and -20999 // Skip ' and first 2 digits of SQLSTATE as well as closing '