Re: Why is columnNames in Connection.prepareStatement(sql, columnNames[]) automatically quoted
От | Balázs Zsoldos |
---|---|
Тема | Re: Why is columnNames in Connection.prepareStatement(sql, columnNames[]) automatically quoted |
Дата | |
Msg-id | CAHEBw=SPKrZz=R7038UmGw9UZAuA7ejm0WA_tmMJ0Uv82-e8mg@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Why is columnNames in Connection.prepareStatement(sql, columnNames[]) automatically quoted (Dave Cramer <pg@fastcrypt.com>) |
Список | pgsql-jdbc |
Hi Dave,
I am not sure. I checked other JDBC drivers. I guess I did not meet the same problem due to the reason that other databases either use upper-case letters by default or they do not even care about the columnNames parameter. E.g.: MySQL JDBC driver simply does not care about that parameter, it is the same as calling with the Statement.RETURN_GENERATED_KEYS integer parameter.
I am not sure if this is documented in any JDBC documentation. I would guess that if I want to use camel-case field names, I should quote the column names by myself like in the SQL statement. E.g.: Connection.executeUpdate("insert into \"myTable\"...", "\"myIdField\"");.
I am not sure that would be the right solution. If you do not want to change this, I can understand as both can be an acceptable behavior. In that case I will try asking the developers of the technology I use (Querydsl) to handle this on their side.
Kind regards,
Balazs
On Fri, Jul 31, 2015 at 2:49 AM, Dave Cramer <pg@fastcrypt.com> wrote:
Actually I think I understand your issue. How would you propose this would work for people who actually have mixed case column names ??On 30 July 2015 at 20:47, Dave Cramer <pg@fastcrypt.com> wrote:Hi,Yes there is a chance to change the driver, but I need more info. What do you mean they are automatically quoted ???On 30 July 2015 at 20:32, Balázs Zsoldos <balazs.zsoldos@everit.biz> wrote:Hi,I would like to write database independent SQL statements. Everything works well, until I call Connection.prepareStatement(sql, columnNames[]).In the SQL statement nothing is quoted and it works well. I am wondering, why the values in the columnNames are automatically quoted? Is it a bug or a feature?More info:I create the fields and tables in DDL without quoting them. Table and field names become upper or lower case based on the engine. E.g.: In case of Oracle, they will have upper-case names, in PostgreSQL they will have lower-case names.If I use Oracle, I must provide the columnNames parameter for the mentioned function with upper-case letters otherwise it does not work (I think that is a bug, too, but I guess it is harder to send a patch for Oracle than PostgreSQL :-) ). If I use any other database engines (Derby, SQLServer, Hsqldb) everything works well.If I use PostgreSQL, however, I must provide lower-case letters for the parameter as it is quoted inside. I do not think it should be quoted. If someone wants to quote those column names, it would be possible by providing the Strings with quotes like Connection.prepareStatement(sql, "\"myCamelCaseColumnName\"");Do you think there is any chance to change this in PostgreSQL JDBC driver or shall I write separate code for Postgres?Regards,Balázs Zsoldos
В списке pgsql-jdbc по дате отправления: