You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by temp temp <mi...@yahoo.com> on 2007/08/24 14:23:21 UTC
sql ant task
I trying to execute small script using ant , here is the script
SET NEWPAGE 0
SET SPACE 0
SET LINESIZE 80
SET PAGESIZE 0
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET MARKUP HTML OFF
SET ESCAPE \
SPOOL DELETEME.SQL
select 'drop table ', table_name, 'cascade constraints \;' from user_tables
how to run this script using ant sql task
Thanks
Miro
---------------------------------
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us.
Re: sql ant task
Posted by Ognjen Blagojevic <og...@etf.bg.ac.yu>.
Hi Temp, :)
> I trying to execute small script using ant , here is the script
...
> select 'drop table ', table_name, 'cascade constraints \;' from user_tables
Save your script to sql/SCRIPT.sql, and try something like this:
<property name="db.driver" value="com.mysql.jdbc.Driver"/>
<property name="db.url"
value="jdbc:mysql://www.mycompany.org/myschema"/>
<property name="db.username" value="myuser"/>
<property name="db.password" value="mypass"/>
<property name="db.classpath"
value="../lib/mysql-connector-java-5.0.4-bin.jar"/>
<target name="sql">
<sql driver="${db.driver}"
url="${db.url}"
userid="${db.username}"
password="${db.password}"
src="sql/SCRIPT.sql"
encoding="UTF-8"
classpath="${db.classpath}"
/>
</target>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: sql ant task
Posted by Steve Loughran <st...@apache.org>.
temp temp wrote:
> I trying to execute small script using ant , here is the script
> SET NEWPAGE 0
> SET SPACE 0
> SET LINESIZE 80
> SET PAGESIZE 0
> SET ECHO OFF
> SET FEEDBACK OFF
> SET HEADING OFF
> SET MARKUP HTML OFF
> SET ESCAPE \
> SPOOL DELETEME.SQL
> select 'drop table ', table_name, 'cascade constraints \;' from user_tables
>
> how to run this script using ant sql task
Stick it inline in the task, set up the classpath with the right JDBC
drivers.
From the source of Ant in Action, two targets to set up the classpath
with mysql and define new sql tasks all set up as the right users
<target name="mysql-init" depends="ivy-resolve"
xmlns:ext="http://antbook.org/d1/ext" >
<ivy:cachepath pathid="sql.classpath" conf="sql" />
<property name="mysql.root.pass" value=""/>
<property name="mysql.diary.pass" value="secret"/>
<presetdef name="mysql-admin"
uri="http://antbook.org/d1/ext">
<sql driver="com.mysql.jdbc.Driver"
classpathref="sql.classpath"
userid="root"
password="${mysql.root.pass}"
print="true"
url="jdbc:mysql://localhost/mysql"
expandProperties="true"/>
</presetdef>
<presetdef name="mysql"
uri="http://antbook.org/d1/ext">
<ext:mysql-admin
userid="diary"
password="${mysql.diary.pass}"
url="jdbc:mysql://localhost/diary"/>
</presetdef>
</target>
Followed up by some operations
<target name="mysql-drop-db" depends="mysql-init"
description="create the database and account">
<ext:mysql-admin onerror="continue">
DROP DATABASE diary;
</ext:mysql-admin>
</target>
<target name="mysql-create-db"
depends="mysql-init,mysql-drop-db"
description="create the database and account">
<ext:mysql-admin>
CREATE DATABASE diary;
GRANT ALL PRIVILEGES ON diary.* TO 'diary'@'localhost';
SET PASSWORD FOR 'diary'@'localhost' =
PASSWORD('${mysql.diary.pass}');
</ext:mysql-admin>
</target>
<target name="mysql-create-events" depends="mysql-init"
description="create the event table">
<ext:mysql>
CREATE TABLE EVENTS (
EVENT_ID varchar(64) not null,
EVENT_NAME varchar(255) not null,
EVENT_DATE timestamp not null,
EVENT_VERSION integer,
EVENT_LASTMODIFIED timestamp,
EVENT_TEXT varchar(8192),
primary key (EVENT_ID));
</ext:mysql>
</target>
<target name="mysql-create-events-file" depends="mysql-init">
<ext:mysql>
<transaction src="config/deploy/sql/create_event_table.sql" />
</ext:mysql>
</target>
<target name="mysql-list-events" depends="mysql-init"
description="list all events in the system">
<ext:mysql>
select * from EVENTS;
</ext:mysql>
</target>
Nothing to it, once you have the JDBC drivers and paths set up
--
Steve Loughran http://www.1060.org/blogxter/publish/5
Author: Ant in Action http://antbook.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: sql ant task
Posted by Krzysztof Kucybała <kk...@echo.fr>.
I guess I can give You a postgreSQL example, if that suits You. Under
unix/linux pgsql comes with a command line tool which you can easily
use. Here's the sample part of antfile - not tested, so no guarantees,
but I suppose it could look more or less like this:
<exec dir="." executable="pgsql">
<arg line="-i ./mystuff/mysqlscript.sql"/>
</exec>
Dig the ant docs a little to find out more. If I remember pgsql well,
this should probably work fine, if you'd have it accessible on the
system path.
Best regards,
Krzysztof
miro wrote:
> Thank you very much for your reply can you send me a simple example of using
> exec task to execute a sql file ?
> Thanks
> Miro
>
>
> Krzysztof Kucybała wrote:
>> I suppose the easies, though maybe not the smartest way to do it, would
>> be to use exec task. Of course that is only useful if you have a command
>> line interface for the db that You're trying to use. You could put this
>> in some *.sql file and have it exec-uted from ant. Does that help?
>>
>> Best regards,
>> Krzysztof
>>
>> temp temp wrote:
>>> I trying to execute small script using ant , here is the script
>>> SET NEWPAGE 0
>>> SET SPACE 0
>>> SET LINESIZE 80
>>> SET PAGESIZE 0
>>> SET ECHO OFF
>>> SET FEEDBACK OFF
>>> SET HEADING OFF
>>> SET MARKUP HTML OFF
>>> SET ESCAPE \
>>> SPOOL DELETEME.SQL
>>> select 'drop table ', table_name, 'cascade constraints \;' from
>>> user_tables
>>>
>>> how to run this script using ant sql task
>>> Thanks
>>> Miro
>>>
>>>
>>> ---------------------------------
>>> Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user
>>> panel and lay it on us.
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: sql ant task
Posted by miro <mi...@yahoo.com>.
Thank you very much for your reply can you send me a simple example of using
exec task to execute a sql file ?
Thanks
Miro
Krzysztof Kucybała wrote:
>
> I suppose the easies, though maybe not the smartest way to do it, would
> be to use exec task. Of course that is only useful if you have a command
> line interface for the db that You're trying to use. You could put this
> in some *.sql file and have it exec-uted from ant. Does that help?
>
> Best regards,
> Krzysztof
>
> temp temp wrote:
>> I trying to execute small script using ant , here is the script
>> SET NEWPAGE 0
>> SET SPACE 0
>> SET LINESIZE 80
>> SET PAGESIZE 0
>> SET ECHO OFF
>> SET FEEDBACK OFF
>> SET HEADING OFF
>> SET MARKUP HTML OFF
>> SET ESCAPE \
>> SPOOL DELETEME.SQL
>> select 'drop table ', table_name, 'cascade constraints \;' from
>> user_tables
>>
>> how to run this script using ant sql task
>> Thanks
>> Miro
>>
>>
>> ---------------------------------
>> Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user
>> panel and lay it on us.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/sql-ant-task-tf4323270.html#a12312062
Sent from the Ant - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: sql ant task
Posted by Krzysztof Kucybała <kk...@echo.fr>.
I suppose the easies, though maybe not the smartest way to do it, would
be to use exec task. Of course that is only useful if you have a command
line interface for the db that You're trying to use. You could put this
in some *.sql file and have it exec-uted from ant. Does that help?
Best regards,
Krzysztof
temp temp wrote:
> I trying to execute small script using ant , here is the script
> SET NEWPAGE 0
> SET SPACE 0
> SET LINESIZE 80
> SET PAGESIZE 0
> SET ECHO OFF
> SET FEEDBACK OFF
> SET HEADING OFF
> SET MARKUP HTML OFF
> SET ESCAPE \
> SPOOL DELETEME.SQL
> select 'drop table ', table_name, 'cascade constraints \;' from user_tables
>
> how to run this script using ant sql task
> Thanks
> Miro
>
>
> ---------------------------------
> Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org