gvenzl / oci-oracle-free

Build scripts for Oracle Database FREE container/docker images
Apache License 2.0
113 stars 28 forks source link

How to change into Directory before running SQL Script from Initialization scripts #27

Closed tkleiber closed 8 months ago

tkleiber commented 8 months ago

Hi!

I want to install utPLSQL into the database before using it.

So first I have a shell script "01_utplsql_download.sh", which successfully download and extract utPLSQL as described in utPLSQL documention:

#!/usr/bin/env bash
curl -LOk $(curl --silent https://api.github.com/repos/utPLSQL/utPLSQL/releases/latest | awk '/browser_download_url/ { print $2 }' | grep ".zip\"" | sed 's/"//g')
unzip -q utPLSQL.zip

The second script "02_utplsql_install.sql" should install utPLSQL, but I have to change directory to the directory "utPLSQL/source" before to run it successfully as described in utPLSQL documention:

@install_headless.sql utp3 oracle

If I change (cd) the directory in the first bash script, the second sql script does not get this directory. If I add the diretory to the @ directive, the installation script run only partially. Any idea?

Best regards Torsten

gvenzl commented 8 months ago

Hi @tkleiber,

Thanks a lot for using these images.

Changing the directory in the first (previous) script won't help indeed, as each script is called in isolation from the others.

The probably simplest solution would be to have the bash script download utPLSQL, change the directory and then invoke sqlplus directly.

I assume the installation only runs partially because the install_headless.sql file in itself uses @<file> to invoke other files, which will then look for these files in the same directory that you have invoked @.../install_headless.sql.

If install_headless.sql were instead using @@<file>, it would look in the directory from where the script itself resides.

tkleiber commented 8 months ago

Hi @gvenzl!

The probably simplest solution would be to have the bash script download utPLSQL, change the directory and then invoke sqlplus directly.

I have done this successfully now. Another reason is, that the sql file run in the cdb and I have to run it in the pdb. I believe there is no way to run this directly as directly as sql file without control over the content of the file?

If install_headless.sql were instead using @@<file>, it would look in the directory from where the script itself resides.

No install_headless.sql use already @@<file>, as far I can see. But I have not gone into the deepest level of the framework to find out, why the install is not succesful, if I not change into the directory.

Best regards Torsten

gvenzl commented 8 months ago

Hi @tkleiber,

Glad to hear that you managed to get this working.

I believe there is no way to run this directly as directly as sql file without control over the content of the file?

Depending on what the SQL file is executing inside it. If it includes a connect statement itself, you have no control over to where it is connecting to, even if you invoke it from being connected to another database.

Thanks,