-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a prepared statement instead of string replacement when :sql_last_value is provided #233
Comments
Any idea when this will be fixed/changed..? Looking forward to it. |
This question is relevant for us. Now there is no solution to this problem? |
Sequel being an ORM is mostly used to define DB interactions using objects that generate the SQL dialect statements that are then submitted for execution. For example:
This is usable if you are writing a web application that has a db schema design that the application itself enforces - the ORM bit because you will map a field on a html form to a column in a table or a value displayed in a web page to a column from a record in a catalogue etc. The Sequel docs show how to use prepared statements thus:
Now I don't yet know the implications of the "type" as set with
The example given in Sequel is shown using the SQL generation via the ORM. It is not easy to see whether In ETL/BI tools it is quite common to allow users to specify a SQL statement execute. This is useful because it is a kind of WYSIWYG mechanism - using some kind of interface to the DB one can build the statement until it yields the correct results or be given one by a DBA. Ironically, the statements that most benefit from being prepared are the most complex ones. It may be possible to build the prepared statement using the raw SQL statement as supplied by the user, I have not tried it but I suspect we will be moving into a different (underused) part of the Sequel code base. I can do some experiments but the big challenge is to get confidence because the basic tests in the plugin don't really verify the more complex statements out in the wild. Another concern is when |
I have had success in making this a reality. Testing on Postgres for now. Experimental plugin given out for testing. PR to follow. |
Have I got this right, that this was fixed..? Raul |
This might actually be not a bug in the code, but a poor documentation choice (if it's possible to provide the sql_last_value as part of the parameters hash with a ? placeholder instead of using :sql_last_value) - I'm not 100% sure.
According to the docs, something like this should be used to filter by sql_last_value:
However, contrary to my expectations, this doesn't use a prepared statement with a bind variable for sql_last_value - it does a string replacement instead, as can be seen in the logstash logs, as well as in the v$sql database view (I'm using Oracle):
thus generating a new unique SQL statement every time.
That leads to a couple of problems:
Logstash Version: 5.3.0
Operating System: Dockerized Linux (
FROM docker.elastic.co/logstash/logstash:5.3.0
)Suggested Fix
Use a prepared statement, and provide sql_last_value as a parameter. The underlying Sequel library provides the necessary infrastructure, as far as I can tell from the docs.
If necessary, I can provide further information and start working on a patch / pull request myself.
The text was updated successfully, but these errors were encountered: