Presentation is loading. Please wait.

Presentation is loading. Please wait.

©Computer Resource Team, Inc. 1998. All Rights Reserved. 1 Eliminating Tedious Work for the Oracle Web Developer By David Oranchak Computer Resource Team,

Similar presentations


Presentation on theme: "©Computer Resource Team, Inc. 1998. All Rights Reserved. 1 Eliminating Tedious Work for the Oracle Web Developer By David Oranchak Computer Resource Team,"— Presentation transcript:

1 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 1 Eliminating Tedious Work for the Oracle Web Developer By David Oranchak Computer Resource Team, Inc. November 8, 1998 Email: doranchak@crtnet.com Phone: (540) 552-3100 extension 210

2 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 2 Goals Free stuff for your tool box Examine PL/SQL coding habits and common pitfalls PL/SQL encapsulation of client-side JavaScript data validation The Power of DBMS_SQL for quick deployment Alternatives to expensive development packages

3 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 3 TOAD What is it? Tool for Oracle Application Developers From the webpage: http://www.toadsoft.com Written by an Oracle application developer for Oracle application developers, TOAD is a Win95/NT tool for Oracle developers. TOAD will help develop queries, perform Explain Plan, browse and edit database objects, edit table data, edit and debug PL/Sql. TOAD also has configurable syntax highlighting, direct OCI access to Oracle, optimization statistics, shared pool recall, AutoTrace, and reports. TOAD is both free and fully usable on your first download.

4 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 4 TOAD Benefits Completely free and un-crippled Easy to use Provides an extremely large amount of database-related information in an easy-to-digest manner. Feature-rich Routinely updated, and new features are typically requested by other developers. Eliminates tedious work!

5 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 5 Tips and Tricks How to help guard your application code against changes in database design Removing duplicate database information in applications Coding style HTML style encapsulation Encapsulation of client-side JavaScript data validation

6 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 6 Anchored Declarations Operator used to assign the datatype of a database element dynamically to a PL/SQL variable Allows for flexibility in PL/SQL applications whenever the database is changed Example syntax: –f_employee_id employees.id%TYPE; Prevents local variables from being mistyped.

7 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 7 Anchored Declarations Example: procedure parameters (old way) PROCEDURE update_ssn ( f_employee_id NUMBER, f_new_ssn VARCHAR2, f_dob VARCHAR2 )

8 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 8 Anchored Declarations Example: procedure parameters (new way) PROCEDURE update_ssn ( f_employee_id employees.id%TYPE, f_new_ssn employees.ssn%TYPE, f_dob employees.dob%TYPE )

9 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 9 Anchored Declarations Moral of the story: –Push database-specific knowledge back to the database. –Anchored declarations allow you to push datatype information back to the database.

10 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 10 Coding Style One of the biggest PL/SQL headaches: finding mismatched HTML tags Structured code helps to streamline the debugging process

11 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 11 Coding Style Old style: htp.p(‘ ’); htp.p(‘ Name ’); htp.p(‘ Social Security Number ’); htp.p(‘ ’); htp.p(‘ <tr valign=top’); htp.p(‘ Jello Biafra ’); htp.p(‘ 123-45-6789 ’); htp.p(‘ ’);

12 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 12 New style: htp.tableOpen ( '0', cattributes => 'CELLPADDING=3 CELLSPACING=0' ); htp.tableRowOpen ( cvalign => 'TOP' ); htp.tableData('Name'); htp.tableData('Social Security Number'); htp.tableRowClose; htp.tableRowOpen ( cvalign => 'TOP' ); htp.tableData('Jello Biafra'); htp.tableData('123-45-6789'); htp.tableRowClose; htp.tableClose;

13 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 13 New style: unpaired tags in HTP: htp.tableRowOpen ( cvalign => 'TOP' ); htp.p(' '); htp.italic('Name'); htp.p('</B'); htp.p(' '); htp.italic('Social Security Number'); htp.p('</B'); htp.p(' '); htp.tableRowClose;

14 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 14 New style: unpaired tags in HTP: htp.tableRowOpen ( cvalign => 'TOP' ); htp.tableData ( htf.bold ( htf.italic('Name') ) ); htp.tableData ( htf.bold ( htf.italic('Social Security Number') ) ); htp.tableRowClose;

15 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 15 Coding Style New style (with concatenated nesting): htp.tableData ( htf.fontOpen ( quidlib_constants.g_main_table_header_text ) || htf.bold('Report Name:') || htf.fontClose, cattributes => 'BGCOLOR="#000000' );

