|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||||
|
|||||
|
Trigger, NEW and variable field name
Hi,
I'm writing a trigger and I need to access NEW.fieldname WHERE "fieldname" is a variable: SQL Code:
but the "NEW.:fld" syntax isn't supported, and without the colon (NEW.fld) it tries to fetch the non-existing "fld" field. How can I get the NEW and OLD values of the field? |
|
#2
|
||||
|
||||
|
Can you please describe what you are trying to achieve?
__________________
My blog about OpenSource Databases PDF tutorials about OSS databases, DBMonster ... Please contribute to Open Source Development, fill bug reports!!! Developer Shed eSupport Commented my.ini/my.cnf (PLEASE ADD YOUR OWN CONFIG TRICK) An introduction to database normalization Natural or Surrogate key Custom ordering for your results Correlated and uncorrelated subqueries Don't turn your outer joins into inner joins |
|
#3
|
|||
|
|||
|
Quote:
I'd like to explore a way to log the changes to each field (saving both the old and new value) for a given table with a trigger. For instance, if I update/insert a row into TABLE1, I'd like to save the old and new values of each changed field, plus the field name and other properties, without having to list the table fields in the trigger. I can get them querying the system tables from within the trigger. In the code above, the FOR cycle loops through the table field names and uses each one as a variable for the subsequent INSERT query. This way, I can use the same trigger on any table, without knowing its structure beforehand. As said, it's more like a proof of concept than an actual need, still I'd love to know if/how that's possible. |
|
#4
|
|||
|
|||
|
You cannot access NEW<fields-by-name>. It cannot be done.
Martijn Tonies Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle & MS SQL Server Upscene Productions http://www.upscene.com My thoughts: http://blog.upscene.com/martijn/ Database development questions? Check the forum! http://www.databasedevelopmentforum.com |
|
#5
|
|||
|
|||
|
Quote:
"NEW.fieldname" works just fine, it's "NEW.:varname" that doesn't work (I wanted to confirm that the latter was true). For the records, I also got a reply by a borland employee, saying the same thing. Oh well... so much for my proof of concept ![]() |
|
#6
|
|||
|
|||
|
Quote:
Yes, that's what I meant to say ![]() my "field by name" should be taken as being a string variable of some kind. Do note that Firebird is not equal to InterBase. Dynamic SQL in Firebird PSQL allows for much more (weird) constructs compared to InterBase. Martijn Tonies Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle & MS SQL Server Upscene Productions http://www.upscene.com My thoughts: http://blog.upscene.com/martijn/ Database development questions? Check the forum! http://www.databasedevelopmentforum.com |
![]() |
| Viewing: Dev Shed Forums > Databases > Firebird SQL Development > Trigger, NEW and variable field name |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|