Skip to content

Instantly share code, notes, and snippets.

@krisrice
Created October 14, 2021 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisrice/5719d73e90842ce0e33c37a58be101ba to your computer and use it in GitHub Desktop.
Save krisrice/5719d73e90842ce0e33c37a58be101ba to your computer and use it in GitHub Desktop.
set scan off
set define off
script sqlid.js
set statusbar add sqlid
➜ examples more sqlid.js
var SqlId = Java.type("oracle.dbtools.util.SqlId");
// SQLCL's Command Registry
var CommandRegistry = Java.type("oracle.dbtools.raptor.newscriptrunner.CommandRegistry");
// CommandListener for creating any new command
var CommandListener = Java.type("oracle.dbtools.raptor.newscriptrunner.CommandListener")
// Broke the .js out from the Java.extend to be easier to read
var cmd = {};
// Called to attempt to handle any command
cmd.handle = function (conn,ctx,cmd) {
return false;
}
// fired before ANY command
cmd.begin = function (conn,ctx,cmd) {
ctx.putProperty("sqlid",SqlId.stmt2sqlid(cmd.getModifiedSQL()));
}
// fired after ANY Command
cmd.end = function (conn,ctx,cmd) {
}
// Actual Extend of the Java CommandListener
var SQLID = Java.extend(CommandListener, {
handleEvent: cmd.handle ,
beginEvent: cmd.begin ,
endEvent: cmd.end
});
// Registering the new Command
CommandRegistry.addForAllStmtsListener(SQLID.class);
var StatusBarComponent = Java.type("oracle.dbtools.raptor.console.StatusBarComponent");
var component = new StatusBarComponent() {
getName: function() {
return "sqlid";
},
getDescription: function() {
return "sqlid ";
},
update: function(context) {
context.append( ctx.getProperty("sqlid"));
}
};
ctx.getConsoleService().registerStatusBarComponent(component);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment