Skip to content

tasks: simplify configuration #41

@pocelka

Description

@pocelka

Hello,

Recently I managed to watch youtube videos with insum insiders series where was referenced this repository.

Looking into the repo I tried to used your scripts for running SQL scripts via vscode, however I find the setup quite a bit complicated. One has to create user-config.sh, then modify it (i.e. change connection string) ... I tried to used it, but I've experienced some issues. So I ended with simplified version.

I would like to suggest simplification, to leverage vscode's settings.json

Something like this:

settings.json

{
  "db_con": "user/pass@//host:port/service",
  "client": "sqlcl"
}

tasks.json

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Oracle: Run SQL",
      "type": "shell",
      "command": ".vscode/run_sql.sh",
      "args": [
        "${file}",
        "${config:db_con}",
        "${config:client}"
      ],
      "group": "build",
      "presentation": {
        "reveal": "always",
        "panel": "dedicated"
      },
      "options": {},
      "problemMatcher": {
        "owner": "plsql",
        "fileLocation": [
          "relative",
          "${fileDirname}"
        ],
        "pattern": {
          "regexp": "(.*) (\\d*)\/(\\d*) (.*?) (.*)",
          "severity": 1,
          "line": 2,
          "column": 3,
          "file": 4,
          "message": 5,
          "loop": true
        }
      }
    }
  ]
}

Then my run_sql.sh looks like this:

#!/usr/bin/bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Env variables $1, $2, etc are from the tasks.json args array
FILE_FULL_PATH=$1
DB_CONN=$2
CMD=$3

# run sqlplus, execute the script, then get the error list and exit
"${CMD}" -S /nolog << EOF
conn $DB_CONN

-- load global settings
@$SCRIPT_DIR/settings.sql

-- Run file
@$FILE_FULL_PATH

set define on
--show errors

@$SCRIPT_DIR/show_all_errors.sql

exit;

EOF

Although I'm not sure whether it would work for all operating systems...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions