[Info-Ingres] Running Ingres SQL commands from a shell script?
Dan Stromberg
dstromberg at datallegro.com
Thu Apr 26 12:03:06 CDT 2007
On Thu, 26 Apr 2007 07:03:58 -0700, OldSchool wrote:
> On Apr 25, 9:33 pm, Dan Stromberg <dstromb... at datallegro.com> wrote:
>> Hi folks.
>>
>> Is there any good way, from a shell script, to run SQL commands against
>> Ingres (perhaps via ingres' terminal monitor), and to get a useful exit
>> status from the SQL statements back to the calling shell?
>>
>> I realize I could use something like python with an ODBC interface, but 1)
>> that seems kind of heavyweight for what I want to do and 2) I don't think
>> I'll be able to get permission to put an ODBC interface -on- the
>> machines in question. It's pretty much whatever comes with CentOS 4.4 or
>> not at all for this project.
>>
>> Ideal might be to have any exit stati and'd or or'd together (dare I say,
>> at the caller's discretion?), or to have an array of exit stati kind of
>> like bash's $PIPESTATUS array, except for a chronology of statements, not
>> concurrent-but-chained-together statements.
>>
>> If I must, I could run the SQL statements (the ones with side effects,
>> at least) one a time though.
>>
>> Any suggestions?
>>
>> Thanks!
>
> Another option to pursue is the shells "here-doc" ability. For
> example
>
> Search_val=Jim
> sql <<eof
> select * from table1 where col1='$Search_val';
>
> eof
>
>
> note that the "eof"s above can be any string you define. if you use
> "<<" operator the string marking the end of input *must* be in column
> 1, if you use "<<-", the ending mark may be preceded by tab.
>
> check the man page for your shell
I can handle getting stuff into terminal monitor OK (although I hadn't
seen <<- before - that's pretty cool), it's more getting a useful
"pass/fail" result back from the terminal monitor to bash for some SQL
statements that I'm wondering about.
More information about the Info-Ingres
mailing list