I am trying to create a regex filter for my app. I am using HSQLDB to store my messages and regex.pattern[1] class to match the incoming messages. I noticed that regex.pattern and LIKE in HSQLDB uses diferent matching "teqniques".
Example
I want to match: {"auth_user":"YQ==","auth_pass":"ZGFz"}.
With HSQLDB: SELECT * FROM messages LIKE %auth%
With regex.pattern: \bauth or auth
My Questions
Is there any way to get the input from user and query with RLIKE or REGEX in HSQLDB?
Is there any easily way to convert regex.pattern in HSQLDB query?
[1] https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
Thank you in advance.
EDIT 1: The messages I get are not only JSON formated.
EDIT 2: I tried REGEXP_MATCHES like #JorgeCampos and #fredt mention to me but I get the following exception
SQL Error [S1000]: java.lang.ClassCastException: org.hsqldb.types.ClobDataID cannot be cast to java.lang.String
when I execute the following command
SELECT * FROM WEBSOCKET_MESSAGE WHERE REGEXP_MATCHES(PAYLOAD_UTF8, '^a.*');
Use REGEXP_MATCHES(column_name, regular_expression)
The function uses Java regular expression syntax.
If the column type is CLOB, use a cast to VARCHAR
REGEXP_MATCHES(CAST (column_name AS LONGVARCHAR), regular_expression)
Related
Is there any source, where I can get list of all errorCode/errorMessage in MySQLException (io.vertx.mysqlclient)
For ex:
1062 is MySQL Duplicate Key
While you asked for vert.x codes, probably source material- MySql Error reference would help https://dev.mysql.com/doc/mysql-errors/8.0/en/ There are server and client side as well as global error codes listed there.
Also, check out https://github.com/sambrmg/mysql-error-codes/blob/master/index.js
In MySQL %s represents a String ID and %d is representing a primary key(usually) decimal.
1062 is about an identical column value as an id column or such like.
https://dev.mysql.com/doc/mysql-errors/8.0/en/client-error-reference.html
Get the PDF download of this page in the left column of all the error codes.
note: If you use PHP it has similar numeric error messages (just to not confuse it).
note: https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html
https://dev.mysql.com/doc/mysql-errors/8.0/en/global-error-reference.html for mysql errors.
Also, I had same error code from MariaDB, and found this link useful. https://mariadb.com/kb/en/mariadb-error-codes/#shared-mariadbmysql-error-codes
I've got a database with names in it. These names sometimes contain non ascii characters e.g. González. I've got the collation settings such that if I search for WHERE LastName LIKE '%Gonzalez%' I get González's record back. In Management Studio I can search for both WHERE LastName LIKE '%Gonzalez%' and WHERE LastName LIKE '%González%' and both return the correct value. However when I use JPA / Hibernate the query that gets sent to the database clearly doesn't represent the á character correctly as I get 0 results.
When utilising the show_sql attribute I can see the actual query is fine, and If I copy and paste that query and replace the ? characters with '%González%' I get the correct results. Likewise if I search for Gonzalez through the web interface I get results, so I'm confident it's the á that is causing me problems, and it's only JPA / Hibernate that is causing the issue. (Having said that the issue could be the AJAX submission to the servlet that is causing the issue, but the parameter is sent as ?LastName=Gonz%C3%A1lez which I think is right?)
So if it's JPA / Hibernate how do I diagnose / fix the issue?
The show_sql logging configuration attribute only lets you see the formatted SQL statement, generated by Hibernate. To troubleshoot the problem further, you need to make sure the values, hibernate replaces the *'?'*s with, are actually correct. Look at the thread on how to see param values in hibernate log and adjust your application log settings.
The second step I'd suggest to add - is in your AJAX request, encode all your params as Base64 string, and then decode it back to UTF-8 string on the controller, handling the request.
The flow of logic should be as follow:
Client receives input 'González'
client encodes the input into 'R29uesOhbGV6' and passes it in AJAX request
controller, handling the request, decodes the parameter back to 'González'
controller passes the value down to hibernate logic, where hibernate generates SQL and executes it
in the application log, you see that hibernate actually passes 'González' parameter down to the database
I am now using solr to query .I want to find all the documents whose key "title" contains text "Bifidobacterium bifidum" or key "abstract" contains text "Bifidobacterium bifidum".So , I write my query like below:
String queryCondition = "title:*Bifidobacterium bifidum* OR abstract:*Bifidobacterium bifidum*";
From the result ,I find out that the returned result is not what I want ,documents whose title contains "Bifidobacterium" or "bifidum" , or whose title contains "Bifidobacterium" or "bifidum" are all returned . So , my question is ,how should I write my query to satisfy my query need?
The * is special symbol, a wildcard. Similar to regular expressions, it tells Solr to match everything. So querying for bifidum* would return everything that starts with bifidum. Not what you want, right?
When reading about Solr's query syntax in the manual, you will find a section named Specifying Terms for the Standard Query Parser there is written
A phrase is a group of words surrounded by double quotes such as "hello dolly"
This is what you need ...
I am using the webservice that will send the request for one of the column as Dran & Hyle , but i get the exception as a expected valid begining name character. due to the special character &
Below is the insert statement in my java .
public static final String PetInsert= insert into pet values(?,?,?);
I believe set define off will not work in java code , it is understood only by sql developer.
Any help is appreciated
From Java, it is recommended to use PreparedStatement when creating a statement to query the database. Read more in the documentation.
Not so sure, but can it be that in the XML of the web service the error is located? Then somewhere
"Dran & Hyle"
should go into the XML. Normally it is done automatically. So it would be the unlikely case of creating the XML oneself with Strings.
In that case use apache's StringEscapeUtils:
s = StringEscapeUtils.escaleXML(s);
P.S. I found set define off of #aUserHimself plausible.
I need to be able to refer to a table on a different schema, using OpenJPA to access a Sybase db.
So, for example, I need to select as follows:
SELECT name FROM SHARE.dbo.PROVINCE;
However, the generated SQL is:
SELECT name FROM "SHARE.dbo".PROVINCE;
which Sybase rejects. Without the quotes it works fine.
I'm using the following annotations on the class:
#Entity
#Table(name="PROVINCE", schema="SHARE.dbo")
using schema="SHARE" doesn't work, although it generates the sql without any quotes. (Sybase requires schema.owner.table, so SCHEMA.PROVINCES is an unknown object)
Any thoughts on how to resolve this issue?
Try concatenating the schema to the table name: #Table(name="SHARE.dbo.PROVINCE")
This is a bit of a shot in the dark, but you could try to disable delimited identifier support?
openjpa.DBDictionary=sybase(SupportsDelimitedIdentifiers=false)