You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Leonardo Junquera <le...@followup.net> on 2000/07/28 15:05:52 UTC
sqlplus ant task
I am loving ant. I want to create a new task to execute sqlplus files. I
can do it using exec but I wanted to tailor it in five ways:
1) I want to check to make sure sqlplus is in the path statement.
Question: is there a mechanism that you use to execute programs built into
task's execute method?
2) I want it to check that the .sql file exists before running it.
Question: how do I access the path attribute that was set in the <project>
element?
3) I want to run it in a specific directory
Question: is this built into the task?
4) I want to require user, password, server and file member variables.
Question: how do you specify that the attribute is required?
5) I want to log the output.
Question: is this built into the task object?
Thanks,
Leo
Re: sqlplus ant task
Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "LJ" == Leonardo Junquera <le...@followup.net> writes:
LJ> Where do I get the <sql> task you mentioned?
You'll need the latest CVS snapshot to have it.
I think you can build a version of Ant that includes <sql> if you use
the Ant 1.1 sources and retrieve docs/index.html, docs/sql.html,
src/main/org/apache/tools/ant/taskdefs/SqlExec.java and
src/main/org/apache/tools/ant/taskdefs/defaults.properties
and build a fresh Ant from it. This is if you don't want to get the
latest nightly build containing new features/bug fixes and bugs.
LJ> Do you know if it can run a .sql file?
I think it will do almost everything you want out of the box as long
as you have a working JDBC driver.
It does read the statements one by one and expects them to be
separated by ; This may or may not be true for your setup (defining
stored procedures might be a problem here) - but it should give you a
good starting point.
LJ> I wanted to make sure that the file existed after the attempt to
LJ> get it from source safe. The build hangs if it cannot find one.
hmm, you can check using the available task and put the exec task into
a target that has an if attribute checking for the property set by
available - think I'm repeating myself.
Stefan
RE: sqlplus ant task
Posted by Leonardo Junquera <le...@followup.net>.
Stefan, thank you very much. Just the info I was looking for. Where do I
get the <sql> task you mentioned? Do you know if it can run a .sql file?
I'm asking because I have a bunch of table alterations, views, and stored
procedures that I want to get out of source safe and run. We usually have a
create.sql script where we list file names for each one (e.g.
@vw_active_customers ) and has a quit statement at the end. I've been using
exec with the command attribute set to "user/password@server @create" which
runs the script and exits sqlplus. I wanted to make sure that the file
existed after the attempt to get it from source safe. The build hangs if it
cannot find one.
Thanks,
Leo
Re: sqlplus ant task
Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "LJ" == Leonardo Junquera <le...@followup.net> writes:
LJ> I am loving ant. I want to create a new task to execute sqlplus
LJ> files.
Take a look at the new <sql> task. Maybe this already does what you
want. You'll only need a JDBC driver to your database.
I assume you've read the "Writing your own task" section in the docs
for the rest of the mail.
LJ> 1) I want to check to make sure sqlplus is in the path statement.
I'd be happy to find a way to check whether I can execute a give
command. I'd add <available executable="..."> immediately.
LJ> 2) I want it to check that the .sql file exists before running
LJ> it. Question: how do I access the path attribute that was set in
LJ> the <project> element?
Project.getBaseDir. Better yet, either make you setter method
something like setSqlFile(File) and relative paths will be resolved
for you (Project.resolveFile is responsible for this).
LJ> 3) I want to run it in a specific directory Question: is this
LJ> built into the task?
Take a look at the Execute and ExecTask classes to see how they do it.
LJ> 4) I want to require user, password, server and file member
LJ> variables. Question: how do you specify that the attribute is
LJ> required?
There is no explicit way. In your execute method make sure they have
been set and throw a BuildException if they are not.
LJ> 5) I want to log the output. Question: is this built into the
LJ> task object?
Not sure, whether I know what you mean. There are Task.log() methods
responsible for logging messages. If you want to redirect the output
of sqlplus, again take a look at ExecTask and Execute.
Stefan