Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(oracle): provide toggle layout functionality #239

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nlinaje
Copy link

@nlinaje nlinaje commented May 24, 2024

This is a PoC to check how to add the toggle layout functionality for oracle databases.

In schemas.vim:
New variable created in "s:oracle_toggle_layout_query" which contains a PL/SQL script to read row by row from the database and then put the "column_name : value". The PL/SQL procedure is called: print_cols_as_rows

Changes in "s:oracle":

  • add this new variable: layout_query and set it to oracle_toggle_layout_query
  • add variable layout_flag: and set it to empty => The ";" of the SELECT statement must be deleted

In dbout.vim:
In case the filetype is plsql, there are many substitutions to make. The main steps are:

  • Extract ONLY the SELECT statement from content. If we send other sql commands like "column xxx format a20" to the PLS/SQL procedure it will not work.
  • Substitute the ";" at the end of the select command with layout_flag. Note: The extract command could be written to not include the last ";" from the select statement. If so, this substitute is not needed, but I've leave for consistency for other databases.
  • Substitute all carriage return with a space, otherwise the PL/SQL procedure does not work
  • Substitute all single quotes (') with two single quotes. This is needed to "escape" the single quote in the PL/SQL procedure. Needed for cases like "... where COLUMN = 'value'"

The content variable is constructed as:

  • The PL/SQL procedure
  • an exec command to start the procedure. As parameter the procedure sends the SQL statement extracted.
  • As the script inserts this procedure to the Oracle schema, we need to drop it again from the schema to leave the schema untouched.

Hope that other people can check this before merging it to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant