Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

PL/SQL & SQL formatter settings based on the Trivadis PL/SQL & SQL Coding Guidelines

License

NotificationsYou must be signed in to change notification settings

Trivadis/plsql-formatter-settings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@PhilippSalvisberg no longer work for Trivadis - Part of Accenture and no one at Trivadis/Accenture will continue this project. Therefore, this GitHub repository was archived on 30 August 2024.

However, @PhilippSalvisberg decided to create a fork and continue this project underPhilippSalvisberg/plsql-formatter-settings.

PL/SQL & SQL Formatter Settings

Introduction

This repository provides formatter settings for thecoding style rules of the Trivadis PL/SQL & SQL Coding Guidelines.

Settings are primarily provided for

These settings have been defined and tested with the product versions mentioned above. They might not work in other versions.

Please note, that these settings cannot be used inOracle SQL Developer for VSCode 23.4.0. And it does not work in the embedded version of SQLcl 23.3.1.0, which cannot run JavaScript.

JDK 11 is required for SQLDev and SQLcl. The standalone tvdformat.jar requires JDK 17 or newer.

Seereleases for settings supporting older versions.

Patching SQL Developer

SQL Developer is slowly reaching the end of its life cycle. The days when SQL Developer and SQLcl were released almost simultaneously every quarter are long gone. We can continue to expect regular SQLcl releases, but with the availability of SQL Developer as a Visual Studio Code Extension, SQL Developer will only be updated sporadically.

A new SQLcl version typically comes with enhancements and bug fixes in the area of PL/SQL and SQL grammar. And this also requires an adaptation of the formatting rules due to symbol name changes etc. And as a result, these formatting rules can actually only be used in SQLcl.

However, we know that the grammars and the formatter are provided in a JAR calleddbtools-common.jar. And this JAR file also exists in the SQL Developer distribution. This means that in order to be able to use the current formatting rules in SQL Developer, we have to copy thedbtools-common.jar file from SQLcl to SQL Developer. Unfortunatelly the classes are not 100% compatible with SQL Developer. As a a result, we have to keep some original classes, which complicates the patching process a bit.

Here's the full procedure to usedbtools-common.jar from SQLcl 23.4.0 in SQL Developer 23.1.1.345:

  1. Quit SQL Developer

    We are going to patch SQL Developer. This is not possible on Windows if SQL Developer is running. On other OS this might have strange effects. Therefore quit SQL Developer.

  2. Rename SQL Developer’sdbtools-common.jar

    Find thedbtools-common.jar in your SQL Developer installation. In our case it's in/Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/lib. Rename this file todbtools-common.original.jar.

  3. Copy SQLcl’sdbtools-common.jar

    Find thedbtools-common.jar in your SQLcl installation. In our case it's in/usr/local/bin/sqlcl/lib. Copy the file to the SQL Developer’s directory (wheredbtools-common.original.jar is located).

  4. Patch SQLcl'sdbtools-common.jar

    Open a terminal window in thelib folder wheredbtools-common.original.jar anddbtools-commmon.jar are located and run the following commands to copy the classoracle.dbtools.parser.ParserNode.class todbtools-common.jar:

    jar -xvf dbtools-common.original.jar oracle/dbtools/parser/ParseNode.classjar -u0vMf dbtools-common.jar oracle/dbtoolsrm -rf oracle

    This step is necessary to ensure that the "Code Outline" continues to work in SQL Developer.

  5. Clear SQL Developer's cache

    Delete the following directory:

    • On Windows:%APPDATA%\SQL Developer\system23.1.1.345.2114\system_cache
    • On other platforms:$HOME/.sqldeveloper/system23.1.1.345.2114/system_cache

    This step is necessary to ensure no other version ofdbtools-common.jar is used from the cache. Allwindow preferences will be reset to factory settings. However, all other preferences including your connections are preserved.

  6. Start SQL Developer

    Open an editor and test if the formatter and code outline is working.

Deviating Settings

Please note that these settings do not comply with rule 5. Line breaks are placed after a comma and not before. All other rules are followed. However, you can easily change this in the preferences.

Change Line Breaks On Comma

Installation

Common

Clone this repository or download the ZIP file and extract it.

SQLcl

Seesqlcl/README.md.

Standalone Formatter

Seestandalone/README.md

SQL Developer

  1. Start SQL Developer
  2. OpenPreferences
  3. SelectCode Editor ->Format ->Advanced Format
  4. PressImport...Advanced Format
  5. Selecttrivadis_advanced_format.xml
  6. PressOpen
  7. SelectCode Editor ->Format ->Advanced Format ->Custom Format
  8. PressImport...Custom Format
  9. Selecttrivadis_custom_format.arbori
  10. PressOpen
  11. PressOK to save the settings

Gitpre-commit Hook

Seehook/README.md.

Nice to Know

Lightweight Formatter

The Arbori program implements alightweight formatter which accepts different coding styles. The primary scope of the formatter is the following SQL statements:

  • create function
  • create package
  • create package body
  • create procedure
  • create trigger
  • create type
  • create type body
  • create view (including thesubquery part ofcreate materialized view)
  • delete
  • insert
  • merge
  • select
  • update

Other statements likecreate table orcreate tablespace are basically left as is. There are some exceptions like adding line breaks after reaching the maximum line length and changing the case of keywords and identifiers. But that's it.

If you need a heavyweight formatter to enforce the conformity of your code, you will need to use the default Arbori program provided by the SQL Developer team.

In any case, you can use our SQLcl JavaScriptformat.js, thestandalone formatter or theGitpre-commit hook to format your code.

Disable Formatter

The formatter is enabled by default. You can disable the formatter with a single-line or multi-line comment containing@formatter:off. From that point on, whitespace are kept as is. To re-enable the formatter use@formatter:on.

Supported Marker CommentActionOrigin
@formatter:offDisables formatterEclipse IDE
@formatter:onEnables formatterEclipse IDE
noformat startDisables formatterPL/SQL Developer
noformat endEnables formatterPL/SQL Developer

The marker comments are case sensitive.

Here's an example showing the code after calling the formatter:

-- @formatter:offselect decode(dummy,'X',1                   ,'Y',2                   ,'Z',3                        ,0)/* @formatter:on*/from dual;

Arbori

SQL Developer uses its own parse tree query language called Arbori for its advanced formatter configuration. Here is some additional information that might be useful if you plan to tweak the behavior of the formatter yourself.

Links

Thank you, Vadim Tropashko for providing this valuable information.

JavaScript Global Variables

To get the most out of the dynamic JavaScript actions from an Arbori program, you should know the following global variables and their corresponding Java class.

VariableTypeJAR File
structoracle.dbtools.app.Formatdbtools-common.jar
targetoracle.dbtools.parser.Parseddbtools-common.jar
tupleHashMap<String, oracle.dbtools.parser.ParseNode>dbtools-common.jar
loggeroracle.dbtools.util.Loggerdbtools-common.jar

Settings for other Products

Formatter settings are also provided for the following products:

ProductVersionFile
Allround Automations PL/SQL Developer14.0.6trivadis_beautifier.br
JetBrains DataGrip2021.1trivadis.xml
Quest Toad for Oracle14.1trivadis_fmtplus.opt

Please refer to the vendor's documentation for instructions on how to import these settings.

License

The Trivadis PL/SQL & SQL Formatter Settings are licensed under the Apache License, Version 2.0. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0.

About

PL/SQL & SQL formatter settings based on the Trivadis PL/SQL & SQL Coding Guidelines

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp