sqlparser/language.cpp
// Oracle PL/SQL assignment statement variable := exp, in PostgreSQL var = exp can be used
Oracle PL/SQL assignment statement variable := exp, in PostgreSQL var = exp can be used
Oracle PL / SQL assignment statement variable : = exp in PostgreSQL var = exp can be used
bool SqlParser::ParseAssignmentStatement(Token *variable)
{
	if(variable == NULL)
		return false;
	if(variable->type != TOKEN_WORD && variable->type != TOKEN_IDENT)
		return false;
	Token *colon = GetNextCharToken(':', L':');
	Token *equal = GetNextCharToken('=', L'=');
	if(equal == NULL)
		return false;
	if(colon == NULL)
	{
		Token *prev = GetPrevToken(variable);
		if(prev == NULL)
			return false;
		if(prev->Compare(';', L';') == false && prev->Compare("BEGIN", L"BEGIN", 5) == false && 
			prev->Compare("THEN", L"THEN", 4) == false && prev->Compare("ELSE", L"ELSE", 4) == false &&
			!TOKEN_CMP(prev, "DO"))
			return false;
	}
	Token *decl_var = GetVariableOrParameter(variable);
	if(_target_app == APP_JAVA)
		Token::Remove(colon);
	else
	if(Target(SQL_SQL_SERVER, SQL_MYSQL, SQL_SYBASE) == true)
	{
		Prepend(variable, "SET ", L"SET ", 4, _declare_format);
		if(Target(SQL_SQL_SERVER, SQL_SYBASE) == true)
			ConvertToTsqlVariable(variable);
		Token::Remove(colon);
	}
	else
	if(_target == SQL_ORACLE && colon == NULL)
		Prepend(equal, ":", L":", 1);
	if(Source(SQL_SYBASE_ADS) && decl_var != NULL && decl_var->data_subtype == TOKEN_DT2_BOOL)
	{
		bool bool_op_not_exists = false;
		ParseBooleanExpression(SQL_BOOL_ASSIGN, NULL, NULL, NULL, NULL, &bool_op_not_exists);
		if(!bool_op_not_exists && Target(SQL_SQL_SERVER))
		{
			APPEND(equal, " CASE WHEN ");
			APPEND(GetLastToken(), " THEN 1 ELSE 0 END");
		}
		return true;
	}
	Token *next = GetNextToken();
	ParseExpression(next);
	return true;
}
bool SqlParser :: ParseAssignmentStatement ( Token * variable ) { if ( variable == NULL ) return false ; if ( variable -> type != TOKEN_WORD && variable -> type != TOKEN_IDENT ) return false ; Token * colon = GetNextCharToken ( ' ' , L' ' ) ; Token * equal = GetNextCharToken ( ' ' , L' ' ) ; if ( equal == NULL ) return false ; if ( colon == NULL ) { Token * prev = GetPrevToken ( variable ) ; if ( prev == NULL ) return false ; if ( prev -> Compare ( ' ' , L' ' ) == false && prev -> Compare ( " " , L" " , 5 ) == false && prev -> Compare ( " " , L" " , 4 ) == false && prev -> Compare ( " " , L" " , 4 ) == false && ! TOKEN_CMP ( prev , " " ) ) return false ; } Token * decl_var = GetVariableOrParameter ( variable ) ; if ( _target_app == APP_JAVA ) Token :: Remove ( colon ) ; else if ( Target ( SQL_SQL_SERVER , SQL_MYSQL , SQL_SYBASE ) == true ) { Prepend ( variable , " " , L" " , 4 , _declare_format ) ; if ( Target ( SQL_SQL_SERVER , SQL_SYBASE ) == true ) ConvertToTsqlVariable ( variable ) ; Token :: Remove ( colon ) ; } else if ( _target == SQL_ORACLE && colon == NULL ) Prepend ( equal , " " , L" " , 1 ) ; if ( Source ( SQL_SYBASE_ADS ) && decl_var != NULL && decl_var -> data_subtype == TOKEN_DT2_BOOL ) { bool bool_op_not_exists = false ; ParseBooleanExpression ( SQL_BOOL_ASSIGN , NULL , NULL , NULL , NULL , & bool_op_not_exists ) ; if ( ! bool_op_not_exists && Target ( SQL_SQL_SERVER ) ) { APPEND ( equal , " " ) ; APPEND ( GetLastToken ( ) , " " ) ; } return true ; } Token * next = GetNextToken ( ) ; ParseExpression ( next ) ; return true ; }
Oracle PL/SQL assignment statement variable := exp, in PostgreSQL var = exp can be used
Oracle PL / SQL assignment statement variable : = exp in PostgreSQL var = exp can be used
// Must be a word or identifier // For PostgreSQL assignment can be without : // Previous word must be ; or keyword that starts a block // Try to find variable declaration // SET @var = value in SQL Server, SET var = value in MySQL // Add @ before the name // For Oracle add : if not set // Sybase ADS supports assignment of boolean expression to logical value i.e a = 1=2; // SQL Server does not allow boolean expression if assignment (= <> etc.) but simple assignment a = true is fine (converted to a = 1 using BIT data type) // Assignment expression