Subject | RDB$GET_CONTEXT - How to? |
---|---|
Author | masotti |
Post date | 2009-04-23T09:14:24Z |
Hi all, I'm experimenting rdb$get_context() and rdb$set_context().
Environment:
IBExpert 27.11.2008,
Firebird 2.1.0.17798,
Windows XP SP3
In http://www.firebirdfaq.org/faq343/ (how to add a record number to a
dataset) there is a example how using these functions. It works like a
charm, obviously you must encapsulate it in a common table to apply
filtering on computed columns.
Filtering on ct1.rownum is allways false: maybe that context functions
are applied "after" filtering the result set, but I've found nothing in
tracker or in docs.
BTW, interesting enough, when trying this on a small database, I'm not
able to give any explanation on result.
select cast(ct1.rownum as integer) as number, ct1.context, ct1.name from
(
SELECT
mod(rdb$get_context('USER_TRANSACTION', 'row#'), 10) as row_number,
rdb$set_context('USER_TRANSACTION', 'row#',
coalesce(cast(rdb$get_context('USER_TRANSACTION', 'row#') as integer),
0) + 1),
a.rdb$relation_name
FROM rdb$relations a
ORDER BY a.rdb$relation_name
) as CT1 ( rownum, context, name )
where mod (ct1.context * ct1.rownum, 5) > 0
Output:
NUMBER CONTEXT NAME
4 1 CORSI_INTEGRATI
8 1 DOCENTI_ANNO
3 1 DOMANDE
8 1 GRUPPI
3 1 IBE$SCRIPTS
8 1 LETTURE_STORICO
3 1 MON$ATTACHMENTS
8 1 MON$DATABASE
3 1 MON$TRANSACTIONS
8 1 RDB$BACKUP_HISTORY
3 1 RDB$CHECK_CONSTRAINTS
8 1 RDB$DATABASE
3 1 RDB$EXCEPTIONS
8 1 RDB$FIELD_DIMENSIONS
3 1 RDB$FILTERS
8 1 RDB$FUNCTIONS
3 1 RDB$GENERATORS
8 1 RDB$INDICES
3 1 RDB$PAGES
8 1 RDB$PROCEDURE_PARAMETERS
3 1 RDB$RELATIONS
8 1 RDB$RELATION_FIELDS
3 1 RDB$SECURITY_CLASSES
8 1 RDB$TRIGGERS
3 1 RDB$TYPES
8 1 RDB$VIEW_RELATIONS
3 1 VW_DOCENTI
What exactly happens?
Ciao.
Mimmo.
Environment:
IBExpert 27.11.2008,
Firebird 2.1.0.17798,
Windows XP SP3
In http://www.firebirdfaq.org/faq343/ (how to add a record number to a
dataset) there is a example how using these functions. It works like a
charm, obviously you must encapsulate it in a common table to apply
filtering on computed columns.
Filtering on ct1.rownum is allways false: maybe that context functions
are applied "after" filtering the result set, but I've found nothing in
tracker or in docs.
BTW, interesting enough, when trying this on a small database, I'm not
able to give any explanation on result.
select cast(ct1.rownum as integer) as number, ct1.context, ct1.name from
(
SELECT
mod(rdb$get_context('USER_TRANSACTION', 'row#'), 10) as row_number,
rdb$set_context('USER_TRANSACTION', 'row#',
coalesce(cast(rdb$get_context('USER_TRANSACTION', 'row#') as integer),
0) + 1),
a.rdb$relation_name
FROM rdb$relations a
ORDER BY a.rdb$relation_name
) as CT1 ( rownum, context, name )
where mod (ct1.context * ct1.rownum, 5) > 0
Output:
NUMBER CONTEXT NAME
4 1 CORSI_INTEGRATI
8 1 DOCENTI_ANNO
3 1 DOMANDE
8 1 GRUPPI
3 1 IBE$SCRIPTS
8 1 LETTURE_STORICO
3 1 MON$ATTACHMENTS
8 1 MON$DATABASE
3 1 MON$TRANSACTIONS
8 1 RDB$BACKUP_HISTORY
3 1 RDB$CHECK_CONSTRAINTS
8 1 RDB$DATABASE
3 1 RDB$EXCEPTIONS
8 1 RDB$FIELD_DIMENSIONS
3 1 RDB$FILTERS
8 1 RDB$FUNCTIONS
3 1 RDB$GENERATORS
8 1 RDB$INDICES
3 1 RDB$PAGES
8 1 RDB$PROCEDURE_PARAMETERS
3 1 RDB$RELATIONS
8 1 RDB$RELATION_FIELDS
3 1 RDB$SECURITY_CLASSES
8 1 RDB$TRIGGERS
3 1 RDB$TYPES
8 1 RDB$VIEW_RELATIONS
3 1 VW_DOCENTI
What exactly happens?
Ciao.
Mimmo.