jump to navigation

Get your ANT together with Subversion and SQL. March 13, 2008

Posted by paperlessme in Ant, Oracle, script, Software, sql.
Tags: , , , ,
add a comment

Never underestimate the power of an ant Ant at work. It has been observed to easily push along a bread crumb ten times its size. When it does several such tasks in a row, an ant can get some real work done.

The ANT script below shows that it does not take much to get data exported from Subversion. Then, one can do whatever other tasks are needed with the exported data. In this example, another task does SQL Plus processing with the exported file. For instance, the file could contain SQL code for creating/replacing a package.

Before plunging into the script, let’s set up the ANT environment for these tasks. Drop svnkit.jar and svnkit-cli.jar (download from svnkit, a subversion java tool at ) into your ANT_HOME/lib directory.

Next, place the incanto.jar, supporting the Oracle <sqlplus> task (download from incanto ) into the same ANT_HOME/lib directory. (You will find the above jar files when you open the downloaded files, and their names could be slightly different.)
By configuring some ANT properties (used below) in a file beforehand, we are ready to fire off this ANT script:

. <taskdef name=”sqlplus” classname=”net.sf.incanto.Sqlplus”/>
. <property file=”${antProps}”/>
.
<target name=”svn.export”>
<echo message=”Exporting source from ${svn.url} to ${svn.exportPath }”/>
<java classname=”org.tmatesoft.svn.cli.SVN” dir=”${svn.exportPath}” fork=”true”>

<arg value=”co”/>
<arg value=”–username”/>
<arg value=”${svn.user}”/>
<arg value=”–password”/>
<arg value=”${svn.password}”/>
<arg value=”${svn.url}/${your.svn.branch}/XYZ”/>

<classpath>
<pathelement location=”${ant.lib.path}/svnkit.jar” />
<pathelement location=”${ant.lib.path}/svnkit-cli.jar” />
</classpath>
</java>
</target>

<target name=”do.example” depends=”svn.export”>
<!– Create/replace ‘yourSql.pkb’ package exported above –>

<sqlplus logon=”${db.user}/${db.password}”
silent=”false” failonerror=”true” resultproperty=”sql.returncode”
start=”${svn.exportPath}/XYZ/yourSql.pkb”>
</sqlplus>

</target>

Note that the Subversion client install is not needed with this example. In the case when the Subversion client is already installed, then we can use the <svn> task for the export. It requires a different set of jar files (from subclipse).

<!– load the svn task –>

<taskdef name=”svn” classname=”org.tigris.subversion.svnant.SvnTask”/>
.
<svn username=”${svn.user}” password=”${svn.password}”>
<export srcUrl=”${svn.url}/${your.svn.branch}/XYZ/youSql.pkb” destPath=”${svn.exportPath}” revision=”HEAD” />
</svn>

Now we got our ANT together. Power to the ant!

 

Locate a phone number on a map and call it via VOIP February 15, 2008

Posted by paperlessme in JavaScript, Software.
Tags: , , ,
add a comment

Install this script in your browser and locate a phone number on a map. Click to call the number via your VOIP provider. Cell phones are located by state/town and toll free numbers are excluded. Copy it from here.

Tested with: Firefox 1.5.01 (requires GreaseMonkey add-on) and IE 6.x (requires Turnabout plug-in @ http://www.reifysoft.com & simple edit of their config.xml)

Less effort – More fun – Enjoy!

Simply Ant. January 15, 2008

Posted by paperlessme in Ant, Oracle, Software, sql.
Tags: , ,
1 comment so far

The open-source Apache Ant scripting tool has a <sql> task, that does not provide a way of feeding the results of the executed SQL back to the Ant script itself. With a few lines of code and by following some conventions, you can add this functionality to your Ant script. Here is how.

<!– Get a record count SQL example using Oracle’s sample DB –>

<property name=”bin” location=”bin/sqlforant.jar“/>
<script language=”javascript”>
<![CDATA[
project.setProperty("db.url","jdbc:oracle:thin:@mydb");
project.setProperty("db.user","scott");
project.setProperty("db.password","tiger");
project.setProperty("db.type","SQL"); // default
project.setProperty("db.type","XML");
project.setProperty("db.query","select * from EMP;");
]]></script>
<taskdef name=”project” classname=”SqlForAnt” classpath=”${bin}”/>
<project/>
<echo message=”DB Query Results: ${db.results}”/>

To test the script: Save this file SqlForAnt (right click) to place it in your folder specified by the bin property above with a .jar extension.

By omitting the project.setProperty(“db.type”,”XML”) line above, ${db.results} will be set to a single value or a comma delimited list of values, depending on the result set.

In order to execute a SQL function or a stored procedure two additional properties should be set – project.setProperty(“db.type”,”FUNCTION”) or project.setProperty(“db.type”,”PROCEDURE”), followed by project.setProperty(“db.results”, res_type) where res_type is one of the following: BIGINT, BINARY, BIT, BOOLEAN, BYTE, CHAR, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, LONG, NULL, NUMERIC, OTHER, REAL, SHORT, SMALLINT, TIME, TIMESTAMP, TINYINT, VARCHAR.

Here are two examples:

project.setProperty(“db.type”,”FUNCTION”);
project.setProperty(“db.query”,”getRecCount(‘EMP’);”);
project.setProperty(“db.results”,”DECIMAL”);

project.setProperty(“db.type”,”PROCEDURE”);
project.setProperty(“db.query”,”begin TESTPARMS(’4/1/1981′, ?); end;”);
project.setProperty(“db.results”,”integer”);

In the case of a stored procedure, with more than one OUT parameter, the res_type should be a comma separated list of values. Omit the setting of this property for procedures without any OUT parameters. Procedures with INOUT parameters are not handled.

By default, the oracle.jdbc.driver.OracleDriver jdbc driver is used. It requires that the ojdbc14.jar or another jar supporting it, is placed in the Ant/lib directory. The script can also execute with another jdbc driver, provided one sets the project.setProperty(“db.driver”,”some.other.jdbc.driver“) and places the supporting .jar files in the Ant/lib. A good source of JDBC drivers is located here.

Enjoy!

Follow

Get every new post delivered to your Inbox.