16 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 16 HTML Style Encapsulate HTML style information in: –PL/SQL packages –Database tables –HTML v4.0 Cascading Style Sheets Benefits: –Provides consistency throughout applications –Makes it easier to make global changes to the appearance of the web application –Provides flexible mechanism to add web-based maintenance capabilities to the application itself

17 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 17 HTML Style Example of PL/SQL encapsulation of HTML style information: create or replace package emp_constants as g_body_bgcolor constant char(7) := '#FFFFFF'; g_body_text constant char(7) := '#000000'; g_main_table_header_bgcolor constant char(7) := '#0099CC'; g_main_table_header_text constant char(7) := '#FFFFFF'; g_sub_table_header_bgcolor constant char(7) := '#003366'; g_sub_table_header_text constant char(7) := '#FFFFFF'; end; Usage: htp.fontOpen(emp_constants.g_main_table_header_text); htp.bold(‘Employee Name:’); htp.fontClose;

18 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 18 Client-Side JavaScript Data Validation Used to process form input before data is sent to the database. Allows client machines to do some of the work involved with maintaining data integrity Streamlines data flow and business rules

19 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 19 Client-Side JavaScript Data Validation Example: htp.p (' function verifyNotNull() { val_check = document.edit_form.employee_name.value; if (val_check == "") { alert("The name of the employee must be entered."); return false; } ');

20 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 20 Client-Side JavaScript Data Validation Usage: htp.formSubmit ( cvalue => 'Update', cattributes => 'onClick = "return verifyNotEmpty()"' );

21 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 21 Client-Side JavaScript Data Validation Problems: –Tedious to repeatedly write validation routines for fields which cannot be null fields that can only contain numerical data –Also, how do we handle maximum data sizes? Using hard-coded maxlength parameter in htp.formInput duplicates information already in the database. Solution: –Build JavaScript library that can generate JavaScript code on the fly, dependent on database information.

22 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 22 Encapsulated Client-Side JavaScript Data Validation Approach: –Use DBMS_SQL (discussed later) to fetch information from data dictionary view user_tab_columns based on the tables and columns you want information for. –For a given table and column, find its entry in the view, then pull out relevent info, such as data_type, data_length, data_precision, and nullable. –Use this info to drive generation of JavaScript functions.

23 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 23 Encapsulated Client-Side JavaScript Data Validation Contents of USER_TAB_COLUMNS for EMPLOYEES table: TABLE_NAME COLUMN_NAME DATA_TYPE DATA_LENGTH DATA_PRECISION NULLABLE ----------- ------------ ---------- ------------ -------------- -------- EMPLOYEES FIRST_NAME VARCHAR2 20 N EMPLOYEES LAST_NAME VARCHAR2 20 N EMPLOYEES SSN VARCHAR2 9 Y EMPLOYEES DOB DATE 7 Y EMPLOYEES HEIGHT NUMBER 22 5 Y

24 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 24 The Power of DBMS_SQL What is DBMS_SQL? –Standard PL/SQL package for creating, executing, and manipulating arbitrary queries. Why use DBMS_SQL? –Provides ability to define and process PL/SQL cursors that are based on dynamic SQL queries instead of static, hard-coded ones. –Provides the means to push more tedious, repetitive work back to the database and away from applications.

25 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 25 The Power of DBMS_SQL How does it work?

26 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 26 QUIDLIB What is it? –Quick Deployment Library –PL/SQL package I made to demonstrate the usefulness of DBMS_SQL, JavaScript encapsulation, and other ideas in this presentation –Web-based form/report generator that can make master/detail reports and maintenance forms for any database tables. –Shows a basic homemade implementation of generic maintenance and reporting

27 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 27 Alternatives WebDB –Oracle’s tool for quick deployment of web applications. –Provides robust mechanism to create database reports and forms. –Similar to Developer 2000, but it is completely web- based. –Currently available in Beta version; full release not expected until (sometime) 1999.

28 ©Computer Resource Team, Inc. 1998. All Rights Reserved. 28 Conclusion Free tools are out there to help you save time Pushing as much as you can back to the database makes a database and its applications more flexible and reusable Web-based deployment is a rapidly-changing environment. Problems can be prevented and time can be saved by making application behaviors as generic as possible.


Download ppt "©Computer Resource Team, Inc. 1998. All Rights Reserved. 1 Eliminating Tedious Work for the Oracle Web Developer By David Oranchak Computer Resource Team,"

Similar presentations


Ads by Google