sqlparser/helpers.cpp
// Add variable declarations generated in the procedural block
Add variable declarations generated in the procedural block
Add variable declarations generated in the procedural block
void SqlParser::AddGeneratedVariables()
{
	if(_spl_need_not_found_handler && Target(SQL_MYSQL, SQL_MARIADB))
	{
		MySQLAddNotFoundHandler();
		MySQLInitNotFoundBeforeOpen();
	}
	Token *format_ident = _declare_format;
	if(_source == SQL_ORACLE)
	{
		format_ident = _spl_last_outer_declare_varname;
		if(_spl_last_outer_declare_varname != NULL && Target(SQL_SQL_SERVER))
			format_ident = _spl_last_outer_declare_varname->prev;
	}
	Token *format = Nvl(_declare_format, _spl_outer_begin, _spl_outer_as);
	if(_spl_dyn_sql_var)
	{
		if(_target == SQL_SQL_SERVER)
		{
			Token *append_var = _spl_last_outer_declare_var;
			APPEND_FMT(append_var, "\n", format_ident);
			APPEND_FMT(append_var, "DECLARE ", format);
			APPEND_NOFMT(append_var, "@sql ");
			APPEND_FMT(append_var, "NVARCHAR(max);", format);
		}
	}
	if(_spl_need_rowcount_var)
	{
		if(_target == SQL_POSTGRESQL)
		{
			Token *append_var = GetDeclarationAppend();
			APPEND_FMT(append_var, "\n", format_ident);
			APPEND_NOFMT(append_var, "v_sqlrowcount ");
			APPEND_FMT(append_var, "INT;", format);
		}
	}
}
void SqlParser :: AddGeneratedVariables ( ) { if ( _spl_need_not_found_handler && Target ( SQL_MYSQL , SQL_MARIADB ) ) { MySQLAddNotFoundHandler ( ) ; MySQLInitNotFoundBeforeOpen ( ) ; } Token * format_ident = _declare_format ; if ( _source == SQL_ORACLE ) { format_ident = _spl_last_outer_declare_varname ; if ( _spl_last_outer_declare_varname != NULL && Target ( SQL_SQL_SERVER ) ) format_ident = _spl_last_outer_declare_varname -> prev ; } Token * format = Nvl ( _declare_format , _spl_outer_begin , _spl_outer_as ) ; if ( _spl_dyn_sql_var ) { if ( _target == SQL_SQL_SERVER ) { Token * append_var = _spl_last_outer_declare_var ; APPEND_FMT ( append_var , " \n " , format_ident ) ; APPEND_FMT ( append_var , " " , format ) ; APPEND_NOFMT ( append_var , " " ) ; APPEND_FMT ( append_var , " " , format ) ; } } if ( _spl_need_rowcount_var ) { if ( _target == SQL_POSTGRESQL ) { Token * append_var = GetDeclarationAppend ( ) ; APPEND_FMT ( append_var , " \n " , format_ident ) ; APPEND_NOFMT ( append_var , " " ) ; APPEND_FMT ( append_var , " " , format ) ; } } }
Add variable declarations generated in the procedural block
Add variable declarations generated in the procedural block
// Add not hound handler that must go after all variables and cursors; and initialize not_found variable before second and subsequent OPEN cursors // Oracle uses DECLARE block with the keyword at the beginning so use the variable name to define the indention // DECLARE is already added before the variable, so use prev token // Dynamic SQL variable is used // @sql for sp_executesql that does not allow expressions // sp_executesql requires unicode string // Row count variable needs to be added