I have a query like this:
"select * from aaa where id < 10 and name = 'test'"
From this query I want to find out the number of conditions after where
(2 in this case).
Also I want to find out how many times <
and =
were repeated.
I have a query like this:
"select * from aaa where id < 10 and name = 'test'"
From this query I want to find out the number of conditions after where
(2 in this case).
Also I want to find out how many times <
and =
were repeated.
you can simply count all the > and = with a loop
bool whereCondition = false;
int counterCompare = 0;
int counterConditions = 0;
// select is your SQL String
for(int i = 0;i<select.length;++i)
{
if(whereCondition){
if(select.charAt(i) = '<' || select.charAt(i) = '>') {
++counterCompare;
}
if(select.charAt(i) = '=' && !(select.charAt(i+1) = '<' || select.charAt(i+1) = '>')) {
++counterCompare;
}
if (select.charAt(i) = 'A') {
if(i+2 < select.length) {
if(select.charAt(i+1) = 'N' &&
select.charAt(i+2) = 'D')
++counterCondition;
}
}
if (select.charAt(i) = 'O') {
if(i+4 < select.length) {
if(select.charAt(i+1) = 'R' &&
select.charAt(i+2) = 'D' &&
select.charAt(i+3) = 'E' &&
select.charAt(i+4) = 'R' &&)
whereCondition = false;
}
}
}
else {
if (select.charAt(i) = 'W') {
if(i+4 < select.length) {
if(select.charAt(i+1) = 'H' &&
select.charAt(i+2) = 'E' &&
select.charAt(i+3) = 'R' &&
select.charAt(i+4) = 'E' &&)
whereCondition = true;
}
}
}
}
i don´t promise this code to work. you also have to deal with a where conditions based on order or an And compare. so you need to check, if you found an And , if it´s not a String you´re comparing in your table. you also have to check if you got small or tall letters. but this is just a basic compare