trigger instead of view
Posted in 2012
Hi,
ifx 11.70 fc6it , Linux
Need a little help to solve a situation what I don't found a decent
workaround.
I'm was executing few tests over the situation bellow , trying
"simulate" a fragmentation/partition using view + trigger...
Just for fun and as possible solution for a database with Innovator-C
which my desire is use it to keep historical data of some collected
statistics.
And to facility the load of data, I want use the view for the "inserts"
DMLs.
* 1 view , result of many selects with union all.
This tables have the same schema and they differ is only the period
of the data, (each table = 1 month)
something like :
drop view if exists vw_dbases;
create view if not exists vw_dbases as
select * from h_dbases_2011_01 where datini >= '2011-01-01' anddatini < '2011-02-01'
union all
select * from h_dbases_2011_02 where datini >= '2011-02-01' anddatini < '2011-03-01'
union all
select * from h_dbases_2011_03 where datini >= '2011-03-01' anddatini < '2011-04-01'
union all
...
* 1 insert trigger with instead of view
I call a SPL to give the properly treatment . HERE is the difficult.
I want wrote a code what identify dynamically the date (year-month) and
execute the insert into the correct table , other desire is don't
have a
schema dependency (suppose I change the schema of this tables adding
a new
column in the middle, the trigger keeps works and identifying the new
fields,
working as 4GL, "LIKE variable.*".
Identify the date and execute the insert into the correct table is
the easy
part. The problem is inform the values.
The table have a considerable amount of columns and is very very very
annoying
and hard work describe each field, casting it to CHAR and treat each
NULL
value...
Let's to code, what I not found a easy workaround :
drop procedure if exists sp_trg_vw_dbases ;
create procedure if not exists sp_trg_vw_dbases()
referencing old as o new as n for vw_dbases
define lSQL char(800);
define lData char(7);
-- set debug file to '/tmp/cesar.out' ;
-- trace on;
let lData = n.datini::datetime year to month ;
-- Here is the code what I desire to work... obvious..don't.
-- how workaround this !???
let lSQL="insert into h_dbases_"||lData||" values ( n.* )" ;
execute immediate lSQL ;