Hi Gaurav,

First of all you have to remove the semicolon at the end of the query:

SELECT getAllCountries()

instead of

SELECT getAllCountries();  < -


Then two simple questions:
1) are you trying to execute the query from Studio or from a client? You
should obtain a single record containing a collection as a result, so maybe
in Studio you will not be able to see it properly.
2) can you try this in Studio and tell me what you see?

SELECT expand(getAllCountries) from  (SELECT getAllCountries())

Regards

Luigi





2014-07-29 8:58 GMT+02:00 Gaurav Dhiman <[email protected]>:

> Hi Luigi,
>
> Thanks for inputs. Your response make sense. I was accessing request
> object in function body, hence the error.
> I altered the function and now below is the current code of
> getAllCountries() function.
>
>   var mc = db.query("SELECT FROM MasterCountry");
>   return mc;
>
> In this case, now when I try to invoke function using SQL << SELECT
> getAllCountries(); >>, below is the response
> { '@rid': { cluster: -2, position: 0 } }
>
> Although now I am not getting error as I removed the access to request
> object in function body, but still the response is not what I was
> expecting. When I call the same function over REST/HTTP, response returns
> all the countries data as shown below.
>
> {"result":[{"@type":"d","@rid":"#14:0","@version":15,"@class":"MasterCountry","name":"Afghanistan","code":"AF","resetFlag":true},
>  
> {"@type":"d","@rid":"#14:1","@version":2,"@class":"MasterCountry","name":"\u00c5land
>  Islands","code":"AX","resetFlag":true}, 
> {"@type":"d","@rid":"#14:2","@version":2,"@class":"MasterCountry","name":"Albania","code":"AL","resetFlag":true},
>  
> {"@type":"d","@rid":"#14:3","@version":2,"@class":"MasterCountry","name":"Algeria","code":"DZ","resetFlag":true},
>  
> {"@type":"d","@rid":"#14:4","@version":2,"@class":"MasterCountry","name":"American
>  Samoa","code":"AS","resetFlag":true}, 
> {"@type":"d","@rid":"#14:5","@version":2,"@class":"MasterCountry","name":"AndorrA","code":"AD","resetFlag":true},
>  
> {"@type":"d","@rid":"#14:6","@version":2,"@class":"MasterCountry","name":"Angola","code":"AO","resetFlag":true},
>  
> {"@type":"d","@rid":"#14:7","@version":2,"@class":"MasterCountry","name":"Anguilla","code":"AI","resetFlag":true},
>  
> {"@type":"d","@rid":"#14:8","@version":2,"@class":"MasterCountry","name":"Antarctica","code":"AQ","resetFlag":true},
>  
> {"@type":"d","@rid":"#14:9","@version":2,"@class":"MasterCountry","name":"Antigua
>  and Barbuda","code":"AG","resetFlag":true},
>
> ....
>
> ....
>
> ....
>
> ....
>
> ]}
>
>
> --
> Best Regards,
> Gaurav
>
>
>
>
> On Tue, Jul 29, 2014 at 12:03 PM, Luigi Dell'Aquila <
> [email protected]> wrote:
>
>> Hi Gaurav,
>>
>> I'd like to see your function code to be sure, but I guess you are trying
>> to access the "request" object (eg. trying to retrieve a request parameter).
>> Request object is not present when invoking a function inside a query.
>> Let me explain in depth, you can invoke JS functions in many ways:
>>
>> 1) as web services, like this:
>> http://localhost:2480/function/<dbname>/getAllCountries/
>>
>> 2) from inside a query, like this:
>> SELECT getAllCountries()
>>
>> 3) from Java API
>>
>> In the first case you are executing an HTTP request to the OrientDB REST
>> API, so "request" and "response" objects will be created by the server and
>> bound to the function context.
>> In the second (and other) case you are not in an HTTP request, so no
>> "request" and "response" objects will be available.
>>
>> Your stack trace suggests that you are trying to access a "request"
>> object that does not exist in the context. I suggest you to change your
>> function code checking if the "request" exists before using it.
>>
>> Regards
>>
>> Luigi
>>
>>
>>
>>
>>
>>
>>
>>
>> 2014-07-29 7:53 GMT+02:00 Gaurav Dhiman <[email protected]>:
>>
>>
>>>
>>> On Tue, Jul 29, 2014 at 3:33 AM, Enrico Risa <[email protected]>
>>> wrote:
>>>
>>>> Hi Gaurav
>>>>
>>>> try :
>>>>
>>>> SELECT getAllCountries() FETCHPLAN *:-1
>>>>
>>>
>>> It throws below error:
>>> com.orientechnologies.orient.core.command.script.OCommandScriptException:
>>> Error on parsing script at position #0: Error on execution of the script
>>> Script: getAllCountries ------^ --> javax.script.ScriptException:
>>> sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "request" is
>>> not defined. (#69) in at line number 69 -->
>>> sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "request" is
>>> not defined. (#69)
>>>
>>>  Regards,
>>> Gaurav
>>>
>>>
>>>>
>>>> Enrico
>>>>
>>>>
>>>> 2014-07-28 23:17 GMT+02:00 Gaurav Dhiman <[email protected]>:
>>>>
>>>>> Hi,
>>>>>
>>>>> I tried calling a JS function in OrientDB using below SQl command, but
>>>>> the result is different from what I get when I run the function directly 
>>>>> in
>>>>> OrientDB Studio.
>>>>>
>>>>> query -- SELECT getAllCountries FETCHPLAN *:-1
>>>>> result -- { '@rid': { cluster: -2, position: 0 } }
>>>>>
>>>>> What is wrong in above quer, why it is not returning the actual data ?
>>>>>
>>>>> If I run the same query in OientDB Studio, it returns the actual data.
>>>>>
>>>>> Regards,
>>>>> Gaurav
>>>>>
>>>>> --
>>>>>
>>>>> ---
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "OrientDB" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>>
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>  --
>>>>
>>>> ---
>>>> You received this message because you are subscribed to a topic in the
>>>> Google Groups "OrientDB" group.
>>>> To unsubscribe from this topic, visit
>>>> https://groups.google.com/d/topic/orient-database/GEUke7zon34/unsubscribe
>>>> .
>>>> To unsubscribe from this group and all its topics, send an email to
>>>> [email protected].
>>>>
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>  --
>>>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "OrientDB" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>  --
>>
>> ---
>> You received this message because you are subscribed to a topic in the
>> Google Groups "OrientDB" group.
>> To unsubscribe from this topic, visit
>> https://groups.google.com/d/topic/orient-database/GEUke7zon34/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to
>> [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>  --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "OrientDB" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to