sqlparser/language.cpp
// Check for NEW or OLD column reference in trigger
Check for NEW or OLD column reference in trigger
Check for NEW or OLD column reference in trigger
bool SqlParser::ConvertTriggerNewOldColumn(Token *token)
{
	if(token == NULL || _spl_scope != SQL_SCOPE_TRIGGER)
		return false;
	bool exists = false;
	if(_spl_new_correlation_name != NULL && 
		Token::Compare(_spl_new_correlation_name, token, _spl_new_correlation_name->len) == true && 
			token->Compare(".", L".", _spl_new_correlation_name->len, 1) == true)
	{
		if(_target == SQL_ORACLE && IsScope(SQL_SCOPE_TRG_WHEN_CONDITION) == false)
		{
			TokenStr ident(":", L":", 1);
			ident.Append(token);
			Token::ChangeNoFormat(token, ident);
		}
		exists = true; 
	}
	else
	if(_spl_new_correlation_name == NULL && Token::Compare(token, "NEW", L"NEW", 1, 3) == true && 
			token->Compare(".", L".", 4, 1) == true)
	{
		if(_target == SQL_ORACLE && IsScope(SQL_SCOPE_TRG_WHEN_CONDITION) == false)
		{
			TokenStr ident(":", L":", 1);
			ident.Append(token);
			Token::ChangeNoFormat(token, ident);
		}
		exists = true; 
	}
	else
	if(_spl_old_correlation_name != NULL && 
		Token::Compare(_spl_old_correlation_name, token, _spl_old_correlation_name->len) == true && 
			token->Compare(".", L".", _spl_old_correlation_name->len, 1) == true) 
	{
		if(_target == SQL_SQL_SERVER)
		{
			TokenStr ident("@", L"@", 1);
			size_t old_len = _spl_old_correlation_name->len;
			ident.Append(token, 0, old_len);
			ident.Append("_", L"_", 1);
			ident.Append(token, old_len + 1, token->len - old_len - 1);
			Token::ChangeNoFormat(token, ident);
		}
		else
		if(_target == SQL_ORACLE && IsScope(SQL_SCOPE_TRG_WHEN_CONDITION) == false)
		{
			TokenStr ident(":", L":", 1);
			ident.Append(token);
			Token::ChangeNoFormat(token, ident);
		}
		if(Find(_spl_tr_old_columns, token) == NULL)
			_spl_tr_old_columns.Add(token);
		exists = true;
	}
	else
	if(_spl_old_correlation_name == NULL && Token::Compare(token, "OLD", L"OLD", 1, 3) == true && 
			token->Compare(".", L".", 4, 1) == true)
	{
		if(_target == SQL_ORACLE && IsScope(SQL_SCOPE_TRG_WHEN_CONDITION) == false)
		{
			TokenStr ident(":", L":", 1);
			ident.Append(token);
			Token::ChangeNoFormat(token, ident);
		}
		if(Find(_spl_tr_old_columns, token) == NULL)
			_spl_tr_old_columns.Add(token);
		exists = true;
	}		
	return exists;
}
bool SqlParser :: ConvertTriggerNewOldColumn ( Token * token ) { if ( token == NULL || _spl_scope != SQL_SCOPE_TRIGGER ) return false ; bool exists = false ; if ( _spl_new_correlation_name != NULL && Token :: Compare ( _spl_new_correlation_name , token , _spl_new_correlation_name -> len ) == true && token -> Compare ( " " , L" " , _spl_new_correlation_name -> len , 1 ) == true ) { if ( _target == SQL_ORACLE && IsScope ( SQL_SCOPE_TRG_WHEN_CONDITION ) == false ) { TokenStr ident ( " " , L" " , 1 ) ; ident . Append ( token ) ; Token :: ChangeNoFormat ( token , ident ) ; } exists = true ; } else if ( _spl_new_correlation_name == NULL && Token :: Compare ( token , " " , L" " , 1 , 3 ) == true && token -> Compare ( " " , L" " , 4 , 1 ) == true ) { if ( _target == SQL_ORACLE && IsScope ( SQL_SCOPE_TRG_WHEN_CONDITION ) == false ) { TokenStr ident ( " " , L" " , 1 ) ; ident . Append ( token ) ; Token :: ChangeNoFormat ( token , ident ) ; } exists = true ; } else if ( _spl_old_correlation_name != NULL && Token :: Compare ( _spl_old_correlation_name , token , _spl_old_correlation_name -> len ) == true && token -> Compare ( " " , L" " , _spl_old_correlation_name -> len , 1 ) == true ) { if ( _target == SQL_SQL_SERVER ) { TokenStr ident ( " " , L" " , 1 ) ; size_t old_len = _spl_old_correlation_name -> len ; ident . Append ( token , 0 , old_len ) ; ident . Append ( " " , L" " , 1 ) ; ident . Append ( token , old_len + 1 , token -> len - old_len - 1 ) ; Token :: ChangeNoFormat ( token , ident ) ; } else if ( _target == SQL_ORACLE && IsScope ( SQL_SCOPE_TRG_WHEN_CONDITION ) == false ) { TokenStr ident ( " " , L" " , 1 ) ; ident . Append ( token ) ; Token :: ChangeNoFormat ( token , ident ) ; } if ( Find ( _spl_tr_old_columns , token ) == NULL ) _spl_tr_old_columns . Add ( token ) ; exists = true ; } else if ( _spl_old_correlation_name == NULL && Token :: Compare ( token , " " , L" " , 1 , 3 ) == true && token -> Compare ( " " , L" " , 4 , 1 ) == true ) { if ( _target == SQL_ORACLE && IsScope ( SQL_SCOPE_TRG_WHEN_CONDITION ) == false ) { TokenStr ident ( " " , L" " , 1 ) ; ident . Append ( token ) ; Token :: ChangeNoFormat ( token , ident ) ; } if ( Find ( _spl_tr_old_columns , token ) == NULL ) _spl_tr_old_columns . Add ( token ) ; exists = true ; } return exists ; }
Check for NEW or OLD column reference in trigger
Check for NEW or OLD column reference in trigger
// Check for new. prefix in DB2 // :new.column in Oracle, but not in WHEN condition // Check for default new. prefix in DB2 // :new.column in Oracle, but not in WHEN condition // Check for old. prefix in DB2 // Change to @old_field in SQL Server // Append OLD name _ and column name  // :old.column in Oracle, but not in WHEN condition // Save referenced old columns (once only) // :old.column in Oracle, but not in WHEN condition // Save referenced old columns (once only)