Modern PL/SQL Code Checking and Dependency Analysis



Similar documents
How to Improve Database Connectivity With the Data Tools Platform. John Graham (Sybase Data Tooling) Brian Payton (IBM Information Management)

Oracle 10g PL/SQL Training

3.GETTING STARTED WITH ORACLE8i

Secure Test Data Management with ORACLE Data Masking

Oracle Database: SQL and PL/SQL Fundamentals

D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:

SQL Databases Course. by Applied Technology Research Center. This course provides training for MySQL, Oracle, SQL Server and PostgreSQL databases.

Oracle Database 12c: Introduction to SQL Ed 1.1

Oracle Database: SQL and PL/SQL Fundamentals NEW

Palo Open Source BI Suite

Oracle Audit in a Nutshell - Database Audit but how?

Oracle SQL. Course Summary. Duration. Objectives

Oracle Database 10g: Introduction to SQL

Oracle Database 10g: Program with PL/SQL

<Insert Picture Here> Oracle SQL Developer 3.0: Overview and New Features

Using TimesTen between your Application and Oracle. between your Application and Oracle. DOAG Conference 2011

Oracle Database: SQL and PL/SQL Fundamentals

Creating PL/SQL Blocks. Copyright 2007, Oracle. All rights reserved.

Top 10 Oracle SQL Developer Tips and Tricks

Oracle Database: Introduction to SQL

Application Development With Data Studio

Oracle Database: Introduction to SQL

BASEL BERN BRUGG LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MÜNCHEN STUTTGART WIEN

Using SQL Developer. Copyright 2008, Oracle. All rights reserved.

Oracle Database: Program with PL/SQL

SOUG-SIG Data Replication With Oracle GoldenGate Looking Behind The Scenes Robert Bialek Principal Consultant Partner

Database Programming with PL/SQL: Learning Objectives

MySQL for Beginners Ed 3

Geodatabase Programming with SQL

Continuous Integration Part 2

Managing Objects with Data Dictionary Views. Copyright 2006, Oracle. All rights reserved.

IBM DB2 XML support. How to Configure the IBM DB2 Support in oxygen

Oracle 11g PL/SQL training

A Migration Methodology of Transferring Database Structures and Data

Oracle SQL Developer for Database Developers. An Oracle White Paper June 2007

CHAPTER 5 INTELLIGENT TECHNIQUES TO PREVENT SQL INJECTION ATTACKS

Optimizing the Performance of the Oracle BI Applications using Oracle Datawarehousing Features and Oracle DAC

Database 10g Edition: All possible 10g features, either bundled or available at additional cost.

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/-

Oracle SQL Developer for Database Developers. An Oracle White Paper September 2008

Instant SQL Programming

Triggers & Packages. {INSERT [OR] UPDATE [OR] DELETE}: This specifies the DML operation.

Business Systems Analysis Certificate Program. Millennium Communications & Training Inc. 2013, All rights reserved

Using ORACLE in the CSLab

ORACLE 9I / 10G / 11G / PL/SQL COURSE CONTENT

Course -Oracle 10g SQL (Exam Code IZ0-047) Session number Module Topics 1 Retrieving Data Using the SQL SELECT Statement

SQL Server Database Coding Standards and Guidelines

Oracle Database: Introduction to SQL

PL/SQL Programming Workbook

OLH: Oracle Loader for Hadoop OSCH: Oracle SQL Connector for Hadoop Distributed File System (HDFS)

Oracle Database: SQL and PL/SQL Fundamentals NEW

What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World

How To Ensure Data Security On Anor

SQL Server An Overview

Fine Grained Auditing In Oracle 10G

1 Stored Procedures in PL/SQL 2 PL/SQL. 2.1 Variables. 2.2 PL/SQL Program Blocks

SQL. Short introduction

Big Data. Marriage of RDBMS-DWH and Hadoop & Co. Author: Jan Ott Trivadis AG Trivadis. Big Data - Marriage of RDBMS-DWH and Hadoop & Co.

Automate Your BI Administration to Save Millions with Command Manager and System Manager

php tek 2006 in Orlando Florida Lukas Kahwe Smith

CUIT with Visual Studio and TFS

5. CHANGING STRUCTURE AND DATA

DBMS / Business Intelligence, SQL Server

Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff

Oracle Database: Develop PL/SQL Program Units

Oracle Database 11g: Program with PL/SQL

