|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi:
Is there any way that I can declare a global variable and access it from few store procedures or triggers? Thank you very much. Regards, Eric |
|
#2
|
|||
|
|||
|
I don't think so...
-- Best regards, Fikret Hasovic http://fikret.fbtalk.net TAMP R&D Team FirebirdSQL Foundation member. - Join today at http://www.firebirdsql.org/ff/foundation JEDI VCS contributor http://jedivcs.sourceforge.net/ |
|
#3
|
|||
|
|||
|
Hi:
Thank you for your reply. Any workaround for this? For example in Sybase we could write select set_appcontext("..","...","..") any equivalent in Firebird? Thank you. Regards, Eric |
|
#4
|
|||
|
|||
|
I don't know...
Maybe you should ask in firebird support list? http://groups.yahoo.com/group/firebird-support -- Best regards, Fikret Hasovic http://fikret.fbtalk.net TAMP R&D Team FirebirdSQL Foundation member. - Join today at http://www.firebirdsql.org/ff/foundation JEDI VCS contributor http://jedivcs.sourceforge.net/ |
|
#5
|
|||
|
|||
|
Hi Fikret Hasovic,
Thank you very much for your infomation. Regards, lsteo Quote:
|
|
#6
|
|||
|
|||
|
Quote:
To store global values you can use generator, or table, or stored procedure. e.g. Create Procedure X Returns (a integer, b integer) As Begin a = 123; b = 456; End |
|
#7
|
|||
|
|||
|
Quote:
Interesting... -- Best regards, Fikret Hasovic http://fikret.fbtalk.net TAMP R&D Team FirebirdSQL Foundation member. - Join today at http://www.firebirdsql.org/ff/foundation JEDI VCS contributor http://jedivcs.sourceforge.net/ |
|
#8
|
|||
|
|||
|
If you need true connection- or transaction- specific variables you can write a small UDF which manages mapping between your variables and values of CURRENT_CONNECTION or CURRENT_TRANSACTION pseudo-variables.
So your resulting PSQL to do this stuff may look like this: old_string_val = set_connection_var('MyVarName', CURRENT_CONNECTION, new_string_var); cur_string_val = get_connection_var('MyVarName', CURRENT_CONNECTION); |
|
#9
|
|||
|
|||
|
Quote:
Yes, Nickolay, that can be done ![]() -- Best regards, Fikret Hasovic http://fikret.fbtalk.net FirebirdSQL Foundation member. - Join today at http://www.firebirdsql.org/ff/foundation JEDI VCS contributor http://jedivcs.sourceforge.net/ |
|
#10
|
|||
|
|||
|
Simple solution
hi,
a simple solution without UDF: /******************************************************************************/ /* Tables */ /******************************************************************************/ CREATE TABLE USER_VARIABLE ( IDCONNECTION INTEGER, VARIABLE_NAME VARCHAR(100), VARIABLE_VALUE VARCHAR(100) ); /******************************************************************************/ /* Indices */ /******************************************************************************/ CREATE INDEX USER_VARIABLE_IDX1 ON USER_VARIABLE (IDCONNECTION); CREATE INDEX USER_VARIABLE_IDX2 ON USER_VARIABLE (VARIABLE_NAME); /******************************************************************************/ /* Triggers for tables */ /******************************************************************************/ /* Trigger: USER_VARIABLE_BI0 */ CREATE OR ALTER TRIGGER USER_VARIABLE_BI0 FOR USER_VARIABLE ACTIVE BEFORE INSERT POSITION 0 AS begin /* Trigger text */ delete from user_variable where idconnection=current_connection and variable_name=new.variable_name; end CREATE OR ALTER PROCEDURE GETVARIABLE ( varname varchar(100)) returns ( varvalue varchar(100)) as begin select coalesce(variable_value,'') from user_variable where idconnection=current_connection and variable_name=:Varname into :Varvalue; suspend; end CREATE OR ALTER PROCEDURE SETVARIABLE ( varname varchar(100), varvalue varchar(100)) as begin insert into user_variable values (current_connection,:Varname,:Varvalue); end ----------------------------------------------------------------- Usage: execute procedure setvariable('VarTest','34'); select * from getvariable('vartest') I was looking for a solution to do this and found it here in the previous post with the "current_connection" variable. so many thanks to the forum ^^ |
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Global variable in Firebird??? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|