Comments (13)
FYI: Changing the query to "SELECT DISTINCT ?" works...
from pgjdbc-ng.
Unfortunately this is how PostgreSQL itself works and the current driver works around it. Currently you must explicitly provide the type, through a means such as casting, for unknown parameters (e.g. SELECT ?::int ). Given this solution, this has not arose as a large issue for me. Would this solve your problem as well?
On Aug 26, 2013, at 1:45 AM, Andreas Joseph Krogh [email protected] wrote:
The following test fails:
public void testSetIntegerFails() throws Exception { String sql = "SELECT ?"; PreparedStatement ps = conn.prepareStatement(sql); ps.setInt(1, 1); ps.executeQuery(); }
Some ORMs generate queries like this:
SELECT ..... WHERE a.id = $1 AND EXISTS (SELECT $2 FROM my_entity WHERE ...)
and then issue a "ps.setInt(2, 1)"This works fine with the old, official, driver but fails with pgjdbc-ng which makes using this driver with ORMs difficult.
Thanks.
—
Reply to this email directly or view it on GitHub.
from pgjdbc-ng.
No, this does not solve my problem as it's EclipseLink that is creating these SQL-statements and I have no control over them. If the current, official, driver works around it, why cannot pgjdbc-ng do the same?
from pgjdbc-ng.
Is this something you'll get around to look at or should I go bark up the EclipseLink tree and explain the issue to them? I expect this issue will bite quite a few developers trying out your new, excellent, driver and hope you'll find a similar workaround as the official driver.
The reason for me nagging is that right now I cannot deploy my app because either Blobs won't work with the official driver (because it doesn't implement Connection.createBlob) or some generated queries won't work with your NG-driver. If you don't plan on looking into this, please say so, then I can go persuading the EL-people to generate "SELECT ?::int"-queries for situations like this. I expect that to take much longer time though.
Thanks.
from pgjdbc-ng.
I am looking into this. I'll update you in a day or so to see where it stands.
from pgjdbc-ng.
Cool!
I wish the official driver guys were as responsive as you:-)
from pgjdbc-ng.
I think I have found finally found a workable solution! I have committed it in 7511c37 . Can you please test this and let me know if it works for you?
from pgjdbc-ng.
Sorry for not seeing this before. Will test now!
from pgjdbc-ng.
It doesn't work for a query generated by EclipseLink:
LOG: statement: BEGIN
ERROR: could not determine data type of parameter $2
STATEMENT: SELECT t0.entity_id, t0.type, t0.VERSION, t1.entity_id, t1.attachment_size, t1.body_hash, t1.body_size_octets, t1.message_id, t1.plain_text_content, t1.sent_timestamp, t1.message_as_string, t1.from_entity_id, t1.forwarded_from_id, t1.replyto_id, t1.envelope_from_id FROM origo_email_folder_message t4, origo_email_delivery t3, onp_crm_entity t2, origo_email_message t1, onp_crm_entity t0 WHERE (((t4.folder_id IN ($1)) AND NOT EXISTS (SELECT $2 FROM origo_email_message_property t5 WHERE (((t5.is_seen = $3) AND (t5.owner_id = $4)) AND (t5.message_id = t0.entity_id))) ) AND (((t2.entity_id = t4.delivery_id) AND ((t3.entity_id = t2.entity_id) AND (t2.type = $5))) AND ((t0.entity_id = t3.message_id) AND ((t1.entity_id = t0.entity_id) AND (t0.type = $6)))))
And it somehow goes into endless loop:
ERROR: current transaction is aborted, commands ignored until end of transaction block
STATEMENT: SELECT t0.entity_id, t0.type, t0.VERSION, t1.entity_id, t1.attachment_size, t1.body_hash, t1.body_size_octets, t1.message_id, t1.plain_text_content, t1.sent_timestamp, t1.message_as_string, t1.from_entity_id, t1.forwarded_from_id, t1.replyto_id, t1.envelope_from_id FROM origo_email_folder_message t4, origo_email_delivery t3, onp_crm_entity t2, origo_email_message t1, onp_crm_entity t0 WHERE (((t4.folder_id IN ($1)) AND NOT EXISTS (SELECT $2 FROM origo_email_message_property t5 WHERE (((t5.is_seen = $3) AND (t5.owner_id = $4)) AND (t5.message_id = t0.entity_id))) ) AND (((t2.entity_id = t4.delivery_id) AND ((t3.entity_id = t2.entity_id) AND (t2.type = $5))) AND ((t0.entity_id = t3.message_id) AND ((t1.entity_id = t0.entity_id) AND (t0.type = $6)))))
ERROR: current transaction is aborted, commands ignored until end of transaction block
STATEMENT: SELECT t0.entity_id, t0.type, t0.VERSION, t1.entity_id, t1.attachment_size, t1.body_hash, t1.body_size_octets, t1.message_id, t1.plain_text_content, t1.sent_timestamp, t1.message_as_string, t1.from_entity_id, t1.forwarded_from_id, t1.replyto_id, t1.envelope_from_id FROM origo_email_folder_message t4, origo_email_delivery t3, onp_crm_entity t2, origo_email_message t1, onp_crm_entity t0 WHERE (((t4.folder_id IN ($1)) AND NOT EXISTS (SELECT $2 FROM origo_email_message_property t5 WHERE (((t5.is_seen = $3) AND (t5.owner_id = $4)) AND (t5.message_id = t0.entity_id))) ) AND (((t2.entity_id = t4.delivery_id) AND ((t3.entity_id = t2.entity_id) AND (t2.type = $5))) AND ((t0.entity_id = t3.message_id) AND ((t1.entity_id = t0.entity_id) AND (t0.type = $6)))))
ERROR: current transaction is aborted, commands ignored until end of transaction block
STATEMENT: SELECT t0.entity_id, t0.type, t0.VERSION, t1.entity_id, t1.attachment_size, t1.body_hash, t1.body_size_octets, t1.message_id, t1.plain_text_content, t1.sent_timestamp, t1.message_as_string, t1.from_entity_id, t1.forwarded_from_id, t1.replyto_id, t1.envelope_from_id FROM origo_email_folder_message t4, origo_email_delivery t3, onp_crm_entity t2, origo_email_message t1, onp_crm_entity t0 WHERE (((t4.folder_id IN ($1)) AND NOT EXISTS (SELECT $2 FROM origo_email_message_property t5 WHERE (((t5.is_seen = $3) AND (t5.owner_id = $4)) AND (t5.message_id = t0.entity_id))) ) AND (((t2.entity_id = t4.delivery_id) AND ((t3.entity_id = t2.entity_id) AND (t2.type = $5))) AND ((t0.entity_id = t3.message_id) AND ((t1.entity_id = t0.entity_id) AND (t0.type = $6)))))
ERROR: current transaction is aborted, commands ignored until end of transaction block
STATEMENT: SELECT t0.entity_id, t0.type, t0.VERSION, t1.entity_id, t1.attachment_size, t1.body_hash, t1.body_size_octets, t1.message_id, t1.plain_text_content, t1.sent_timestamp, t1.message_as_string, t1.from_entity_id, t1.forwarded_from_id, t1.replyto_id, t1.envelope_from_id FROM origo_email_folder_message t4, origo_email_delivery t3, onp_crm_entity t2, origo_email_message t1, onp_crm_entity t0 WHERE (((t4.folder_id IN ($1)) AND NOT EXISTS (SELECT $2 FROM origo_email_message_property t5 WHERE (((t5.is_seen = $3) AND (t5.owner_id = $4)) AND (t5.message_id = t0.entity_id))) ) AND (((t2.entity_id = t4.delivery_id) AND ((t3.entity_id = t2.entity_id) AND (t2.type = $5))) AND ((t0.entity_id = t3.message_id) AND ((t1.entity_id = t0.entity_id) AND (t0.type = $6)))))
...
...
...
...
from pgjdbc-ng.
Is there any way you could send me some DDL to create the necessary bits to make this query work? Should be a simple fix once I can test it easily.
from pgjdbc-ng.
Strange, I created a sample EclipseLink project, without Spring, and there it works correctly.
I see the following in the PG-log though:
ERROR: could not determine data type of parameter $1
STATEMENT: SELECT t0.id, t0.content, t0.message_id FROM part t0 WHERE NOT EXISTS (SELECT $1 FROM message t1 WHERE (t1.id = $2))
LOG: execute 0000000000000001: SELECT t0.id, t0.content, t0.message_id FROM part t0 WHERE NOT EXISTS (SELECT $1 FROM message t1 WHERE (t1.id = $2))
DETAIL: parameters: $1 = '1', $2 = '2'
I don't know what technique you use for making this work but it seems the server first gets a query which results in an error, then re-executes the query?
I'll create a test with Spring-managed transactions later and update this issue.
For now I use this work-around, using a custom SessionCustomizer in EclipseLink:
session.getPlatform.setShouldBindLiterals(false)
from pgjdbc-ng.
I think the solution to this is "don't do it". The simple fact is Postgres doesn't support it. With this driver my vision is to expose all of Postgres's awesome features; not emulate a bunch of stuff it doesn't support.
The "workaround" seems to kill in flight transactions. Which is why yours worked in a simple test but failed in the full environment. I didn't realize that.
It sounds like setShouldBindLiterals(false) is exactly what people need to do in this case. Postgres doesn't allow binding literals. Can you confirm that this completely solves your issues with EclipseLink?
from pgjdbc-ng.
I can confirm that setShouldBindLiterals(false) solves the issue. Close this ticket:-)
from pgjdbc-ng.
Related Issues (20)
- Allow underscore _ in the host name of a postgres database HOT 1
- Issue with RDS IAM Role Authentication
- update protocol properties at the time of connection creation
- What's the status and direction of the project? HOT 17
- Does it support MATCH_RECOGNIZE? HOT 4
- SCRAM channel binding check failed HOT 3
- Connection leak when timing out connection attempts
- Transfer to PostgreSQL Organization HOT 12
- Committer approval for transfer of copyright HOT 29
- Prepared statement already exists
- Parameter Parsing fails on concat operator in SQLText#parse
- Version upgrades HOT 1
- Execution of executeUpdate Closes Previously Acquired ResultSet
- NullPointerException on Calling getMoreResults
- Syntax Error with Statement.RETURN_GENERATED_KEYS
- Inconsistency between rs.getType() and stmt.getResultSetType()
- Inconsistent Handling of Invalid setFetchDirection Input between ResultSet and Statement
- ResultSet.beforeFirst() Unexpectedly Succeeds on TYPE_FORWARD_ONLY ResultSet
- Execution of executeUpdate Closes Previously Acquired ResultSet HOT 2
- Unable to create Array of ByteArrays for prepared statement
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pgjdbc-ng.