Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

Sending Multiple Variables into a single WHERE clause for a DB Query

I am trying to run Example 1 under Geospatial Queries found at http://docs.appery.io/documentation/b...

However, I want to enter three variables instead of three constants into the WHERE clause : the lat and long for $nearSphere and the $MaxDistanceinMiles.

From the example:

Query 1 (80 miles diameter around Vienna):

{
"location" : {
"$nearSphere" : [48.208, 16.373],
"$maxDistanceInMiles" : 80
}
}

I do not see documentation regarding placing more than one variable into the WHERE clause. Could you point me to documentation that would provide details on how to achieve this?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Sending Multiple Variables into a single WHERE clause for a DB Query

Hello! Sorry for delay, working on it.

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Sending Multiple Variables into a single WHERE clause for a DB Query

Hi, you would need to add JS in mapping for parameter "where" and form string as you need:
codereturn '{ "asdf" : { "$nearSphere" : [48.208, 16.373], "$maxDistanceInMiles" : 80 } } ';/code

You can also get all data previously from local storage and set it in returned string. For example:
codevar lat = localStorage.getItem('lat'), long = localStorage.getItem('long');
return '{ "asdf" : { "$nearSphere" : [' + lat + ', ' + long + '], "$maxDistanceInMiles" : 80 } } ';/code

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

Sending Multiple Variables into a single WHERE clause for a DB Query

ok, that's good info.

I am trying to do a test with the following QueryService I created

I am starting with the static request (no variables):

return '{ "location" : { "$nearSphere" : [' 33 ', ' -117'], "$maxDistanceInMiles" : 80 } } ';

and am getting the error "incorrect query".

{
"status":"400 Bad Request",
"url":"https://api.appery.io/rest/1/db/colle...",
"response":{
"code":"DBSQ219",
"description":"Incorrect query"
}
}

Database Content:
I have a database table ('profiles') that has the column 'location' [type:geopoint] with 2 entries:
user_name: diamond, location:[33,-117.23]
user_name: gold, location:[33,-116.77]

***note: I entered the geopoints myself because I did not know how to put the lat and long in as a geopoint (we can talk about that later), so it is possible they may be formatted incorrectly, but when I entered them in the database I received no error code.

Can you tell me why the test query might be incorrect?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Sending Multiple Variables into a single WHERE clause for a DB Query

Hi Christopher,

Try the following request:
codereturn '{ "location" : { "$nearSphere" : [33, -117], "$maxDistanceInMiles" : 80 } } ';/code

Be carefully with quotes. In your example, there were a number of problems:
' 33 ' - 33 is surrounded by spaces
'33 '- This is a string, while you need the number. So quotes there are unacceptable.

Let us know about the result please

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

Sending Multiple Variables into a single WHERE clause for a DB Query

Hi Katya,

I tried

code
return '{ "location" : { "$nearSphere" : [33, -117], "$maxDistanceInMiles" : 80 } } ';
/code

as you posted above, but still got

{
"status":"400 Bad Request",
"url":"https://api.appery.io/rest/1/db/colle...",
"response":{
"code":"DBSQ219",
"description":"Incorrect query"
}
}

Any thoughts?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Sending Multiple Variables into a single WHERE clause for a DB Query

Hi Christopher,

Please open the collection in database and run your request there. Enter the following line without single quotes:
code{ "location" : { "$nearSphere" : [33, -117], "$maxDistanceInMiles" : 80 } }/codeand send us a result screen shot please.

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

Sending Multiple Variables into a single WHERE clause for a DB Query

No problem. Screen shot is below. It appears that the Lat and Long are reversed. This is a bit presumptuous, but I think I have it right (based on geopoint lat long documentation and the geopoint query documentation on appery) and that it the error handling for this call on appery is incorrect. What do you think?

Image

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Sending Multiple Variables into a single WHERE clause for a DB Query

Hi Christopher,

Sorry, could you tell us where you found the reverse order please? There seems to be a typo in our docs. The order has to be changed.

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

Sending Multiple Variables into a single WHERE clause for a DB Query

Hi Katya,

I think I was mistaken and your documentation is correct or at least does not directly specify a longitude and latitude in the Geospatial Queries at http://docs.appery.io/documentation/b...

It might be worth more overt specification of the order of longitude and latitude for this geospatial query functionality because the geopoint class which holds both the longitude and latitude data as described by google is in the opposite order, if I am making relevant comparisons (which I may not be).
https://developers.google.com/appengi...

With your help (thank you), I have gotten the "location" query functionality to work at the level of the testing tab using

code{ "location" : { "$nearSphere" : [-117, 33], "$maxDistanceInMiles" : 15 } }/code

Now time to implement variables into the query! I will write back soon as I work my way down that path.

Return to “Issues”