SQL Server 2008 Core Skills. Gary Young 2011

Part A: Data Definition Language (DDL) Schema and Catalog CREAT TABLE. Referential Triggered Actions. CSC 742 Database Management Systems

Oracle Database 10g Express

Oracle Service Bus vs. Oracle Enterprise Service Bus vs. BPEL wann soll welche Komponente eingesetzt werden?

PL/SQL Developer 7.1 User s Guide. March 2007

Oracle Application Express Workshop

Introducing Oracle s SQL Developer

Oracle Data Miner (Extension of SQL Developer 4.0)

Oracle Database: Program with PL/SQL

Database Query 1: SQL Basics

Maintaining Stored Procedures in Database Application

Generating XML from Relational Tables using ORACLE. by Selim Mimaroglu Supervisor: Betty O NeilO

agileworkflow Manual 1. agileworkflow 2. The repository 1 of 29 Contents Definition

Oracle Database: Program with PL/SQL

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

Developing SQL and PL/SQL with JDeveloper

A Brief Introduction to MySQL

Testing of the data access layer and the database itself

Netezza Workbench Documentation

Oracle Enterprise Manager

Discovering SQL. Wiley Publishing, Inc. A HANDS-ON GUIDE FOR BEGINNERS. Alex Kriegel WILEY

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Oracle8/ SQLJ Programming

An Oracle White Paper June Migrating Applications and Databases with Oracle Database 12c

<Insert Picture Here>

An Introduction to PL/SQL. Mehdi Azarmi

ORACLE DATABASE 11G: COMPLETE

PL/SQL Overview. Basic Structure and Syntax of PL/SQL

Textual Modeling Languages

Oracle Database: Program with PL/SQL

An Eclipse Plug-In for Visualizing Java Code Dependencies on Relational Databases

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

WELCOME. Where and When should I use the Oracle Service Bus (OSB) Guido Schmutz. UKOUG Conference

Transcription:

Modern PL/SQL Code Checking and Dependency Analysis Philipp Salvisberg Senior Principal Consultant BASEL BERN BRUGG LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MUNICH STUTTGART VIENNA 1

About Me With Trivadis since April 2000 Senior Principal Consultant, Partner Member of the Board of Directors philipp.salvisberg@trivadis.com www.salvis.com/blog Member of the Main focus on database centric development with Oracle DB Application Development Business Intelligence Application Performance Management Over 20 years experience in using Oracle products 2

AGENDA 1. Introduction 2. Grammar 3. Code Checking 4. Dependency Analysis 5. Core Messages 3

PL/SQL & SQL Coding Guidelines Openly available since August 2009 Download for free from www.trivadis.com 4

Coding Guideline #26 26. Always specify the target columns when executing an insert command. Reason Data structures often change. Having the target columns in your insert statements will lead to changeresistant code. Examples -- Bad INSERT INTO messages VALUES (l_mess_no, l_mess_typ, l_mess_text); -- Good INSERT INTO messages (mess_no, mess_typ, mess_text) VALUES (l_mess_no, l_mess_typ, l_mess_text); 5

PL/SQL Assessment Code Analysis based on Trivadis SQL & PL/SQL Guidelines Cookbook using e.g. Quest CodeXpert SQL Scripts using PL/Scope SQL Scripts Manual checks Interviews Final Report Results Recommendations Fixed Price Offering 6

