datamapper / do

DataObjects
147 stars 74 forks source link

Fixed problem with Postgres 9.1 Writeable CTE's #31

Closed jwkoelewijn closed 12 years ago

jwkoelewijn commented 12 years ago

Problem solved by rewriting code that checked whether the query should be executed using PreparedStatement#executeQuery() or using PreparedStatement#executeUpdate(). Original code checked for the existence of the word 'RETURNING', where this is perfectly possible in Postgres 9.1, where a writable CTE can be created with the word RETURNING in it, while not actually returning any values (i.e. #executeQuery() should have been called)

Fix is to use the PreparedStatement#execute(), which returns a boolean that indicates whether a result was returned, or that existing rows were affected. Based on the value of this boolean either a ResultSet is requested or the number of affected rows is retrieved.

dkubb commented 12 years ago

@dbussink looks like there's a spec failure for DO: http://travis-ci.org/#!/datamapper/do/jobs/1295368 .. not sure if it was caused by this commit, but I figured I'd mention it just in case.

jwkoelewijn commented 12 years ago

@dkubb This spec failure is unrelated, but I am checking it nonetheless :)

dkubb commented 12 years ago

@jwkoelewijn thank you very much!