Re: FW: Question about the postgres resultset implementation
От | Oliver Jowett |
---|---|
Тема | Re: FW: Question about the postgres resultset implementation |
Дата | |
Msg-id | 416D98E8.5090600@opencloud.com обсуждение исходный текст |
Ответ на | FW: Question about the postgres resultset implementation ("Tornroth, Phill" <ptornroth@intellidot.net>) |
Список | pgsql-jdbc |
Tornroth, Phill wrote: > I did some tinkering of my own and found that one of the problems with > making the driver less cumbersome is the fact that findColumn() is currently > case insensitive. I don't know if this is required by the jdbc spec, but it > seems all the field names come back lower case (in the fields[] array), and > so I could replace the implementation without understanding how to prevent > the case of the field names from changing (changing from the case they were > sent in as). They come back lower-case because that's how they are in the actual schema. Unless you quote identifiers, they get smashed to lowercase by the backend: >> test=> create table t1(lowercase integer, UPPERCASE integer, "QUOTEDUPPERCASE" integer); >> CREATE TABLE >> test=> select * from t1; >> lowercase | uppercase | QUOTEDUPPERCASE >> -----------+-----------+----------------- >> (0 rows) > At any rate, if case insensitivity could be thrown out then a very fast > implementation could be worked out. As is, the following code was a marked > improvement: That change is slightly buggy as you *can* get uppercase characters in a field name. We can't entirely discard case-insensitivy as JDBC requires that column names are found case-insensitively. This actually makes the use of column names somewhat unreliable if you ever have two columns with names that only differ by case. From the JDBC javadoc: >> Column names used as input to getter methods are case insensitive. When >> a getter method is called with a column name and several columns have >> the same name, the value of the first matching column will be returned. >> The column name option is designed to be used when column names are used >> in the SQL query that generated the result set. For columns that are NOT >> explicitly named in the query, it is best to use column numbers. If >> column names are used, there is no way for the programmer to guarantee >> that they actually refer to the intended columns. (I am assuming that "findColumn" is considered a getter method.. the javadoc is vague as ever) Nevertheless, we could certainly use a hashmap to speed up field lookups. This should be pretty trivial to implement, expect a patch shortly. (hah, in fact I see that Kris got there first..) -O
В списке pgsql-jdbc по дате отправления: