Created
January 7, 2012 02:31
-
-
Save nagoodman/1573540 to your computer and use it in GitHub Desktop.
move_window_forward.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foreignTableName = "KEY_WINDOWED"; | |
var foreignTableSchema = "APPLIB"; | |
var connection = Packages.java.sql.DriverManager.getConnection("jdbc:default:connection"); | |
// TODO: should actually be select max(key) from target table | |
var newStartKeySQL = "select '[\"02/01/2007\"]' from (values(0))"; | |
//Packages.java.lang.System.out.println("newStartKeySql:" + newStartKeySQL); | |
var stmt = connection.createStatement(); | |
var rs = stmt.executeQuery(newStartKeySQL); | |
var newStartKey; | |
while (rs.next()) { | |
newStartKey = rs.getString(1); | |
} | |
stmt.close(); | |
//Packages.java.lang.System.out.println("newStartKey:" + newStartKey); | |
var origDDLSQL = "select statement from table(sys_root.generate_ddl_for_table('" | |
+ foreignTableSchema | |
+ "', '" | |
+ foreignTableName | |
+ "'))"; | |
//Packages.java.lang.System.out.println("origDDLSQL:" + origDDLSQL); | |
var stmt = connection.createStatement(); | |
var rs = stmt.executeQuery(origDDLSQL); | |
var ddlString = ""; | |
while (rs.next()) { | |
var currentLine = rs.getString(1); | |
if ( currentLine.indexOf('startkey') > 0 ) { | |
currentLine = currentLine.substr(0, currentLine.indexOf('startkey=') + 9 ) | |
+ escape(newStartKey) | |
+ '\''; | |
} | |
ddlString += currentLine; | |
} | |
stmt.close(); | |
// Trim out ; from ddl statement | |
ddlString = ddlString.substr(0, ddlString.length - 1); | |
//Packages.java.lang.System.out.println("OrigDDLSQL" + ddlString); | |
var dropDDL = "drop foreign table " + foreignTableSchema + "." + foreignTableName; | |
var stmt = connection.createStatement(); | |
stmt.execute(dropDDL); | |
stmt.close(); | |
// Create new table | |
var stmt = connection.createStatement(); | |
stmt.execute(ddlString); | |
stmt.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment