In my application I show the route between point A to point B.
final PolylineOptions polyOptions = new PolylineOptions();
polyOptions.color(ContextCompat.getColor(mContext, R.color.accent_color));
polyOptions.width(20);
polyOptions.addAll(currentRoute.getPoints());
In currentRoute.getPoints I have all LatLng used to draw route on map. I extract all points that have 5km distance between them into a ListArray named points.
Now I want to populate along this route with locations from my database. I need to display all locations from my database that are on route or near it on 5km limit (on both sides of route).
For that I need to go to database and filter the records to find all locations that are in 5km range. I don't know how to implement WHERE request for location_latitude and location_longitude to can get all records that are on 5km range to reference location.
My current SQL is:
query = "SELECT location_id, location_name, " +
"location_address, location_image, " +
"location_latitude, location_longitude, " +
"c.category_marker, l.category_id " +
"FROM tbl_categories c, tbl_locations l " +
"WHERE l.category_id " + " = " + categ + " AND l.category_id = c.category_id AND " +
"location_county " + " = \"" + county + "\"";
Any suggestion how to filter faster my database (sql query) to find all locations near route?
I gone to this way:
where_query = new StringBuilder();
for (i = 0; i <= points.size()-1 ; i ++) {
if (i == 0) {
where_query.append(" AND ((location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append(")");
} else {
if (i < points.size() - 1) {
where_query.append(" OR (location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append(")");
} else {
where_query.append(" OR (location_latitude between ").append(points.get(i).latitude - 0.1).append(" AND ").append(points.get(i).latitude + 0.1).append(" AND location_longitude between ").append(points.get(i).longitude - 0.1).append(" AND ").append(points.get(i).longitude + 0.1).append("))");
}
}
}
Waiting suggestions!
Related
When victory line chart display the x-axis labels, the labels are on one line and I would like to display the label with text-wrapping. See the two images below to see what it is doing currently and what I would like for it to do.
Currently What is Happening
The image below is what I would like to happen. What I would like
I have created a function in the tickFormat to provide custom label text and that part is working.
<VictoryAxis fixLabelOverlap={true} tickFormat={t => this.formatLabel(t)} />
formatLabel = (t) => {
var x = new Date(t);
var s = x.getHours() + ":" + x.getMinutes() + (x.getMonth() + 1) + '/' + x.getDate();
return s;
}
You should be able to create a new line with a line break "\n"
formatLabel = (t) => {
var x = new Date(t);
var s = x.getHours() + ":" + x.getMinutes() +'\n'+ (x.getMonth() + 1) + '/' + x.getDate();
return s;
}
So im trying to write an update query that either updates the funds of a user based on if they have visa or MasterCard.
What im trying to state here, and which im thinking is what causes the error, is to update the sum if the current balance and wanted withdraw amount is less than 10.000. If that is not the case and the visa balance becomes less than 0, im creating an intentional error so that i can use it later to redirect the user to an error page (i know its not the most PC way to do it).
This is how the code looks:
const connection = require('../models/loginrouters');
function takeMoney(amount, cardnumber) {
// prettier-ignore
console.log("db cardnumber is".cardnumber)
console.log('db amount is', amount);
connection.query(
"UPDATE users.usercards SET Balance = CASE WHEN type = 'visa' AND balance>'" +
amount +
"' THEN Balance - '" +
amount +
"' ELSE CASE WHEN type='mastercard' AND SUM(balance - '" +
amount +
"')<'-10000' THEN Balance - '" +
amount +
"' ELSE 'NEIN CASH' END END WHERE CardNumber = '" +
cardnumber +
"';",
function(err) {
if (err) {
console.log('You too poor');
console.log(err);
} else {
console.log('You got the cash');
}
}
);
}
module.exports = takeMoney;
When this query is run I get the following error:
Error: ER_INVALID_GROUP_FUNC_USE: Invalid use of group function
The query is posted to me as:
sql: 'UPDATE users.usercards SET Balance =
CASE WHEN type = \'visa\' AND balance>\'1000\'
THEN Balance - \'1000\'
ELSE
CASE WHEN type=\'mastercard\' AND SUM(balance - \'1000\')<\'-10000\'
THEN Balance - \'1000\'
ELSE \'NEIN CASH\'
END
END
WHERE CardNumber = \'123456\';'
In advance, thanks for your response!
So as Gordon Linoff stated in a comment, I cannot use SUM in an update query. I just wrapped it in a () and it works perfectly.
TLDR; DONT use SUM in an update query.
connection.query(
"UPDATE users.usercards SET Balance = CASE WHEN type = 'visa' AND balance>'" +
amount +
"' THEN Balance - '" +
amount +
"' ELSE CASE WHEN type='mastercard' AND (balance - '" +
amount +
"')>'-10000' THEN Balance - '" +
amount +
"' ELSE 'NEIN CASH' END END WHERE CardNumber = '" +
cardnumber +
"';",
function(err) {
if (err) {
console.log('You too poor');
} else {
console.log('You got the cash');
}
}
);
}
I have 2 tables and I made a View Of them
My View Name is ViewMix
this code was for my table
var Qsearch = db.tbl_lessons.SqlQuery("select * from tbl_lessons where eTeacher in (" + teacher + ")");
that was correct
and now I want to run that query for my View
i wrote :
var Qsearch = db.ViewMix.SqlQuery("select * from ViewMix where eTeacher in (" + teacher + ")");
I got an error : "invalid object name 'ViewMix'"
I tried this too :
var Qsearch = db.ViewMix.SqlQuery("select * from dbo.ViewMix where eTeacher in (" + teacher + ")");
and got an error too :
"invalid object name 'dbo.ViewMix'"
what is the problem ?
I am developing an application on ReactNative, which works over geoquery. Simply, I am getting data with the help of geoquery then showing in FlatList.
But the problem is that I am using an state of array as,
this.state = {
data: []
}
How to add the keys I am getting from geoquery in this state of array.
I am using geoquery as,
geoQuery.on('key_entered', (key, location, distance) => {
console.log(key + " entered query at " + location + " (" + distance + " km from center)");
})
I want to add key getting from geoquery to an state of array, then get data of related key from firebase with the help of state of array containing key.
As per my understanding from your question, you can do something like below:
geoQuery.on('key_entered', (key, location, distance) => {
console.log(key + " entered query at " + location + " (" + distance + " km from center)");
this.setState({data: [...this.sate.data, key]});
})
I am developing mobile application in which I have used WebSql as local database. Now I am creating a search functionality where I want to escape "_" when the user will search the records. I tried using the MS-SQL approach by passing it in square bracket "[ _ ]"
Below are my code example
if ($.trim($('#txtPolicy').val()).length > 0) {
policy = $.trim($('#txtPolicy').val());
if (policy.indexOf("_") >= 0)
policy = policy.replace(/_/g, "[_]");
query += " (";
var arrploicy = policy.split(',');
for (var j = 0; j < arrploicy.length; j++) {
query += " policy like ? or ";
arr[i] = "%" + arrploicy[j] + "%";
++i;
}
query = query.substring(0, query.length - 3);
query += ") ";
}
I have a records which has data as 1234_456789. But it does not return any records, probably because it might be considering it as string.
You can use parameterized query without requering uou to escape. It is more secure too.