US and Worldwide: +1 (866) 660-7555
Results 1 to 6 of 6

Thread: how read row resultset in javascript

  1. #1
    Join Date
    Jan 2010
    Posts
    27

    Question how read row resultset in javascript

    Hi.

    I have the follow js code.

    var strConn = "MY Connection";
    var strSQL = "SELECT COUNT(*) FROM ...";
    var xArr = fireToDB(strConn, strSQL);

    How I can read resultset? I can't find out any example.
    I have tried with a for, but the xArr.length return an undefined value.
    Which kind of java object is xArr?

    Alert (xArr.length);
    for (i=0;i<xArr.length;i++){
    Alert("inside for");
    }

    Could anyone help me?


    Thanks


    Gisella
    Last edited by bronzett; 07-08-2010 at 09:08 AM.

  2. #2
    Join Date
    Sep 2009
    Posts
    809

    Default

    Hi there,

    check out this post, it has an example of how to use the fireToDb function

    http://type-exit.org/adventures-with...-and-firetodb/

    Cheers

    Slawo

  3. #3
    Join Date
    Jan 2010
    Posts
    27

    Cool

    excellent!!!!

    Thank you Slawo

  4. #4
    Join Date
    Jan 2010
    Posts
    27

    Default

    Only one other question about fireToDb.

    I have tried your transformation and it works, but if I just want debug the script with some Alert(xArr[i][0]);

    then I get an exception and I can't explain me why.


    Errore inatteso :
    org.pentaho.di.core.exception.KettleValueException:
    Errore javascript:
    Java class "java.lang.Class" has no public instance field or method named "0". (script#12)
    at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.addValues(ScriptValuesMod.java:436)
    at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.processRow(ScriptValuesMod.java:667)
    at org.pentaho.di.trans.step.BaseStep.runStepThread(BaseStep.java:2889)
    at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.run(ScriptValuesMod.java:730)
    Caused by: org.mozilla.javascript.EvaluatorException: Java class "java.lang.Class" has no public instance field or method named "0". (script#12)
    at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
    at org.mozilla.javascript.Context.reportRuntimeError(Context.java:922)
    at org.mozilla.javascript.Context.reportRuntimeError(Context.java:978)
    at org.mozilla.javascript.Context.reportRuntimeError2(Context.java:948)

  5. #5
    Join Date
    Sep 2009
    Posts
    809

    Default

    Hi there,

    I tried to Alert(xArr[i][0]) in the demo transformation, and it worked fine. Without seeing your script and query I cannot tell what exactly is wrong with it. You'd have to remember that you are between worlds here: the javascript world and the java world. The scripting engine is trying its best to give you access to java objects and is doing some automatic conversions. Javascript arrays vs. Java arrays, automatic string conversions, etc. This can sometimes lead to strange error messages when trying to access invalid objects or indexes, for example.

    If you'd post an example script I might be able to help with it.

    Cheers

    Slawo
    Last edited by slawomir.chodnicki; 07-08-2010 at 02:44 PM.

  6. #6
    Join Date
    Jan 2010
    Posts
    27

    Default

    Morning Slawo.

    We tried the same code (I'm using PDI 3.2).


    // for each row, save the returned rule for later use
    for (var i in xArr){
    Alert(xArr[i][0]);
    regex.push(xArr[i][0]);
    }


    I noticed that the error I posted is thrown when I test the script by the "Test Script" button inside the js step. On the contrary if I execute the full transformation all work perfectly.
    May be the js test do not load all the lib it need.


    Grazie


    Gisella

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •