Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks, I need to connect to a Database with username/password authentication(should be appropriate to all the 3 db's i.e. MSSQL,Oracle,DB2) and execute an .sql script say 1234.sql by passing another .sql script say abcd.sql as input for the 1234.sql script. Then store the output generated into a specified location. Please note that the main .sql script(1234.sql) should loop and execute to all the input .sql files in a folder. Thanks.

Replies are listed 'Best First'.
Re: Execute a sql script with another sql scripts as input
by marto (Cardinal) on Sep 05, 2005 at 11:26 UTC
    Hi,

    Using DBI you can connect to the three databases you mentioned. You will need the appropriate driver for each.

    I dont quite understand the rest of your request, perhaps I am being silly or perhaps you could describe your problem better. I dont think you should have a problem working out how to process each .sql file in a folder from a Perl script using DBI.

    If you are new to Perl I would suggest having a look at the Tutorials section of this site, they cover everything you will need to know in order to complete this task.

    Hope this helps.

    Martin
Re: Execute a sql script with another sql scripts as input
by jfroebe (Parson) on Sep 05, 2005 at 14:40 UTC

    Hi,

    From what I can understand, the 1234.sql script is pretty much a template. The abcd.sql script fills in the template so that the resultant 'new' file contains pure sql. Is this what you mean?

    If so, this can be done quite easily by using the Template Toolkit or similar.

    Jason L. Froebe

    Team Sybase member

    No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1

Re: Execute a sql script with another sql scripts as input
by CountZero (Bishop) on Sep 05, 2005 at 16:13 UTC
    It would be most helpful if you could show us an example of these SQL-scripts so we have an idea of what you mean/need. Perhaps there is even a solution withing SQL itself possible (subrequests and the like spring to mind).

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law