Oracle APEX - APEX_UTIL.SET_SESSION_STATE not working - oracle

I have a process running On Submit.
At the end of the process, I am trying to update the session state of an item :P2_CASE_ID.
I am trying to assign it the value of a variable calculated in the PL\SQL.
My code at the end setting the session state is as below:
APEX_DEBUG.INFO(p_message => 'ABOUT TO CHANGE VALUE OF P2_CASE_ID, BEFORE: ' || :P2_CASE_ID);
APEX_DEBUG.INFO(p_message => 'CHANGING P2_CASE_ID TO HAVE THE VALUE OF case_ids: ' || case_ids);
APEX_UTIL.SET_SESSION_STATE('P2_CASE_ID',RTRIM(case_ids , ','));
APEX_DEBUG.INFO(p_message => 'CHANGED VALUE OF P2_CASE_ID, AFTER: ' || :P2_CASE_ID);
When I check the debug logs, the session state hasn't changed.
select * from APEX_DEBUG_MESSAGES WHERE MESSAGE like '%P2_CASE_ID%'
ORDER BY MESSAGE_TIMESTAMP DESC
Output from DEBUG:
> ABOUT TO CHANGE VALUE OF P2_CASE_ID, BEFORE: 2003,2004
> CHANGING P2_CASE_ID TO HAVE THE VALUE OF case_ids: 2006,2007,2008,2009
> Session State: P2_CASE_ID=>2006, 2007, 2008, 2009
> CHANGED VALUE OF P2_CASE_ID, AFTER: 2003,2004
The debug line starting "Session State" is not one of mine, so assume it is an output of the APEX_UTIL function to set the session state.

Use APEX_UTIL.GET_SESSION_STATE to check if it is in session state. Mixing bind variable syntax with set/get session state in the same process is not a good practice.
But... there should be no need to use APEX_UTIL.SET_SESSION_STATE within the context of your application.
:P2_CASE_ID := RTRIM(case_ids , ',');
Will work just as well and it's less typing :)

Related

How to include session id in APEX_UTIL.PREPARE_URL?

I'm running Apex 20.1 and I need to generate some urls that includes the checksum and the session (that's mandatory)
I'm doing :
Output := APEX_UTIL.PREPARE_URL(p_url => 'f?p=' || ApplicationAlias || ':' || PageAlias || ':' || SessionId ||'::::' || Arguments || ':' || ArgumentsValues, p_checksum_type => 'SESSION');
with :
-- for example
Arguments := 'param1,param2';
ArgumentsValue := 'value1,value2';
This command works properly but the URL is missing the session.
The URL Returned is :
https://www.example.com/ords/schema/r/myapp/pagealias?
param1=value1&
param2=value2&
cs=3BSsM-dn0SHfT0DBLYTRIHlSC_71paQVC0VQ_Hfa6YuVc-DzsnTzEs6yH
Now I need to have the session included in the URL. Means at the end of the URL I should have
&session=45654654987
I tried adding the session manually like :
Output := Output || '&session=' || v('APP_SESSION');
This works only for standard pages and not modal pages. So for modal pages I'm doing like :
-- Output generated from APEX_UTIL.PREPARE_URL :
javascript:apex.navigation.dialog(
'\u002Fords\u002Fschema\u002Fr\u002Fmyapp\u002pagealias?
param1=value1\u0026
param2=value2\u0026
cs=3_XtJdikM6ypsgs1BPNLnh3dKfHI5-gbFl0YMA78wn032WRoN8Z4PoFDOmQJ9RvaMkW1q-Uk-x9BNEaunXyY_hw\u0026
dialogCs=fC8UqaERKj1k7OONTBxSKhPe4GeVKJ4Mk0nSTNDMRIR0o5hpagnDAKoNiYHzqcWo5Q6FgikwEvkbfQBdNE7MtQ',
{title:'Page title',height:'auto',width:'720',maxWidth:'960',modal:true,dialog:null},'t-Dialog-page--standard '+'',apex.jQuery('#regionId'));
Trick to fix it :
Output := replace(Output, ',{title' , '&session=' || v('APP_SESSION') || ',{title');
That returns
javascript:apex.navigation.dialog(
'\u002Fords\u002Fschema\u002Fr\u002Fmyapp\u002pagealias?
param1=value1\u0026
param2=value2\u0026
cs=3_XtJdikM6ypsgs1BPNLnh3dKfHI5-gbFl0YMA78wn032WRoN8Z4PoFDOmQJ9RvaMkW1q-Uk-x9BNEaunXyY_hw\u0026
dialogCs=fC8UqaERKj1k7OONTBxSKhPe4GeVKJ4Mk0nSTNDMRIR0o5hpagnDAKoNiYHzqcWo5Q6FgikwEvkbfQBdNE7MtQ&
session=98798798797',
{title:'Page title',height:'auto',width:'720',maxWidth:'960',modal:true,dialog:null},'t-Dialog-page--standard '+'',apex.jQuery('#regionId'));
Is there any better way to do this please ?
Thanks.
Cheers,
Instead of using APEX_UTL.PREPARE_URL, have you tried using APEX_PAGE.GET_URL? In the APEX 21.2 documentation for APEX_UTIL.PREPARE_URL, it is recommended to use APEX_PAGE.GET_URL instead of APEX_UTIL.PREPARE_URL.
APEX_PAGE.GET_URL has a parameter to include the APEX session id so it should properly build the session id into the URL depending the type of page you are navigating to. The checksum will also automatically be generated in the URL as long as you are navigating within the same workspace as your current session.
APEX_PAGE.GET_URL will also return the URL in "friendly" syntax if "friendly URLs" are enabled for the application of the page you are navigating to.

