"variable" dbaccess question
Posted in 1999
Topics: Server Administration
I have a situation where a Perl script is driving the updates for an
Informix based system. (The Perl bit is irrelevant to this post, hopefully).
I am thinking of writing a generalized function within the script, which
executes, via dbaccess, the SQL passed as a parameter to it. The script
processes the result of the query, but that's not important for the sake of
my question. The reason for my re-write is that there are a lot of
functions, which basically do the same thing but run different SQL's ' it's
crying out for a general function.
In a ideal world I would have all the SQL's in separate files and have a
parameter file which the SQL file names, the script would loop through the
file names and execute them one at a time. Unfortunately some of the SQL's
needs run time parameters which are used to match values in columns on WHERE
clauses etc. The run time parameters are variables within the Perl script.
I hope I have been clear enough, anyone done this kind of thing before and
have any suggestions?
Thanks in anticipation :)
Its actually quite simple. What you need to do is to create your SQL statement
in a Perl string variable say $sqlstmt and if using raw Perl (ie not DBD):
@sqlresults = `dbaccess $dbname - 2>/dev/null <<EOF
$sqlstmt
EOF
`;
You will have to parse the @sqlresults array probably individually depending
on the number of columns returned, etc to get the results.
HTH
Sujit
In article <7830d6$suh@sjx-ixn9.ix.netcom.com>,
"Ban Spam Now" <no_spam@no_spam.com> wrote:
> I have a situation where a Perl script is driving the updates for an
> Informix based system. (The Perl bit is irrelevant to this post, hopefully).
>
> I am thinking of writing a generalized function within the script, which
> executes, via dbaccess, the SQL passed as a parameter to it. The script
> processes the result of the query, but that's not important for the sake of
> my question. The reason for my re-write is that there are a lot of
> functions, which basically do the same thing but run different SQL's ' it's
> crying out for a general function.
>
> In a ideal world I would have all the SQL's in separate files and have a
> parameter file which the SQL file names, the script would loop through the
> file names and execute them one at a time. Unfortunately some of the SQL's
> needs run time parameters which are used to match values in columns on WHERE
> clauses etc. The run time parameters are variables within the Perl script.
>
> I hope I have been clear enough, anyone done this kind of thing before and
> have any suggestions?
>
> Thanks in anticipation :)
>
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
Ban Spam Now wrote:
>
> I have a situation where a Perl script is driving the updates for an
> Informix based system. (The Perl bit is irrelevant to this post, hopefully).
>
> I am thinking of writing a generalized function within the script, which
> executes, via dbaccess, the SQL passed as a parameter to it. The script
> processes the result of the query, but that?s not important for the sake of
> my question. The reason for my re-write is that there are a lot of
> functions, which basically do the same thing but run different SQL?s - it?s
> crying out for a general function.
>
> In a ideal world I would have all the SQL?s in separate files and have a
> parameter file which the SQL file names, the script would loop through the
> file names and execute them one at a time. Unfortunately some of the SQL?s
> needs run time parameters which are used to match values in columns on WHERE
> clauses etc. The run time parameters are variables within the Perl script.
>
> I hope I have been clear enough, anyone done this kind of thing before and
> have any suggestions?
>
> Thanks in anticipation :)
--
Are you, by any chance, using version 7 of Informix?
I'm experiencing a problem with client updates due to the restrictions
of db_access with version 7.
Thanks!
ps I wish I could help you out with your situation more but I'm not that
deeply involved in what your trying to do.
Jill Katrina Snider
Visteon/Ford Motor Company
17000 Rotunda Dr., C275
Dearborn, MI 48121-6010
ph: 313-845-8955 fax: 313-322-9754