Tactics to Tackle APEX Bugs Karen Cannell kcannell@integratc.com
About Me (Speaker Qualifications) Karen Cannell ~ Principal Analyzed, designed developed, converted, upgraded, enhanced and otherwise worked on database applications for 22+ years, focused on Oracle since 1994. Currently migrating business processes to web-based systems, leveraging the Oracle10g and 10g suite of tools. Lately APEX, Discoverer. VOLUNTEER for IOUG, ODTUG, Oracle Magazine. ODTUG Technical Journal Editor Volunteer to author SELECT and ODTUG Journal Articles!! Using APEX since the HTMLDB beginning http://www.tunahuntress.com Software Page http://www.integratc.com/whitepapers.asp
About You (Audience Background) New to APEX? APEX Experience? Previous Tools? Debug Fun? Debug Nightmares?
Session Objectives Review APEX Debug Options APEX-supplied IDE s 3rd Party Web Development Strategy & Tactics Mindset Application Tools Demonstrate Remote PL/SQL Debug Overview Web Development Tools Tackle some APEX Problems Reinforce APEX best practices
APEX Debug?.. Where to Start? APEX is a blend of technologies How to Debug? PL/SQL Debugger? DMBS_OUTPUT? View Source? Java-what Console? The Old Tools Just Don t Fit!
APEX Debugging Where to Start? What Happens Where? What Language? What Level? Which Process? Which Template? Page? Region? Item? Function? Web Service? We need new Tactics for debugging!
APEX Tactics for Debugging Tactics tac-tics [tāk'tĭks ] (singular tak-tic) noun Definition: 1. a. (used with a sing. verb) The military science that that deals with with securing objectives set by set strategy by strategy b. (used b. (used with a with pl. verb) a pl. verb) Maneuvers Maneuvers used against used against an enemy an enemy
Debug Strategy Know Yourself Know your Enemy Your Application Know your Weapons AvailableTools Follow the Battle Plan Follow a Sound Plan Don t Stay Lose Sane It!
Know Yourself Guidelines for Sanity: You Know What You Know If the Code Did Not Change, It s Not the Code The Computer Does Exactly What You Tell It To Exactly. Remember - You Know Stuff
Common Sense When Do We Make Mistakes? Overtired Under Pressure Developer Diet Lone Wolf When Do We Debug? Overtired Under Pressure Developer Diet Lone Wolf
Common Sense Take a Break 30 minute Rule Set Reasonable Expectations, Timeframes Eat Food (Red Bull is Not Food) Ask for Help It s OK to Ask for Help Coding Therapy for Developers, Steven Feuerstein, 2009
Change of Thought, Toolset SQL and PL/SQL Essential APEX Flow and Page Rendering Essential HTML Essential for Templates, Themes CSS Essential for Templates, Themes JavaScript, AJAX, Web Services Essential as you Enhance your Apps Expand Your Skills as your APEX Development Expands
Know your Application Know Your Application Build with Best Practices Coding Standards Modularize Separate Business Logic from Presentation Use Packages Comment All Code APEX included Backup Regularly Export Regularly APEX Essentials or similar
Know Your Tools APEX-Supplied PL/SQL IDE - SQL Developer 3 rd Party Web Development Tools CSS Editors
APEX-Supplied Debug Tools Syntax Session State Debug Mode Builder View Events, References Activity Reports Developer Activity By Change, Weighted Page Performance Export As Of Others #TIMING#, Instrumentation, &p_trace see APEX Debug Options, Cannell, 2008
Know Your Tools APEX Syntax f?p Syntax Application : Page : Session : Request : Debug: Clear Cache : Item Names: Item Values : Printer Friendly All Programmers Smartly Request Double Cash In Virtual Programs
Know Your Tools APEX-Supplied APEX Debug Tools Dev Toolbar View Session State Activity Reports Toggle Debug Mode
Know Your Tools APEX-Supplied Session State
Know Your Tools APEX-Supplied Debug Mode On
Know Your Tools APEX-Supplied wwv_flow.debug Set you own debug messages wwv_flow.debug( Your message here ); apex_application.debug( Your message here ); wwv_flow.debug( <span style= color:red; > <br>your message here <br></span> );
Know Your Tools APEX-Supplied Page - View Select List
Know Your Tools APEX-Supplied Page View Select List - Events
Know Your Tools APEX-Supplied Page View Select List - Referenced Referenced Components
Know Your Tools APEX-Supplied Activity Reports Most are Informational Page Views, Caching, Session Developer Activity Clues as to What Changed Recent Changes - - > Hint to Recent Errors
Know Your Tools APEX-Supplied Activity Reports
Know Your Tools APEX-Supplied Developer Activity by Application Change
Know Your Tools APEX-Supplied Activity Weighted Page Performance Where is time spent Clue to performance issues
Know Your Tools APEX-Supplied Validate PL/SQL in APEX Database Object Dependencies
Know Your Tools APEX-Supplied Application Reports Shared Components Database Object Dependencies PL/SQL Process Validation App Reports Shared Components Database Object Dependencies Compute Dependencies
Know Your Tools APEX-Supplied Parsing Errors == PL/SQL to fix
Parsing Errors
Know Your Tools APEX-Supplied DBMS_APPLICATION_INFO APEX Sets Values: Module APEX:APPLICATION <App Id> Client Info User Identifier User: Session Id Action PAGE <Page>
Know Your Tools APEX-Supplied DBMS_APPLICATION_INFO Retrieve Info: V$SQL SELECT sql_text, action, module, program_id, program_line# FROM v$sql WHERE module LIKE '%APEX%'
Know Your Tools APEX-Supplied DBMS_APPLICATION_INFO Retrieve Info: V$SESSION ( 10.2.0.2 and higher) SELECT plsql_entry_object_id, FROM plsql_entry_subprogram_id, plsql_object_id, plsql_subprogram_id, module, action v$session WHERE module = 'APEX:APPLICATION 1103'
Know Your Tools APEX-Supplied Utilities Database Monitor Top SQL
Know Your Tools APEX-Supplied #TIMING# in Region Footer Add #TIMING# to Region Footer (doesn t work in Header) Displays CPU Time in Region Footer Gives clues as to where performance issue may be
Know Your Tools APEX-Supplied #TIMING# Output Timing output
Know Your Tools - IDE SQL Developer (or other PL/SQL IDE) SQL and PL/SQL Validation, Tuning Reports Remote Debug
Know Your Tools IDE ex: SQL Developer PL/SQL Debug and Performance Build & Tune Outside First Tune SQL, PL/SQL Outside of APEX Same Principles Apply Validate PL/SQL Processes in APEX Compute Dependencies Modularize Use Bind Variables
Know Your Tools IDE ex: SQL Developer SQL Developer Reports APEX Reports Supplied - Informational User-Defined Reports Build Your Own Custom Most Power Here
Know Your Tools SQL Developer SQL Developer Remote Debug Code Must be a Stored Procedure DB Privileges DEBUG CONNECT SESSION DEBUG ANY PROCEDURE Start Debug Listener in SQL Developer Connect APEX app to SQL Dev via DBMS_DEBUG_JDWP.CONNECT_TCP Run App Debug in SQL Developer
Know Your Tools SQL Developer Not Remote-Debug-able DECLARE v_status PLS_INTEGER := 0; v_fmp trip_charge.fmp%type; v_date_land DATE; BEGIN SELECT fmp, date_land INTO v_fmp, v_date_land FROM trip_and_charge WHERE das_id = :P6_DAS_ID; wwv_flow.debug( '<span class="t16error"> ' v_fmp ' ' TO_CHAR( v_date_land,'dd-mon-yyyy') ' After COMMIT </span>'); AMS_EDIT.CHARGE_SUITE_ONE( :P6_DAS_ID, :P6_PERMIT_NBR, v_fmp, v_date_land, v_status); wwv_flow.debug( '<span class="t16error"> After CHARGE_SUITE_ONE </span>'); EXCEPTION WHEN OTHERS THEN htp.p( DBMS_UTILITY.FORMAT_ERROR_BACKTRACE); END;
Know Your Tools SQL Developer Can Remote Debug IF :DEBUG = 'YES' THEN DBMS_DEBUG_JDWP.CONNECT_TCP( '127.0.0.1', 4000); END IF; AMS_EDIT.RUN_CHARGE_SUITE_ONE( :P6_DAS_ID, :P6_PERMIT_NBR); IF :DEBUG = 'YES' THEN DBMS_DEBUG_JDWP.DISCONNECT; END IF; Can Debug This in SQL Dev
Know Your Tools SQL Developer Steps for Remote Debug In SQL Dev, set Remote Debug ON for a session, entering DB host IP In app, add IF :DEBUG = 'YES' THEN DBMS_DEBUG_JDWP.CONNECT_TCP( '127.0.0.1', 4000); END IF; In app, after module add disconnect IF :DEBUG = 'YES' THEN DBMS_DEBUG_JDWP.DISCONNECT; END IF;
Know Your Tools 3 rd Party Web Development Tools Web Developer Firebug Live HTTP Header Yslow Others abound! Safari 4 - WebKit IE 8
Know Your Tools Web Development Tools Web Developer Firefox Add-In Free Download https://addons.mozilla.org/en-us/firefox/addon/60
Know Your Tools Web Development Tools Web Developer Tool Bar
Web Developer Display Element Information
Know Your Tools Web Development Tools Firebug Another Firefox Add-In Download from https://addons.mozilla.org/en-us/firefox/addon/1843
Know Your Tools Web Development Tools Firebug Console HTML CSS Script (JavaScript) DOM Firebug Lite JavaScript include for non- Firefox browsers http://www.getfirebug.com/ for more information
Know Your Tools Web Development Tools Firebug JavaScript Debugger JavaScript Debug Interface
Safari 4 Web Inspector / WebKit Safari 4 Developer Tools http://www.apple.com/safari/whatsnew.html#developer WebKit http://webkit.org/
Have a Plan Triage Apply Correct Tool & Tactics Analyze Repeat
Follow a Plan - Triage Triage Think. Session State Debug Mode Activity Reports View Events All from Dev Toolbar Classify ~ Choose Tactics
Follow a Plan Classify the Issue Classify Issue SQL or PL/SQL APEX Flow HTML or CSS JavaScript, AJAX Others: Timing No Clue
Follow a Plan Apply Tactics Tactics for SQL and PL/SQL Issues Validate (again) Outside of APEX Tune (again) Outside of APEX because you have modularized, use bind variables, and have already tuned this is easy! Validate Session State & Timing Remote Debug
Follow a Plan Apply Tactics Tactics for APEX Flow Issues Debug Mode What Fires in What Order With What Values View Events Confirm Order of Events is What it Should Be Validate All Conditions Turn Conditions On/Off to Find the Offender
Follow a Plan Apply Tactics Tactics for HTML, CSS Issues Web Developer (Firebug, or similar) Show Element Information View Tables Edit CSS Use the Utilities! CSS Editor Build and Validate Stylesheets Test in All Browsers! Adjust tool to browser
Follow a Plan Apply Tactics Tactics for JavaScript, AJAX Firebug JavaScript Tools JavaScript Console Test and Validate in Console First Validate in Console Again Venkman JavaScript Debugger Safari 4 IE 8 Others?
Demonstrations Simple Error Misleading Message Case for Remote Debug MRU Error One Flavor View of Web Developer, Firebug
Simple Error Message 601 p28
Debug Mode On This Column No Longer Exists!
Lessons Learned Table Changed Column No Longer Exists All Pages Were Not Updated All Pages Were Not Tested! APEX Essentials was not run! Know Your Application Know Your Tools Follow Standards ~ No Shortcuts!
Don t Believe the Message 601 Add Trip p50 err on way
Turn Debug Mode On
Lesson Learned: The Actual Error was on a Different Item than it appeared in the displayed error message The error was a dumb mistake the developer may not have made if Don t Take Everything at Face Value Know Your Application, inside and out! Stay Sane Be Thorough
Report Error - string buffer too small
Report Error String buffer too small Underlying Data Changed Caused Error in app
Lessons Learned Report Error When it Rains it Pours Expect the Unexpected When you can least afford it. Know Your Application... and what you do to it. Know Your Data and when it changes. Know Your Tool and it s Limitations.
Case for Remote Debug App 602, p50 Write Remote Debug-able Code: Packages, Procedures, Functions vs. Code in the Builder
Lesson Learned Remote Debug After all is validated Outside of APEX When there is no other way For Focused Cases Only Not Always Clean Exit 605 p50 add trip or del trip
MRU Error One Incarnation Current version of data in database has changed since user initiated update process...
MRU Error Error in mru internal routine: ORA-20001: no data found in tabular form Know Your App Know Your Tools Save Often Go To The Forum! Lease exch status
MRU Error - Suggestions Table Name and PK Must Be Correct PK Must be Posted Back with Form: Hidden Display Only, Saves Session State Don t Change Query After Building Beware those Last Minute Improvements
HTML and CSS Errors Know Your Tool Web Developer, Firebug, etc. Features CSS Edit Table Levels Many Many Utilities! Test In All Browsers! Firebug Lite for IE < 8
JavaScript Debug Firebug Safari Web Inspector Other JavaScript Console Test and Refine in JS Console first Use Tool to Find, Address Errors
Firebug JavaScript Debugger JavaScript Debug Interface
Forum Etiquette Know Your Application Know Your Problem Search and Read FIRST Then and only then Post Clearly State Problem. Ask a Question Be Polite.
Tactics for Debug - Recap Know Yourself Know your Your Application Know Your Available Tools Follow a Sound Plan Don t Stay Lose Sane It!
Tactics to Tackle - Recap THINK Remember You Know Stuff Triage Tackle Bug with the Right Tactic
Resources APEX Debug Options, Cannell, 2008 APEX Cheat Sheet, Cannell, 2008 http://www.tunahuntress.com Software Page http://www.integratc.com/whitepapers.asp Coding Therapy, Feuerstein, 2009 The APEX OTN Forum - http://forums.oracle.com/forums/forum.jspa?forumid=137. SQL Developer - Home Page on OTN http://www.oracle.com/technology/products/database/sql_developer/index.html Web Developer http://chrispederick.com/work/web-developer/. Firebug Safari http://www.getfirebug.com/. http://www.apple.com/safari/
Share Your Knowledge! Call for Articles/Reviewers ODTUG Journal IOUG SELECT Journal Editor, ODTUG Technical Journal kcannell@odtug.com
ODTUG Kaleidoscope 2010 June 27 July 1 Washington, DC
Questions? Tactics to Tackle APEX Bugs Please fill out the evaluations! Karen Cannell kcannell@integratc.com http://www.integratc.com
Thank You ~ Tactics to Tackle APEX Bugs Please fill out the evaluations! Karen Cannell kcannell@integratc.com http://www.tunahuntress.com (Software page)
Karen Cannell APEX Papers http://www.tunahuntress.com Software Page or http://www.integratc.com/whitepapers.asp