Internal Client Exception with sync method

Hi,
I’m getting Internal Client Exception while using sync method find(dataQuery) in AsyncTask(){}.doInBackground.
When i’m using Async method all is fine. So there is my question. Can someone show me some example of using sync methods in new thread?
Bests

Have you seen this page in documentation?

https://backendless.com/documentation/data/android/data_basic_search.htm
Or you are using not android?

Stanislaw

I’m using android and yes i saw this page. But sync method should be putted in new thread to work correctly right?
So i made something like below:

new AsyncTask<Void, Void, Void>() { 
 @Override 
 protected Void doInBackground(Void... params) { 
 final MatchesListElement mle = parseMatchesListElement(); 
 if ( isUnique(mle)) { 
 Backendless.Persistence.save( mle ); 
 pd.dismiss(); 
 startActivity(intent); 
 
 } else { 
 pd.dismiss(); 
 Toast.makeText(getApplicationContext(), R.string.matchDuplicate, Toast.LENGTH_LONG).show(); 
 } 
 return null; 
 } 
}.doInBackground(); 

and isUnique throws Internal Client Exception

protected final boolean isUnique(final MatchesListElement MLE){
    long startDate = MLE.getStartDate().getTime();
    long endDate = MLE.getEndDate().getTime();

    String whereClause = "city = '" + MLE.getCity() + "' and  street = '" + MLE.getStreet() +
            "' and ((startDate after " + startDate + " and startDate before " + endDate +
            ") or (endDate after " + startDate + " and endDate before " + endDate + "))";

    BackendlessDataQuery dataQuery = new BackendlessDataQuery();
    dataQuery.setWhereClause( whereClause );
    Log.i("whereClause", dataQuery.getWhereClause());
    try {
        BackendlessCollection<MatchesListElement> matchesListElementBackendlessCollection = Backendless.Persistence.of(MatchesListElement.class).find(dataQuery);
        if ( matchesListElementBackendlessCollection.getCurrentPage().size() > 0) {
            return false;
        } else {
            return true;
        }
    } catch ( BackendlessException error){
        Log.e("isUnqiue Error", error.getCode());     
        return false;
    }
    
}

#Edited isUnique method

Hi,

I’ve created an internal ticket, soon our developer will contact you to help you resolve this issue.

Thanks Stanislaw!

Hi Łukasz,

Could you please provide where clause you try to execute and exect message you get after executing this query.
Also please provide your app id. You can sand it to support@backendless.com by email.

Regards,

Denys

As u can see in Code i published above:

 city = 'Lublin' and street = 'Skierki' and ((startDate after 1473924480000 and startDate before 1473931680000) or (endDate after 1473924480000 and endDate before 1473931680000))

It’s should return 0 records

but catch produce error : Internal client exception

Id already send via mail

Sync queries are restricted for Android.

Instead using sync call you can do following:

private void saveIfUnique(final MatchesListElement MLE)
{
	BackendlessDataQuery dataQuery = new BackendlessDataQuery();
	Backendless.Data.of( MatchesListElement.class ).find( dataQuery, new AsyncCallback<BackendlessCollection<MatchesListElement>>()
	{
	 @Override
	 public void handleResponse( final BackendlessCollection<MatchesListElement> response )
	 {
		if( response.getCurrentPage().isEmpty() )
		 save(MLE);
	 }

	 @Override
	 public void handleFault( final BackendlessFault fault )
	 {
		Log.e("isUnqiue Error", fault.getCode());
		Toast.makeText( getApplicationContext(), R.string.matchDuplicate, Toast.LENGTH_LONG ).show();
	 }
	} );
}

private void save(final MatchesListElement MLE)
{
	Backendless.Data.of( MatchesListElement.class ).save( MLE, new AsyncCallback<MatchesListElement>()
	{
	 @Override
	 public void handleResponse( final MatchesListElement response )
	 {
		
	 }

	 @Override
	 public void handleFault( final BackendlessFault fault )
	 {
		Log.e("Save Error", fault.getCode());
	 }
	} );
}

Regards,

Denys

That’s what i was doing before but nested Async looks a bit messy for me. I tried to avoid this. Where can i read about android sync restrictions? Any fast link?

Nevermind problem is fixed

#close