SQLite querying for exact matches - java

SQLite statement 'abc' LIKE 'ABCd' will return true. So my question is how to make an SQLite query that will return only exact record matches for a particular query.

The LIKE operator has two modes that can be set by a pragma. The default mode is for LIKE comparisons to be insensitive to differences of case for latin1 characters. Thus, by default, the following expression is true:
'a' LIKE 'A'
But if the case_sensitive_like pragma is enabled as follows:
PRAGMA case_sensitive_like=ON;
Then the LIKE operator pays attention to case and the example above would evaluate to false.

for exact record match you need to use = sign.
ex : abc = abc.
and if you want all records which contain abc words. You need to write
abc like '%abc%' in your sqllite query.

Related

KNIME: Compare if One Column Contains a subset of another column

In Knime I am trying to compare if a value in one column is contained within another column. I tried to do this using "LIKE" in the Rule Engine but couldn't get the wildcards to work with a column input instead of a string. E.g.
For row1 I want to check if column 1, row 1 is within column 2, row 1
For row2 I want to check if column 1, row 2 is within column 2, row 2
Like is "ABC" contained within "test ABCtest"
Does the "LIKE" in Rule Engine only allow hard coded strings for comparison? Other ideas to achieve this? Thank you for the help!
The String Manipulation node with the regexMatcher can help here, though the result will be String (with values True/False by default), so further node will be required if for example a number is required (if different String, you can use the ?/: ternary operator like == "True" ? "when true" : join("when false it was because '", $columnReference$, "' was not found")).
You can use regexMatcher like this (\Q/\E helps to avoid treating the content in Reference column as a regular expression (except when it contains \E)):
regexMatcher($text$, join(".*?\\Q", $Reference$, "\\E.*+")) == "True" ? "vrai" : "faux"
Rule engine allows wildcards with LIKE operator but it does not allow wildcards combined with columns meaning the following will work fine:
$column1$ LIKE "*test*" => "1"
The following is allowed as well but will not work fine:
$column1$ LIKE "*$column2$*" => "1"
The reason is when you got double quotes $ is not recognized so you do not get the values from column2. Instead you get same string each time: "*$column2$*" which is not what you want.
Additionally you can use indexOf() function in String Manipulation or Column Expressions node that will return the first position of string value from column1 in column2. If not found the function will return -1. Follow it with Rule Engine node to add appropriate indication.

How to nest a query with Neo4j?

I am trying to do a sort of nested Neo4j query in Java, which first labels a subset of nodes and then tries to match certain patterns among them. More specifically it is like combining 2 queries of this type:
1 - MATCH (n)-[r:RELATIONSHIP*1..3]->(m) set m:LABEL
2 - MATCH (p:LABEL)-[r2:RELATIONSHIP]->(q:OTHERLABEL) where r2.time<100 return p,r2,q
Is there a way I can merge these two query in only one using the Java function engine.execute() ?
'p' in query #2 will, in general, correspond to a superset of 'm' in query #1. If that is your intention, then the following should work. Notice that the 2 MATCH statements have no common variables, but a WITH is required by the Cypher syntax, so I arbitrarily picked the variable 'm' to pass to the second MATCH (even though it will be ignored).
MATCH (n)-[r:RELATIONSHIP*1..3]->(m)
SET m:LABEL
WITH m
MATCH (p:LABEL)-[r2:RELATIONSHIP]->(q:OTHERLABEL)
WHERE r2.time<100
RETURN p,r2,q;
If you intend 'm' and ''p' to be the exactly the same, then just replace '(p:LABEL)' with '(m)':
MATCH (n)-[r:RELATIONSHIP*1..3]->(m)
SET m:LABEL
WITH m
MATCH (m)-[r2:RELATIONSHIP]->(q:OTHERLABEL)
WHERE r2.time<100
RETURN m,r2,q;

regex to find integers in string not matching

I have two tables' contents stored in Stringbuffers. One has data in it; the other is only a header. I converted the Stringbuffers into Strings and removed whitespace.
table1:
ACCOUNT_NUMBER;BRANCH_CODE;RECALC_ACTION_CODE;RECALC_DATE;PROCESS_NO;PRINCIPAL_CHG_AMXX23QRUP120970003;023;E;05.09.2013;1;-522.53
table2:
ACCOUNT_NUMBER;BRANCH_CODE;MSG_TYPE
I only want to proceed with a table if it has data in it, like table1.
To check for data (i.e integers) I used regex: table1.matches("\\d"), but this returns false. I also tried table1.matches("(?s)\\d")), for new line character but even this returns false.
How can I check for integer data in the strings?
Read the documentation on matches. The "match" requires the entire string to match, and so your table1.matches("\\d") fails -- "table1" is not 'one digit only'.
Use table1.matches(".*\\d.*") instead. Note the double backslash! You might not be aware they need escaping in a String constant.

Catch-all second alternative for my start rule

I'm trying to write an ANTLR grammar for a little query language. Queries are a list of search terms restricted to specific fields:
field1:a field2:b field3:c
That's supposed to return a list of entities where field1 matches a, field2 matches b, and so on. Queries can also be completely unrestricted:
abc
That's supposed to return entities with any field that matches abc. Here's the ANTLR grammar:
#members {
String unrestrictedQuery;
}
FIELD1_OPERATOR: 'field1:';
FIELD2_OPERATOR: 'field2:';
FIELD3_OPERATOR: 'field3:';
DIGIT: '0'..'9';
LETTER: 'A'..'Z' | 'a'..'z';
query: subquery (' ' subquery)*
| UNRESTRICTED_QUERY=.* {unrestrictedQuery = $UNRESTRICTED_QUERY.text;}
;
I want unrestricted queries to be any text that doesn't match the query rule's first alternative.
1) Is there a better way to grab the text that the second alternative matched?
2) When I plug this into my web server, the unrestrictedQuery parser field resolves to the last character of the query. It seems like the action gets called for every character of the query when I really want the whole string.
Thanks for reading!
"I want unrestricted queries to be any text that doesn't match the query rule's first alternative".
This is a bad design decision. What if in future, you want to add Field4? Then incompatibility occur. Better change the grammar so that unrestricted queries are easily recognized. Surround field values (a, b, c) with quotes, or start unrestricted query with a colon:
field1:a :abc field2:b

Exact match with sql like and the bind

I have a bind in the SQL query
SELECT * FROM users WHERE name LIKE '%?%'
the bind set the ?.
Now, if i want to search with like method everything work but if, without change the sql, i want to search the exact match i dont now how to do.
I tried some regexp int the textbox es:
_jon \jon\ [jon] and some others but nothing work properly.
Any ideas?
Change your query to
select * from users where name like '?'
If you want to do a wildcard match, put the wildcards as part of the string that you're binding to the variable. If you don't want to do a wildcard match, then don't.
Note that like and = have the same performance except when your wildcard character is first in the string (for example, '%bob') as in that case the query optimizer can't use indexes as well to find the row(s) that you're looking for.
you can't search an exact match if the sql contains % symbols, as they are wildcards. you'll need to change the sql to
select * from users where name = '?'
for an exact match
(you can also use select * from users where name like '?' but that's more inefficient)
What is keeping you from changing the SQL?
The Like condition is for 'similar' matches, while the '=' is for exact matches.

Categories