0
votes

I am working on Oracle Apex and not that familiar with it. The application I am working on has already been developed by some other developer who has left the company. The issue is - There is a main/super user with which the actual db connection is made (using DADS.conf file entry). After that, user is presented with a Login screen where he enters db subuser credentials. We have few application level contexts defined, so after subuser login we set the context like username for that subuser. In the application there is a report that is supposed to show data for logged in subuser. Now, when first user logs in, the reports shows correct data. When second user logs in from a different machine report starts showing data for the second user in both the application instances. Sometimes second user's report shows data for first user. This behavior is random. Apart from the report other application works fine. I seems that Apex in this case is using same physical database connection and hence the contexts are getting overwritten. I might be wrong here. I am very confused and unable to find any solution. Any help is appreciated.

Here is the report query (much complicated) -

With 
Date_range as (
   select * from X_LOHAC_DateRANGE_WK
    )
  --
    ,Haud_a
        AS (            select wor_works_order_no haud_pk_id, WOR_CHAR_ATTRIB110 HAUD_NEW_VALUE, WOR_DATE_ATTRIB131 HAUD_TIMESTAMP
          from work_orders
          where 1=1
             AND WOR_CHAR_ATTRIB110 in  ('REV', 'REVUPD','REVCOMM','APPCOMM','APP','REJCOMM','REJ','INTREJ','APPUN')
             AND WOR_DATE_ATTRIB131 BETWEEN (select min(st_range) from Date_range) AND (select max(end_range) from Date_range)
            )            
      , haud as (
          select h.*, range_value from haud_a h, Date_range 
          where   HAUD_TIMESTAMP BETWEEN st_range AND end_range 
          )
--
--
--
, claims as
(
        select a.woc_works_order_no, a.woc_interim_no, woc_claim_value, claim_previous from
            (select woc_works_order_no, woc_interim_no, woc_claim_value
            , lag(woc_claim_value) over (partition by woc_works_order_no order by woc_interim_no Asc)  as claim_previous 
            from work_order_claims
            order by woc_works_order_no, woc_interim_no asc) a
            , (select woc_works_order_no, max(woc_interim_no) woc_interim_no from work_order_claims group by woc_works_order_no) b
        where a.woc_works_order_no = b.woc_works_order_no
        and a. woc_interim_no = b.woc_interim_no 
)
--
, main as (
SELECT DISTINCT
    '<p title="Click for forms"  id="'||works_order_number||'"  onmouseover="showWOLDetails(this);">'||  WORKs_ORDER_NUMBER||'</p>' WORKS_ORDER_NUMBER
    ,decode( DECODE (mai_sdo_util.wo_has_shape (hig.get_sysopt ('SDOWOLNTH'), wor.works_order_number),
                    'TRUE', 'Y','N'),
            'N',
        '<img width=24 height=24 src="/im4_framework/images/grey_globe.png" title="No Location">'
        ,'<a href="javascript:showWODefOnMap('''||WORKs_ORDER_NUMBER||''',''~'');" ><img width=24 height=24 src="/im4_framework/images/globe_64.gif" title="Find on Map"></a>') map
    ,decode(im_framework.has_doc(works_order_number,'WORK_ORDERS'),0,
        '<img width=24 height=24 src="/im4_framework/images/mfclosed.gif" title="No Documents">'
        ,'<a href="javascript:showWODocAssocs('''||works_order_number||''',&APP_ID.,&APP_SESSION.,''WORK_ORDERS'')" ><img width=24 height=24 src="/im4_framework/images/mfopen.gif" title="Show Documents"></a>') DOCS
    ,(select ial_meaning from nm_inv_attri_lookup where ial_domain = 'INVOICE_STATUS' and ial_value = wor_char_attrib110) INVOICE_STATUS
    ,WOR_CHAR_ATTRIB111 as "INVOICE_STATUS_COMMENT"
    ,works_order_description
    , claim_previous Previous_Claim_Amount
    , woc_claim_value New_Claim_Amount
    , WOR_CHAR_ATTRIB111  Claim_Comments
     ,bud.work_category_description  Budget_Description
    , 'BOQ' BOQ
        ,WOR_CHAR_ATTRIB115    "Correct area of work "
        ,WOR_CHAR_ATTRIB116    "Quality of Work OK"
        ,WOR_CHAR_ATTRIB70    "Correct BOQ_Uplifts" 
        ,WOR_CHAR_ATTRIB113    "Before_After_Photos_Present" --"Before After Photos Present"
        ,WOR_CHAR_ATTRIB114 "Certification Comments"
--,(select hus_name from hig_audits, hig_users where haud_pk_id = haud.haud_pk_id and haud_timestamp = haud.haud_timestamp and haud_new_value = haud.haud_new_value and haud_attribute_name = haud.haud_attribute_name and  rownum =1) Reviewed_By
,  (select HUS_NAME from hig_users where hus_user_id = WOR_NUM_ATTRIB04 )   Reviewed_By  
  , works_order_number wor_number
, 'Edit' rec_edit
--
    FROM imf_mai_work_orders_all_attrib wor,
        imf_mai_work_order_lines wol,
        haud
    ,claims        
    ,imf_mai_budgets bud
        ,pod_nm_element_security,
        pod_budget_security
    WHERE    1=1
        and wol.budget_id = bud.budget_id
        AND works_order_number = haud_pk_id
        AND works_order_number = claims.woc_works_order_no(+)
        AND works_order_number = work_order_number
        AND pod_nm_element_security.element_id = wol.network_element_id
        AND pod_budget_security.BUDGET_CODE = wol.work_category
        AND  WOR_CHAR_ATTRIB110 = haud_new_value
        AND range_value = :P40_DAYS
        AND WOR_CHAR_ATTRIB110  = :P40_PRIORITY
        )     
--
Select * from main;

Setting Context just uses DBMS_SESSION package as follows -

DBMS_SESSION.SET_CONTEXT('NM3SEC', p_attribute, p_value);

In this case - p_attribute is USERNAME

1
That question - as it currently stands - is very difficult (IMHO, impossible) to answer. Please add at least the source code for the procedures where the context is set, as well as the SQL query used in your APEX report (don't post it as a comment - use the "Edit" button to edit your question).Frank Schmitt
Thank you for your reply Frank! I have edited the original question to add the things you mentioned.Upendra Hukeri

1 Answers

0
votes

You can't use DBMS_SESSION with apex since it's a stateless framework pooling multiple connections between multiple sessions.

Apex uses url based session-id's.

You should rather

1) Create an application item in Shared Components. 2) Set the value of the item as a post login procedure using apex_util.set_session_state

Use the value of that item in your SQL code.