2011 06 Millinger Dynamic Duo
2011 06 Millinger Dynamic Duo
Dynamic Duo
Josh Millinger
Niantic Systems
June 7, 2011
[email protected]
Speaker Qualifications
[email protected]
Niantic Systems
[email protected]
Agenda
[email protected]
Agenda
Javascript Overview
Dynamic Action Overview
Demonstration
[email protected]
What is Dynamic SQL?
[email protected]
What is Dynamic SQL?
You can use dynamic SQL to create applications that execute dynamic queries,
whose full text is not known until runtime. Many types of applications need to
use dynamic queries, including:
Applications that allow users to input or choose query search or sorting criteria at runtime
Applications that allow users to input or choose optimizer hints at run time
Applications that query a database where the data definitions of tables are constantly changing
Applications that query a database where new tables are created often
[email protected]
Static vs. Dynamic
Static:
select patient, service_date, exam from exams
In this case the SQL statement is well known as design time
Dynamic:
declare
l_sql varchar2(1000);
begin
l_sql := select || :PX_COLNAME|| from exams;
return l_sql;
end;
[email protected]
When do I need to use Dynamic SQL
declare
l_sql varchar2(10000);
begin
l_sql := select col1, col2 from jobs where 1=1 ;
..filters here
l_sql := l_sql || order by || v(P1_ORDERBY) ;
return l_sql;
end;
[email protected]
When do I need to use Dynamic SQL - Example
[email protected]
Region Type Definition
[email protected]
Where do I create Dynamic SQL?
return my_pkg.get_page25_query(:P25_ITEMNAME);
[email protected]
Apex Parsing
Warning: You might get error if column number greater than the number of
columns in query is higher on Report Attributes Page
[email protected]
Dynamic SQL and Charts
[email protected]
How to debug
declare
l_sql varchar2(1000);
begin
l_sql := select || :PX_COLNAME|| from exams;
apex_application.debug(My query is : ||l_sql);
return l_sql;
end;
[email protected]
Using bind variables in Dynamic SQL
When generating in database still use the :BINDVAR syntax
This will allow the optimizer to reuse execution plan
declare
l_sql varchar2(1000);
l_col varchar2(100);
begin
if v(P1_TEST) = 1 then l_col := mycol1 ; else l_col := mycol2; end if;
l_sql := select || v(PX_COLNAME)|| from exams where id = :P1_ID ;
apex_application.debug(My query is : ||l_sql);
return l_sql;
end;
[email protected]
Using bind variables in Dynamic SQL
Prevent SQL Injection Attacks
Take a block of code that generates a query
declare
q varchar2(4000);
begin
q := select *
from tasks
where assigned = :APP_USER ';
[email protected]
Using bind variables in Dynamic SQL
When a user provides email for P1_SEARCH our
query will be:
select *
from tasks
where assigned=:app_user
and category = email
[email protected]
Using bind variables in Dynamic SQL
select *
from tasks
where .
and category = email or
a = a
[email protected]
Interactive Reports and Collections
[email protected]
Interactive Reports and Collections
1. Create collection when the page renders
declare
l_sql varchar2(1000);
begin
if apex_collection.collection_exists(P25_ROWS)
then
apex_collection.delete_collection(P25_ROWS);
end if;
[email protected]
Dynamic Sql - Conclusion
Dynamic SQL
Is useful when a query not known at develop time
Unknown table
Unknown columns
Unknowns sorting
Can be used with Interactive Reports
By using collection or other row collecting mechanism
Can be used with Reports, Charts, and LOVs
[email protected]
Apex and Javascript
[email protected]
Apex and Javascript
[email protected]
Apex and Javascript
[email protected]
Dynamic Actions
[email protected]
Dynamic Actions
[email protected]
Dynamic Actions - Standard
Selection Type: Item, Region, jQuery or DOM Object
Can be conditionally executed
[email protected]
Dynamic Actions - Standard
Action can Hide/Show or Enable/Disable page elements
Can create opposite False Action
If Dynamic Action shows item when the condition is
TRUE, then this created DA that hides item when FALSE
[email protected]
Dynamic Actions - Standard
Select what elements are affected by TRUE/FALSE action
[email protected]
Dynamic Actions - Advanced
Event Based
Change of Value
Losing Focus
Mouse entering/leaving
Page load/unload
Scroll
Double Click
Key Up/Down
[email protected]
Dynamic Actions - Advanced
Declare what action to take
Clear
Hide/Show
Set Value
Execute JS or PL/SQL
Add remove classes
[email protected]
Dynamic Actions Code Generation
Code is automatically generated for the page
Can be seen when looking at page source
Located at bottom of page
[email protected]
Dynamic Actions Conclusion
Javascript is integral to Apex
Previous to 4.0, manual coding was necessary
Dynamic Actions allow for easy generation without coding
Get opposite action for free
Can extend with custom Javascript, PL/SQL, jQuery
Makes everyone a Javascript Developer!
[email protected]
Questions?
Topics for Next Time?
[email protected]
Thank You!
Josh Millinger
[email protected]
202.642.6845