Scripting enhancement - assign a variable the value of other variables
GStegemann opened this issue · 4 comments
Hello,
in a script I need to save results from a database query for a next query. For this it would be great to store the value of a result variable to another variable bound as input.
Sample:
-- Result variables
:variable1 COLUMN LONG;
:variable2 COLUMN LONG;
:variable3 INPUT LONG;
-- Check if current host is defined in table OBJECTS
:select on;
select parentid,objectid from OBJECTS where classname = 'Flink' and objectname = 'HOSTXX';
-- Is it the right value?
:if variable2 = 0;
:print 'ERROR: No such host in Objects';
-- Exit now
:if variable2 = 0;
:file close;
:if variable2 = 0;
:exit;
-- Next test if application is already defined
select objectid from OBJECTS where classname = 'Flapp' and objectname = 'XxxApp';
:variable3 = variable2;
:if variable1 = 0;
:print 'No such application in Objects';
Would it be possible to implement this feature?
Thank you for the request. And yes: of course: it is possible (We can go to the moon, so this should be easy :-)
Placed the request on the backlog.
Stay tuned.
Thanks for considering my request.
As you may have seen from my sample script I attempted to use ":if" statements in different ways, not only together with ":print" statements, but also for any other kind of statements. But however that does not work, since ":if" statements have only an effect on succeeding ":print" statements. I discovered this later after some testings and reading the scripting documentation several times. That's one more thing.
A third wish is to have an "equal" operator for the ":if" statement. I have implemented the following patch as a proposal:
diff --git a/QueryTool/OpenEditor/OEView_7.cpp b/QueryTool/OpenEditor/OEView_7.cpp
index 866f29a..c7a618e 100644
--- a/QueryTool/OpenEditor/OEView_7.cpp
+++ b/QueryTool/OpenEditor/OEView_7.cpp
@@ -1474,6 +1474,7 @@ bool
COEditorView::ScriptCommandIf(int p_line,CString command)
{
bool result = false;
+ int i_compare = 0;
CString error;
command.Trim();
@@ -1489,7 +1490,15 @@ COEditorView::ScriptCommandIf(int p_line,CString command)
{
SQLVariant* var = it->second;
int pos = command.Find(_T("<>"));
- if(pos > 0)
+ if (pos > 0)
+ i_compare = 1; // Compare type not equal
+ if (pos == -1)
+ {
+ pos = command.Find(_T("=="));
+ if (pos > 0)
+ i_compare = 2; // Compare type equal
+ }
+ if (pos > 0)
{
command = command.Mid(pos + 2);
command.Trim();
@@ -1498,7 +1507,10 @@ COEditorView::ScriptCommandIf(int p_line,CString command)
CString value;
var->GetAsString(value);
- m_scriptCompare = (command.Compare(value) == 0);
+ if (i_compare == 1)
+ m_scriptCompare = (command.Compare(value) == 0);
+ if (i_compare == 2)
+ m_scriptCompare = (command.Compare(value) != 0);
m_ifLast = true;
if(m_scriptOutput && m_scriptOutput->GetIsOpen())
{
It would be great if you could review it and place this request also in you backlog.
Hello Edwig,
Many thanks. I will try the changes after my vacation.
Best regards,
Gerhard
I performed some short tests. The scripting extensions do work.
Now I will try to complete my script and see if the extensions do work for me.