Book a Demo

Author Topic: Running SQL Queries with Javascript scripts  (Read 5265 times)

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1405
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Running SQL Queries with Javascript scripts
« on: August 19, 2019, 06:55:08 pm »
Hi,

A client chose Javascript scripting in EA to define a custom feature.
I'm looking at improving the exec time by replacing method calls in time consuming loops with SQL queries.

I managed to create the DOM object, however I'm struggling to loop through the query results.
e.g.
Code: [Select]
var SQL = "select t_object.Name from t_object where t_object.Stereotype = 'test'"
var res = Repository.SQLQuery(SQL);
var xmlDOM = new COMObject( "MSXML2.DOMDocument" );
xmlDOM.validateOnParse = false;
xmlDOM.async = false;
if( xmlDOM.loadXML( res ) ){
var nodeList = xmlDOM.documentElement.selectNodes( '//Name' );
for ( var i = 0 ; i < nodeList.length ; i++ ){
LOGDebug(nodeList.item(i).text);
}
}

I'm getting a "nodeList.item is not a function" error. The same works with JScript.
Moving to JScript is not currently an option since the script contains a lot of code that only works with Javascript (fails running with JS)


Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com


Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Running SQL Queries with Javascript scripts
« Reply #1 on: August 20, 2019, 09:35:23 am »
Unfortunately, I remember coming across this one during the upgrade of the Javascript engine in EA15.

The Javascript engine didn't handle properties with arguments on wrapped com objects. (Yes, that's what it is, despite the documentation calling it a method. The C++ syntax having a "get_" prefix is the give away)

I suppose an upgrade to EA 15 is out of the question too?

Guillaume

  • EA Practitioner
  • ***
  • Posts: 1405
  • Karma: +42/-2
    • View Profile
    • www.umlchannel.com
Re: Running SQL Queries with Javascript scripts
« Reply #2 on: August 20, 2019, 04:20:00 pm »
Hi Eve,

I can confirm that it works with EA15 which could be used by those who need to run the script.

On the performance issues:
- is there globally a difference in using the VBScript, JScript or Javascript engine?
- running the same script from the Cloud Service (DB hosted in the cloud) versus a local copy (EAP) makes a big difference (5 times quicker). Is there any known trick that would help when using the shared EA Project to make this faster?

Thanks
Guillaume

Blog: www.umlchannel.com | Free utilities addin: www.eautils.com