Questions about the find(dataQuery) funtion

Hi,

I have a couple of questions about the use of find(dataQuery, async):

  1. Is there any way to use max() function as part of a query? I want to find a row with the highest date, how do I do that?

  2. I called find with a bad “condition” and I got called back in the success function of the Async function pair with a non-zero “code” and “message” properties. Shouldn’t this callback to the error function?

Thanks

Hallo, Paul!

  1. No, you cannot perform aggregation functions like max() for today. I can offer you the following: use sorting feature. Here is the link to docs: http://backendless.com/documentation/data/js/data_search_and_query.htm.
    Example: considering that you want to find row in table “YourClass” where property “requestDate” has minimum value (in Android):
QueryOptions options = new QueryOptions();
options.addSortByOption( "requestDate" ); // here is the property to sort by in ascending order

BackendlessDataQuery query = new BackendlessDataQuery();
query.setQueryOptions( options );

Backendless.Data.of( YourClass.class ).find(query, new AsyncCallback<BackendlessCollection<YourClass>>() {
    @Override
    public void handleResponse(BackendlessCollection<YourClass> yourClassBackendlessCollection) {
        YourClass first = personBackendlessCollection.getCurrentPage().get( 0 );
        System.out.println( first.getRequestDate() );
    }

    @Override
    public void handleFault(BackendlessFault backendlessFault) {
        System.out.println( "Searching failed with: " + backendlessFault.toString() );
    }
});
  1. Please, tell what kind of “bad condition” you mean? If you’re trying to use incorrect where clause - exception might not be thrown.

hope it would be helpful,
Alex Navara

Thanks, I will try the sort option.

Regarding “bad condition” - I meant the DataQuery.condition where clause had a syntax error in it, e.g. “id='FFF” - missing quote. I got a 1017 I think was the error with a message of bad where clause or something similar. The error callback (on the Async) wasn’t called, the success was called instead, with error properties. Is this normal?

Thanks

Hi, Paul!

Yes, you’re right - 1017 is code of error “invalid where clause”. But it’s not normal that success callback is called. Can you tell me what SDK do you use? And, if possible, provide part of code similar to yours.

Thank you!

I’m using the JavaScript SDK in nodejs. However, I am using an SDK version that I downloaded from another thread in this forum who had issue (different to me) and you fixed it by providing the new SDK.

This snippet of code reproduces the issue for me:

function doTest1017()
{
function GameType(args)
{
args = args || {};
this.type = args[“type”] || “”;
this.name = args[“name”] || “”;
}

var dataQuery = new Backendless.DataQuery();
dataQuery.condition = "xxx"


var async = new Backendless.Async(
	function(success)
	{
		console.log("success=" + JSON.stringify(success));
	},
	function(err)
	{
		console.log("err=" + JSON.stringify(err));
	}
);


var store = Backendless.Persistence.of(GameType);
store.find(dataQuery, async);

};

doTest1017();

Hi, Paul!

I cannot reproduce this issue using the latest JS SDK. Can you try with it?

My output is:

err={“message”:“Invalid where clause. Not Existing columns: xxx”,“code”:1017,“statusCode”:400}

Alex

Has there been an update to the SDK in the last couple of day? Because I only downloaded it 2 days ago and had issues with it working in nodejs. So I’m using a “fixed” SDK that I downloaded from a Support Topic for someone that had the same issues as I did with nodejs.

So do you suggest I get the latest again, has that been fixed for nodejs?

Thanks

No, there were no updates.
Please can you test this using attached SDK?
Also, can give me a link to SDK you’re using now? I’ll try to reproduce this issue with it.
Thank you!

backendless.zip (23.89kB)

The one I’m using is at the bottom of this post: http://support.backendless.com/t/node-js-httpsync-error

I’ll try yours. Thanks

I’ve tried yours - it also works as expected.
Can you reproduce the issue now?

With your SDK I get:

success={“0”:"{",“1”:""",“2”:“m”,“3”:“e”,“4”:“s”,“5”:“s”,“6”:“a”,“7”:“g”,“8”:“e”,“9”:""",“10”:":",“11”:""",“12”:“I”,“13”:“n”,“14”:“v”,“15”:“a”,“16”:“l”,“17”:“i”,“18”:“d”,“19”:" “,“20”:“w”,“21”:“h”,“22”:“e”,“23”:“r”,“24”:“e”,“25”:” “,“26”:“c”,“27”:“l”,“28”:“a”,“29”:“u”,“30”:“s”,“31”:“e”,“32”:”.",“33”:" “,“34”:“N”,“35”:“o”,“36”:“t”,“37”:” “,“38”:“E”,“39”:“x”,“40”:“i”,“41”:“s”,“42”:“t”,“43”:“i”,“44”:“n”,“45”:“g”,“46”:” “,“47”:“c”,“48”:“o”,“49”:“l”,“50”:“u”,“51”:“m”,“52”:“n”,“53”:“s”,“54”:”:",“55”:" “,“56”:“x”,“57”:“x”,“58”:“x”,“59”:”"",“60”:",",“61”:""",“62”:“c”,“63”:“o”,“64”:“d”,“65”:“e”,“66”:""",“67”:":",“68”:“1”,“69”:“0”,“70”:“1”,“71”:“7”,“72”:"}",“type”:"",“name”:""}

With the one I sent you, I get:

success={“type”:"",“name”:"",“message”:“Invalid where clause. Not Existing columns: xxx”,“code”:1017}

In both cases, the success callback fires.

Note: I am working in nodejs, that’s why the weird result above. This is apparently an issue with your standard SDK and nodejs that you are aware of and will fix in the next release.

Hi, Paul!

I’ve reproduced this issue and opened internal ticket for it. It’s going to be fixed in the next release.

regards,
Alex

Hello, Paul!

The issue is fixed. Please try the new library, version 2.0.1.
Here is the link: https://backendless.com/sdk/js/2.0.1/backendless-js-sdk.zip

best regards,
Alex Navara

Yes, it does appear to be fixed. Thanks!