Reputation: 1299
I am running sybase ASE db in a docker container for local development and testing purpose, I am able to successfully run the container and I can see that server is up and running and databases are created. Now I wrote a small sql script to test if the server and databases are up or not before running the test and I am running script inside the sybase container using isql. However I see that when executing the script with isql there is no output but if I execute the commands manually via isql it gives the output properly.
2> exit
[root@dib10-XTYH8OK2 /]# /opt/sybase/OCS-16_0/bin/isql -U sa -P myPassword -S MYSYBASE -i sybase_test.sql
[root@dib10-XTYH8OK2 /]#
Executing via script gives no output
drwxrwxrwt 1 root root 4096 May 2 11:14 tmp
[root@dib10-XTYH8OK2 /]# /opt/sybase/OCS-16_0/bin/isql -U sa -P myPassword -S MYSYBASE
1> use configDB
2> select getDate()
3> go
-------------------------------
May 2 2024 11:16AM
(1 row affected)
Executing comamnds manually via isql gives correct output
Below is the script
use configDB
SELECT getdate()
go
~
Upvotes: 2
Views: 214
Reputation: 35256
When submitting a script (eg, sybase_test.sql
) via isql
the execution command (go
) must a) be on a line by itself, b) start in column 1 and c) have nothing but white space and/or a linefeed (\n
) after the o
. With this in mind ...
I'm guessing your actual script has windows/dos line endings (\r\n
) so what your file really contains is go\r\n
, and it's the \r
that is negating the effect of the go
(ie, isql
doesn't recognize go\r
as the execution command).
Consider the following:
$ cat sybase_test.sql
select getdate()
go
$ file sybase_test.sql
sybase_test.sql: ASCII text
$ od -c sybase_test.sql
0000000 s e l e c t g e t d a t e ( )
0000020 \n g o \n
^^^^^^^^^^ # line ends with a linefeed (\n)
$ isql -i sybase_test.sql
------------------------------- # script executes as expected
May 2 2024 8:16AM
Now, let's convert the file to contain windows/dos line endings (\r\n
) ...
$ unix2dos sybase_test.sql # convert `\n` to `\r\n`
$ cat sybase_test.sql
select getdate() # contents *look* the same
go
$ file sybase_test.sql
sybase_test.sql: ASCII text, with CRLF line terminators
^^ # a `\r` has been added
$ od -c sybase_test.sql
0000000 s e l e c t g e t d a t e ( )
0000020 \r \n g o \r \n
^^^^^^^^^ # 'go' followed by '\r'
$ bisql -i sybase_test.sql
$ # no output because to isql `go\r` is not the same as `go`
If windows/dos line endings (\r\n
) turn out to be the issue in this case there are several ways to remove the \r
with the easiest being:
dos2unix sybase_test.sql
You get output from your manual attempt because you are manually submitting go
(and not go\r
) to isql
.
A better test would be to run your complete command from the command line:
/opt/sybase/OCS-16_0/bin/isql -U sa -P myPassword -S MYSYBASE -i sybase_test.sql
I'm guessing this will also do nothing.
You could then remove the windows/dos line endings and try again:
dos2unix sybase_test.sql # convert `\r\n` to `\n`
/opt/sybase/OCS-16_0/bin/isql -U sa -P myPassword -S MYSYBASE -i sybase_test.sql
I'm guessing at this point you will get some output.
If the above does not address your issue then please update the question with the complete output from the following:
od -c sybase_test.sql
Upvotes: 1