Approach & Considerations Requirements Parser to process SQL*Plus files Code checking framework Options SQL & PL/SQL Parser - Oracle JDeveloper Extensions (oracle.javatools.parser.plsql.plsqlparser) - Free ANTLR based grammars (e.g. http://www.antlr3.org/grammar/list.html) - General SQL Parser Sonar-Plugin - PL/SQL Plug-In with standard existing rules and ability for extension Eclipse Xtext - Framework for development of textual domain specific languages (DSL) - Uses ANTLR behind the scenes - Used successfully to generate database access layer for bitemporal tables 9

Features Eclipse-based Editors Validation and Quick Fixes Syntax Coloring Code Completion Outline View Code Formatting Bracket Matching Integration Eclipse Modeling Framework (e.g. for graphical editors) Eclipse Workbench (e.g. for list of problems/warnings) Export into self-executing JAR (e.g. to build a command-line utility) 10

AGENDA 1. Introduction 2. Grammar 3. Code Checking 4. Dependency Analysis 5. Core Messages 11

SQL*Plus File Content of a SQL*Plus File SQL*Plus Command e.g. set Using SQL e.g. copy Using PL/SQL e.g. execute SQL Command e.g. select Data Definition Language (DDL) e.g. create view Data Manipulation Language (DML) e.g. update Using PL/SQL e.g. create function Using Java e.g. create java source SQL Command e.g. select SQL Command Transaction Control Statements e.g. commit Session Control Statements e.g. alter session System Control Statements e.g. alter system PL/SQL e.g. anonymous PL/SQL block SQL Command e.g. select 12

Complete Single Grammar Approach One, huge grammar (SQL*Plus, PL/SQL, SQL, Java) Conflicting keywords between SQL*PLUS and SQL, PL/SQL "describe" is a SQL*Plus keyword, but not a reserved word in SQL (valid for table etc.) Abbreviatory notation of SQL*Plus, e.g. - run command ( r ru run ) - accept command (a ac acc acce accep accept) Grammar for a lot of complex commands which are not in focus for any analysis (e.g. CREATE DATABASE) Xtext and ANTLR cannot handle such a huge grammar Maximum size of 64 KB for Java classes and methods Maximum number of 65535 fields for Java classes 13

Reduced Single Grammar Approach One grammar, still huge Skeleton definition for less interesting commands Swallow everything between start and end keywords TtitleCommand: {TtitleCommand} K_TTITLE3 text=generictext? =>SqlPlusCmdEnd; Necessary to avoid parse errors which would lead to incomplete analysis Complete definition of more interesting commands (e.g. SELECT) Not feasible before Xtext 2.0.1 because of generator limitations Still conflicting keywords between SQL*PLUS and SQL, PL/SQL 14

Multiple Grammar Approach Skeleton grammar for SQL*Plus files (SQL*Plus, SQL, PL/SQL, Java) Complete grammar for PL/SQL and more interesting SQL commands (e.g. CREATE VIEW) Chaining grammars Parse SQL*Plus files using SQL*Plus parser Parse PL/SQL and chosen SQL commands in SQL*Plus validator Apply guidelines checks in PL/SQL validator No conflicting keywords between SQL*PLUS and SQL, PL/SQL 15

AGENDA 1. Introduction 2. Grammar 3. Code Checking 4. Dependency Analysis 5. Core Messages 16

Excerpt of Grammar for Insert Statement InsertStatement: InsertPlusHintsAndComments ( singletableinsert=singletableinsert multitableinsert=multitableinsert ) ; InsertPlusHintsAndComments returns InsertStatement hidden (WS): {InsertStatement} 'insert' (hints+=hintorcomment)* ; SingleTableInsert: intoclause=insertintoclause ( (valuesclause=valuesclause returningclause=returningclause?) (subquery=selectstatement) ) errorloggingclause=errorloggingclause? ; InsertIntoClause: 'into' dmlexpressionclause=dmltableexpressionclause alias=sqlnameexpression? ('(' columns+=qualifiedsqlnameexpression (',' columns+=qualifiedsqlnameexpression)* ')')? ; ValuesClause: 'values' expression=expression ; 17

Validator for Guideline #26 @Check public void checkguideline26(insertintoclause intoclause) { if (intoclause.getcolumns().isempty()) { InsertStatement insert = EcoreUtil2.getContainerOfType(intoClause, InsertStatement.class); boolean ignore = false; SingleTableInsert singletableinsert = insert.getsingletableinsert(); if (singletableinsert!= null) { ValuesClause valuesclause = singletableinsert.getvaluesclause(); if (valuesclause!= null) { Expression expr = valuesclause.getexpression(); if (!(expr instanceof ParenthesisExpression)) { ignore = true; // record variable, column list not allowed! } } } if (!ignore) { warning(guideline_26_msg, intoclause.getdmlexpressionclause(), null, GUIDELINE_26, serialize(nodemodelutils.getnode(insert).getparent())); } } } 18

Eclipse Editor 19

TVDCC Command Line Interface processing file 'ESC_USER_ADMIN.pkb'... 346 issues found. processing file 'ESC_USER_ADMIN.pks'... 129 issues found. processing file 'ESC_USER_ADMIN_DEFAULT.pkb'... 30 issues found. processing file 'ESC_USER_ADMIN_DEFAULT.pks'... 6 issues found. processing file 'ESC_UTIL.pkb'... 193 issues found. processing file 'ESC_UTIL.pks'... no issues found. XML, HTML, Excel Output Summary: - Total files: 42 - Total bytes: 1806872 - Total lines: 32062 - Total commands: 5322 - Total statements (PL/SQL): 5800 - Max. cyclomatic complexity: 140 - Total issues: 4668 - Total warnings: 4667 - Total errors: 1 - Total processing time in seconds: 23.496 transforming tvdcc_report.xml into tvdcc_report.html... done. transforming tvdcc_report.xml into tvdcc_report.xlsx... done. cleanup completed. Console 20

AGENDA 1. Introduction 2. Grammar 3. Code Checking 4. Dependency Analysis 5. Core Messages 21

Motivation Find Object/Subobject Usage Table/view statements (e.g. Select, Insert, Update, Delete, Merge) Package procedures/functions Type methods Table/view columns Manage Accessibility of Sensitive Columns Client identifying data Turnover, cost per order/customer, gross margin, discount Nested views, named queries, subqueries column name changes Estimate Impact of Software Design Changes Aspect of design decisions Identify impacted modules (e.g. for testing purposes) 22

Scope of Database Dependency Analysis Dynamic SQL or PL/SQL Code Static SQL or PL/SQL Code Scope Deployed in an Oracle Database 23

Extend the Oracle Data Dictionary SQL> desc tvd_parsed_objects_t Oracle Database Name Type ------------- ------------------ OBJECT_ID NUMBER OWNER VARCHAR2(30) OBJECT_NAME VARCHAR2(128) OBJECT_TYPE VARCHAR2(30) LAST_DDL_TIME DATE DDL_SOURCE CLOB PARSE_TREE XMLTYPE XML Parse Tree dbms_ metadata. get_ddl SQL & PL/SQL Parser DDL 24

TVDCA Tables, Views used in DML Statements Usage within Function, Procedure, Trigger, Package Spec/Body, Type Body Consider Insert, Update, Delete, Merge statements Procedure_name semantics according DBA_PROCEDURES Example SQL> SELECT object_type, object_name, operation AS op, procedure_name, 2 table_owner AS t_own, table_name 3 FROM tvd_object_dml_usage_v t 4 WHERE owner = 'TVDCC'; OBJECT_TYPE OBJECT_NAME OP PROCEDURE_NAME T_OWN TABLE_NAME ------------ ---------------------- ------ -------------------- ----- -------------------- PACKAGE BODY TVD_PARSED_OBJECTS_PKG INSERT REFRESH TVDCC TVD_PARSED_OBJECTS_T FUNCTION TVD_SAMPLE_FUNCTION INSERT INNER_PROCEDURE TVDCC TVD_PARSED_OBJECTS_T FUNCTION TVD_SAMPLE_FUNCTION INSERT INNER_FUNCTION TVDCC TVD_PARSED_OBJECTS_T FUNCTION TVD_SAMPLE_FUNCTION INSERT TVDCC TVD_PARSED_OBJECTS_T PACKAGE BODY TVD_SAMPLE_PACKAGE INSERT MOST_INNER_PROCEDURE TVDCC TVD_PARSED_OBJECTS_T 25

Extend the Scope of Dependency Analysis SQL, PL/SQL Collector SQL, PL/SQL SQL> desc tvd_captured_sql_t Name Type ------------- ----------------- CAP_ID NUMBER CAP_SOURCE CLOB SQL_ID VARCHAR2(13) USER_NAME VARCHAR2(30) SCHEMA_NAME VARCHAR2(30) MODULE VARCHAR2(64) ACTION VARCHAR2(64) LAST_LOAD_TIME DATE PARSE_TREE XMLTYPE Oracle Database XML Parse Tree SQL & PL/SQL Parser 26

AGENDA 1. Introduction 2. Grammar 3. Code Checking 4. Dependency Analysis 5. Core Messages 27

Core Messages Writing a SQL*Plus parser is laborious Writing a validator is simple Extend the Oracle Data Dictionary for Dependency analysis and consider code not deployed in the database Xtext is a complete DSL framework More than just a parser generator Separation of parser and validators Promising for further applications like code fixing, code formatting, presenting graphical models, etc. 28

Questions and answers... Philipp Salvisberg Senior Principal Consultant philipp.salvisberg@trivadis.com BASEL BERN BRUGG LAUSANNE ZÜRICH DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. HAMBURG MUNICH STUTTGART VIENNA 29