My Roblox Studio script is sometimes having errors.. idk why

So.. I've been coding to make a GUI show the quantity of currency of a player, the datastore API works perfectly but the local script doesn't (it's local because else it would just update it each time a player's currency gets updated and would be a mess being the opposite of what I want to)
and well... sometimes it loads the currency into the GUI but other times it just stays on the original text: "Label" instead of my current currency (4600)
here's the proof
What normally happens and should always happen
What sometimes happens and shouldn't happen:
here's the script, I've tried putting waits on the start but the original code is inside the while true do..
wait(game.Players.LocalPlayer:WaitForChild("Data")
wait(game.Players.LocalPlayer.Data:WaitForChild("Bells"))
while true do
script.Parent.TextLabel.Text = game.Players.LocalPlayer:WaitForChild("Data"):WaitForChild("Bells").Value
wait() --wait is for not making the loop break and stop the whole script
end
well.. if you want to see if data is really in the player, here's the script, it requires a API (DataStore2)
--[Animal Crossing Roblox Edition Data Store]--
--Bryan99354--
--Module not mine--
--Made with a AlvinBlox tutorial--
--·.·.*[Get Data Store, do not erase]*.·.·--
local DataStore2 = require(1936396537)
--[Default Values]--
local DefaultValue_Bells = 300
local DefaultValue_CustomClothes = 0
--[Data Store Functions]--
game.Players.PlayerAdded:Connect(function(player)
--[Data stores]--
local BellsDataStore = DataStore2("Bells",player)
local Data = Instance.new("Folder",player)
Data.Name = "Data"
Bells = Instance.new("IntValue",Data)
Bells.Name = "Bells"
local CustomClothesDataStore = DataStore2("CustomClothes",player)
local CustomClothes = Instance.new("IntValue",Data)
CustomClothes.Name = "CustomClothes"
local function CustomClothesUpdate(UpdatedValue)
CustomClothes.Value = CustomClothesDataStore:Get(UpdatedValue)
end
local function BellsUpdate(UpdatedValue)
Bells.Value = BellsDataStore:Get(UpdatedValue)
end
BellsUpdate(DefaultValue_Bells)
CustomClothesUpdate(DefaultValue_CustomClothes)
BellsDataStore:OnUpdate(BellsUpdate)
CustomClothesDataStore:OnUpdate(CustomClothesUpdate)
end)
--[test and reference functions]--
workspace.TestDevPointGiver.ClickDetector.MouseClick:Connect(function(player)
local BellsDataStore = DataStore2("Bells",player)
BellsDataStore:Increment(50,DefaultValue_Bells)
end)
workspace.TestDevCustomClothesGiver.ClickDetector.MouseClick:Connect(function(player)
local CustomClothesDataStore = DataStore2("CustomClothes",player)
CustomClothesDataStore:Increment(50,DefaultValue_CustomClothes)
end)
the code that creates "Data" and "Bells" is located in the comment: Data Stores
the only script that gets the issue is the short one with no reason :<
I hope that you can help me :3
#Night94 I tryed your script but it also failed sometimes
The syntax in your LocalScript is a little off with the waits. With that fixed, it works every time. Also, I would use an event handler instead of updating the value with a loop:
game.Players.LocalPlayer:WaitForChild("Data"):WaitForChild("Bells").Changed:Connect(function(value)
script.Parent.TextLabel.Text = value
end)

Airflow retain the same database connection?

I'm using Airflow for some ETL things and in some stages, I would like to use temporary tables (mostly to keep the code and data objects self-contained and to avoid to use a lot of metadata tables).
Using the Postgres connection in Airflow and the "PostgresOperator" the behaviour that I found was: For each execution of a PostgresOperator we have a new connection (or session, you name it) in the database. In other words: We lose all temporary objects of the previous component of the DAG.
To emulate a simple example, I use this code (do not run, just see the objects):
import os
from airflow import DAG
from airflow.operators.postgres_operator import PostgresOperator
default_args = {
'owner': 'airflow'
,'depends_on_past': False
,'start_date': datetime(2018, 6, 13)
,'retries': 3
,'retry_delay': timedelta(minutes=5)
}
dag = DAG(
'refresh_views'
, default_args=default_args)
# Create database workflow
drop_exist_temporary_view = "DROP TABLE IF EXISTS temporary_table_to_be_used;"
create_temporary_view = """
CREATE TEMPORARY TABLE temporary_table_to_be_used AS
SELECT relname AS views
,CASE WHEN relispopulated = 'true' THEN 1 ELSE 0 END AS relispopulated
,CAST(reltuples AS INT) AS reltuples
FROM pg_class
WHERE relname = 'some_view'
ORDER BY reltuples ASC;"""
use_temporary_view = """
DO $$
DECLARE
is_correct integer := (SELECT relispopulated FROM temporary_table_to_be_used WHERE views LIKE '%<<some_name>>%');
BEGIN
start_time := clock_timestamp();
IF is_materialized = 0 THEN
EXECUTE 'REFRESH MATERIALIZED VIEW ' || view_to_refresh || ' WITH DATA;';
ELSE
EXECUTE 'REFRESH MATERIALIZED VIEW CONCURRENTLY ' || view_to_refresh || ' WITH DATA;';
END IF;
END;
$$ LANGUAGE plpgsql;
"""
# Objects to be executed
drop_exist_temporary_view = PostgresOperator(
task_id='drop_exist_temporary_view',
sql=drop_exist_temporary_view,
postgres_conn_id='dwh_staging',
dag=dag)
create_temporary_view = PostgresOperator(
task_id='create_temporary_view',
sql=create_temporary_view,
postgres_conn_id='dwh_staging',
dag=dag)
use_temporary_view = PostgresOperator(
task_id='use_temporary_view',
sql=use_temporary_view,
postgres_conn_id='dwh_staging',
dag=dag)
# Data workflow
drop_exist_temporary_view >> create_temporary_view >> use_temporary_view
At the end of execution, I receive the following message:
[2018-06-14 15:26:44,807] {base_task_runner.py:95} INFO - Subtask: psycopg2.ProgrammingError: relation "temporary_table_to_be_used" does not exist
Someone knows if Airflow has some way to retain the same connection to the database? I think it can save a lot of work in creating/maintaining several objects in the database.
You can retain the connection to the database by building a custom Operator which leverages the PostgresHook to retain a connection to the db while you perform some set of sql operations.
You may find some examples in contrib on incubator-airflow or in Airflow-Plugins.
Another option is to persist this temporary data to XCOMs. This will give you the ability to keep the metadata used with the task in which it was created. This may help troubleshooting down the road.

Password Changer using VAccess

Hey I am working on a password changer. User logs in ( successfully), loads a global var with user initials, then launch a password expired form. I try and use those initials on the password expired form to retrieve user info from DB.
vaUserLog.FieldValue("USERINIT") = UserInitials
vaUserLog.GetEqual
vaStat = vaUserLog.Status
vaStat keeps giving me an error of 4. I am using pervasive v9. Connection with VA looks like:
With vaUserLog
.RefreshLocations = True
.DdfPath = DataPath
.TableName = "USERLOG"
.Location = "USERLOG.MKD"
.Open
If .Status <> 0 Then
ErrMsg = "Error Opening File " + .TableName + " - Status " + str$(.Status) + vbCrLf + "Contact IT Department"
End If
End With
In DB table, USERINIT is Char, 3. UserInitials is a String.
Probably missing something small but can't think right now. Any help is appreciate. Lemme know if you require more info.
Cheers
Status 4 means that the record could not be found. In your case, it could be the case of the value being searched is wrong, there's a different padding (spaces versus binary zero), or that the UserInitials value just isn't in the data file.
You can use MKDE Tracing to see what's actually being passed to the PSQL engine. Once you've done that, make sure the value you're using works through the Function Executor where you can open the file and perform a GetEqual.
Here are my suggestions:
- Make sure you're pointing to the right data files.
- Make sure you're passing the right value into the GetEqual (by setting the FieldValue).

PHP4 including file during session

I am trying to put second language on my webpage. I decided to use different files for different languages told apart by path - language/pl/projects.ln contains Polish text, language/en/projects.ln - English. Those extensions are just to tell language files from other, the content is simple php:
$lang["desc"]["fabrics"]["title"] = "MATERIAŁY";
$lang["desc"]["fabrics"]["short_text"] = "Jakiś tam tekst na temat materiałów";
$lang["desc"]["services"]["title"] = "USŁUGI";
$lang["desc"]["services"]["short_text"] = "Jakiś tam tekst na temat usłóg";
And then on the index page I use it like so:
session_start();
if (isset($_SESSION["lang"])) {
$language = $_SESSION["lang"];
} else {
$language = "pl";
}
include_once("language/$language/projects.ln");
print $lang["desc"]["fabrics"]["title"];
The problem is that if the session variable is not set everything works fine and array item content is displayed but once I change and set $_SESSION["lang"] nothing is displayed. I tested if the include itself works as it should by putting print "sth"; at the beginning of projects.ln file and that works all right both with $_SESSION["lang"] set and unset.
Please help.
Can you test the return value of session_start() - if it's false, it failed to start the session.
Is it being called before you output anything to the browser? If headers were already sent and your error_reporting level is too low, you won't even see the error message.
Stupid, but - do you set value of $_SESSION['lang'] to valid value like "en"? Does the English translation load correctly when you use it as default value in else block instead of "pl"?
"Jakiś tam tekst na temat usłóg" -> "usług" :)
Can you tell us what does this one output:
if(session_start()) {
echo SID, '<br/>';
if(isset($_SESSION['lang'])) {
echo 'lang = "',$_SESSION['lang'], '"';
}
}
Session starts fine and accidentally I managed to fix it.
I renamed $_SESSION['lang'] to $_SESSION['curr_lang'] and it now works allright. It seams like it didn't like the array and session variable having the same name (?).

Resources