Subject Re: pipe multiline sql into isql
Author Roger Crämer
--- In firebird-support@yahoogroups.com, Yves Glodt <y.glodt@s...> wrote:
>
> Hi,
>
> I frequently use (and really like) the "pipe sql into" feature of
isql, e.g:
>
> echo "update ...;" | isql-fb -user SYSDBA -pass masterke localhost:db
>
> Now I need to update a trigger, that is drop an recreate it, and I
tried
> to put it as one long line between the quotes, like this:
>
> echo "drop TRIGGER CONFIGURATION_UPDATED; SET TERM ^; CREATE TRIGGER .."
>
> But it fails as it expects the sql to be split into multiple lines...:
>
> Statement failed, SQLCODE = -104
> Dynamic SQL Error
> -SQL error code = -104
> -Token unknown - line 1, char 37
> -SET
>
> As I'm on linux, I tried to do it in a little bash script, like e.g.:
>
> #!/bin/bash
>
> sql='
> 123
> 123
> 123
> '
> echo $sql
>
> But this also outputs like this:
> 123 123 123
>
> No newlines neither...
>
>
> How could I work around this?
>
>
> Best regards,
> Yves
>
>
> p.s.
> In my special case, I can not use the -i feature, because I can not
rely
> on external files. So "isql-fb -user SYSDBA -pass masterke localhost:db
> -i bla.sql" is not an option :-(
>


Hi Yves,

using Bash-Shell you may use the following construct
{
echo "drop TRIGGER CONFIGURATION_UPDATED;"
echo "SET TERM ^;"
echo "CREATE TRIGGER ..."
} | isql_fb -user SYSDBA -pass masterke localhost:db

that is for each line of the SQL-"Script" use one echo command.

Because that's a lot of writing, use the so called 'here document'
feature of the Shell:

cat <<- _EOT_ | isql_fb user SYSDBA -pass masterke localhost:db
drop TRIGGER CONFIGURATION_UPDATED;
SET TERM ^;
CREATE TRIGGER ....
...
_EOT_

(The blanks at the begin of each line are really tabs!)

More about 'here documents':
http://www.tldp.org/LDP/abs/html/here-docs.html


Regards
Roger