Skip to Main Content

SQLcl: MCP Server & SQL Prompt

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Substitution variables in SQLcl Javascript

Erik van RoonApr 17 2021

Hope somebody can give me some insight in what I'm doing wrong.....
I'm playing around with some javascript scripts for SQLcl (disclaimer: I know little javascript).
According to (the comments in the script in) this post by Kris Rice:
https://krisrice.io/2016-11-30-sqlcl-custom-input-prompt-and/
the substitution variables that are defined in SQLcl can be accessed through a collection of type "map".
Awesome!
Now, according to this
https://javascript.info/map-set
a map has a number of methods and properties.
Of that list the get(), set() and size() work like a dream.
But has() and delete() tell me "null is not a function", see screenshot.
Why is this? What am I doing wrong or what am I misunderstanding?
Especially has() is one that I would really like to use.

Example with size() which works and has() which doesn't:
script
// Function writes text and an end-of-line to screen
function writeLine (line) {
ctx.write (line + "\n");
}

ctx.setSubstitutionOn(true);

writeLine ("Number of defined substitution variables: " + ctx.getMap().size());

if (ctx.getMap().has("MY_VAR")) {
writeLine ("Variable exists");
} else {
writeLine ("Variable does NOT exist");
}
/
sqlcl_substvar.png

Comments

Post Details

Added on Apr 17 2021
0 comments
274 views