Groovy - java scripting language

For those who ventured too far - just hope they know their way back :)

Moderator: neilg

Groovy - java scripting language

Postby neilg » Tue Nov 29, 2005 12:44 pm

For the Groovy home page see: http://groovy.codehaus.org

This sample script reads a text file and outputs some SQL DDL statements to rename columns.

Most of it is regular Java although it follows normal script practices (loosely typed, etc):

Code: Select all
myFileDirectory = "/path/to/my/textfile/"
myFileName = "mytextfile.txt"
tableName = "mytable"
myFile = new File(myFileDirectory + myFileName)

i = 1
qte = "\""

processLine =
{
   if (it.indexOf("ADD FIELD") == 0)
   {
      sql = ""
      oldColumnName = qte + "Column #".concat("" + i++) + qte
      //splits the input according to some regular expression
      newColumnName = qte + it.split(qte)[1] + qte
      //
      sql = "alter table " + tableName
      sql = sql + " rename column " + oldColumnName
      sql = sql + " to " + newColumnName
      //
      println sql
      println "GO"
   }
}

myFile.eachLine(
   processLine
)

neilg
Regular
 
Posts: 141
Joined: Thu Jun 16, 2005 1:58 pm

Return to Strictly Technical

Who is online

Users browsing this forum: No registered users and 1 guest

cron