pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
12+ messages / 6 participants
[nested] [flat]

* Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-09 19:15  Walter Couto <Walter.Couto@EMBARCADERO.COM>
  0 siblings, 2 replies; 12+ messages in thread

From: Walter Couto @ 2014-06-09 19:15 UTC (permalink / raw)
  To: pgsql-odbc

CREATE TABLE DATE_TEST
(
    test               integer         NOT NULL,
    TIMESTAMPOFFSET_COL TIMESTAMP WITH TIME ZONE,
    PRIMARY KEY(TEST)
)
;
INSERT INTO DATE_TEST VALUES ( 2, timestamp WITH TIME ZONE '2002-04-11 01:33:08.12345+02' );
;

NOTE: My client machines time zone offset is currently  -4.  The server's times zone offset is +3.

Execute:

select TIMESTAMPOFFSET_COL from DATE_TEST where test = 2.

Results:
If you bind to that column as a timestamp, I get the following:

	JDBC: 2002-04-11 19:33:08.12345
               ODBC:  2002-04-11 02:33:08.12345 

If I bind as a string I get:

	JDBC: 2002-04-10 19:33:08.12345-04
                ODBC: 2002-04-11 02:33:08.12345

The fact the two drivers return completely different results is a concern as they both should behave the same for this data type for consistency, but I can work around that via the string binding if the time zone is returned....but ODBC can never give me the time zone!  I think this is a serious bug.  I can work around this by assuming the same time zone as the server, but I would then have to keep checking what that time zone offset is just in case the session time zone changed, but I think this is a waste of a query round trip since that info should have been available to me via binding as a string.

Regards,
Walter


CONFIDENTIALITY NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-09 23:27  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Walter Couto <Walter.Couto@EMBARCADERO.COM>
  1 sibling, 0 replies; 12+ messages in thread

From: Adrian Klaver @ 2014-06-09 23:27 UTC (permalink / raw)
  To: Walter Couto <Walter.Couto@EMBARCADERO.COM>; pgsql-odbc

On 06/09/2014 12:15 PM, Walter Couto wrote:
> CREATE TABLE DATE_TEST
> (
>      test               integer         NOT NULL,
>      TIMESTAMPOFFSET_COL TIMESTAMP WITH TIME ZONE,
>      PRIMARY KEY(TEST)
> )
> ;
> INSERT INTO DATE_TEST VALUES ( 2, timestamp WITH TIME ZONE '2002-04-11 01:33:08.12345+02' );
> ;
>
> NOTE: My client machines time zone offset is currently  -4.  The server's times zone offset is +3.
>
> Execute:
>
> select TIMESTAMPOFFSET_COL from DATE_TEST where test = 2.
>
> Results:
> If you bind to that column as a timestamp, I get the following:

>
> 	JDBC: 2002-04-11 19:33:08.12345
>                 ODBC:  2002-04-11 02:33:08.12345
>
> If I bind as a string I get:
>
> 	JDBC: 2002-04-10 19:33:08.12345-04
>                  ODBC: 2002-04-11 02:33:08.12345

I am not following the above.

Are you talking about binding when you do the INSERT?

If so can you show the code for each case?

How and where are you doing the selects?

>
> The fact the two drivers return completely different results is a concern as they both should behave the same for this data type for consistency, but I can work around that via the string binding if the time zone is returned....but ODBC can never give me the time zone!  I think this is a serious bug.  I can work around this by assuming the same time zone as the server, but I would then have to keep checking what that time zone offset is just in case the session time zone changed, but I think this is a waste of a query round trip since that info should have been available to me via binding as a string.


Looks to me like the JDBC driver is trying to convert to local time.

Just to be clear what JDBC driver are you using?
>
> Regards,
> Walter
>
>
> CONFIDENTIALITY NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
>
>


-- 
Adrian Klaver
adrian.klaver@aklaver.com


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-10 00:18  David G Johnston <david.g.johnston@gmail.com>
  parent: Walter Couto <Walter.Couto@EMBARCADERO.COM>
  1 sibling, 1 reply; 12+ messages in thread

From: David G Johnston @ 2014-06-10 00:18 UTC (permalink / raw)
  To: pgsql-odbc

Walter Couto wrote
> The fact the two drivers return completely different results is a concern
> as they both should behave the same for this data type for consistency, 

At face value this is not something that can be expected. JDBC and ODBC have
no requirement to be consistent between each other.

Your choice to omit displaying the timezone in the timestamp retrieval
(JDBC:getDate) is in error.  If both outputs resolve to the same
point-in-time there is no inconsistency to worry about.

JDBC is at least kind enough, when you ask to to provide a string
representation (JDBC:getString) of the timestamp, to show the timezone
information.  The fact that the ODBC driver does not is an enhancement worth
considering.

Also, the reason for some confusion is that you do not "bind" when you
retrieve a value from a result set.  Given that your insert was done
on-server and I'm doubting you are paramertizing the SELECT statement, you
never actually "bind" anything as its commonly used - with placeholders in
queries sent to the server.

I am not familiar with ODBC but given your first example I would have to
conclude you are getting sufficient and correct data from the server as long
as you leave it in a Date object and use your language methods to ensure
that upon display you are converting to the correct timezone.

Note that you can let PostgreSQL do the work by using:

SELECT timestampoffset_col AT TIME ZONE 'GMT' --which then returns a plain
timestamp adjusted to the specified timezone.  You can further ensure the
return value by formatting the above expression as text.

SELECT to_char(now() AT TIME ZONE 'GMT','YYYY-MM-DD HH24:MI:SS GMT');

David J.







--
View this message in context: http://postgresql.1045698.n5.nabble.com/Inconsistency-between-JDBC-and-ODBC-drivers-when-dealing-wit...
Sent from the PostgreSQL - odbc mailing list archive at Nabble.com.


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-10 02:49  Walter Couto <Walter.Couto@EMBARCADERO.COM>
  parent: David G Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Walter Couto @ 2014-06-10 02:49 UTC (permalink / raw)
  To: David G Johnston <david.g.johnston@gmail.com>; pgsql-odbc

I have to strongly disagree that this is an enhancement.  It is a severe bug. In PostgreSQL, if you look at both the JDBC and ODBC source code, for timestamp with time zone, the string that the server gives to the driver for my example is "2002-04-11 02:33:08.12345+3"  if the session time zone is set to +3.

Asking for a timestamp with time zone as a timestamp in either ODBC and JDBC is done knowing you are accepting the lose of time zone info. I have NO issue with this (as a side note the JDBC and ODBC driver did behave the same at one point, in both cases they returned the timestamp in the server time zone, but surprise change in a recent version to correct this to be JDBC spec compliant caused some headaches for some people using the driver as they wrote code assuming this behaviour and now were all wrong).

I have an issue with the retuned string value from ODBC....the driver got a perfectly fine string, it could have given it to me. There is no sane reason to have the time zone part stripped out before giving it to me.  At least with JDBC it gave me an EQUALLY ACCURATE string of "2002-04-10 19:22:08.12345-04", with ODBC I need to run a separate query to get the session time zone to correct the string that was perfectly fine when ODBC was given it.

Changing the query is nice for internal queries and is a good work around for this bug, but when non-internal queries are given to our application, we can't expect to ask the customers to work around driver bugs and change all their perfectly working queries. I expect the driver to give information as accurately as the server gave to the driver.  That is what I am asking here and that is what is not happing in the case of ODBC when asking for the string form of a timestamp with time zone.  This is why I see this as a severe bug as the driver is giving me CORRUPT data that is not the same or even equally the same as the data it retrieved from the server that the client tool has to "fix" by issuing another query.

Regards,
Walter

________________________________________
From: pgsql-odbc-owner@postgresql.org [pgsql-odbc-owner@postgresql.org] on behalf of David G Johnston [david.g.johnston@gmail.com]
Sent: Monday, June 09, 2014 8:18 PM
To: pgsql-odbc@postgresql.org
Subject: [ODBC] Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE

Walter Couto wrote
> The fact the two drivers return completely different results is a concern
> as they both should behave the same for this data type for consistency,

At face value this is not something that can be expected. JDBC and ODBC have
no requirement to be consistent between each other.

Your choice to omit displaying the timezone in the timestamp retrieval
(JDBC:getDate) is in error.  If both outputs resolve to the same
point-in-time there is no inconsistency to worry about.

JDBC is at least kind enough, when you ask to to provide a string
representation (JDBC:getString) of the timestamp, to show the timezone
information.  The fact that the ODBC driver does not is an enhancement worth
considering.

Also, the reason for some confusion is that you do not "bind" when you
retrieve a value from a result set.  Given that your insert was done
on-server and I'm doubting you are paramertizing the SELECT statement, you
never actually "bind" anything as its commonly used - with placeholders in
queries sent to the server.

I am not familiar with ODBC but given your first example I would have to
conclude you are getting sufficient and correct data from the server as long
as you leave it in a Date object and use your language methods to ensure
that upon display you are converting to the correct timezone.

Note that you can let PostgreSQL do the work by using:

SELECT timestampoffset_col AT TIME ZONE 'GMT' --which then returns a plain
timestamp adjusted to the specified timezone.  You can further ensure the
return value by formatting the above expression as text.

SELECT to_char(now() AT TIME ZONE 'GMT','YYYY-MM-DD HH24:MI:SS GMT');

David J.







--
View this message in context: http://postgresql.1045698.n5.nabble.com/Inconsistency-between-JDBC-and-ODBC-drivers-when-dealing-wit...
Sent from the PostgreSQL - odbc mailing list archive at Nabble.com.


--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

CONFIDENTIALITY NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-10 03:18  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Walter Couto <Walter.Couto@EMBARCADERO.COM>
  0 siblings, 1 reply; 12+ messages in thread

From: Adrian Klaver @ 2014-06-10 03:18 UTC (permalink / raw)
  To: Walter Couto <Walter.Couto@EMBARCADERO.COM>; David G Johnston <david.g.johnston@gmail.com>; pgsql-odbc

On 06/09/2014 07:49 PM, Walter Couto wrote:
> I have to strongly disagree that this is an enhancement.  It is a severe bug. In PostgreSQL, if you look at both the JDBC and ODBC source code, for timestamp with time zone, the string that the server gives to the driver for my example is "2002-04-11 02:33:08.12345+3"  if the session time zone is set to +3.
>
> Asking for a timestamp with time zone as a timestamp in either ODBC and JDBC is done knowing you are accepting the lose of time zone info. I have NO issue with this (as a side note the JDBC and ODBC driver did behave the same at one point, in both cases they returned the timestamp in the server time zone, but surprise change in a recent version to correct this to be JDBC spec compliant caused some headaches for some people using the driver as they wrote code assuming this behaviour and now were all wrong).
>
> I have an issue with the retuned string value from ODBC....the driver got a perfectly fine string, it could have given it to me. There is no sane reason to have the time zone part stripped out before giving it to me.  At least with JDBC it gave me an EQUALLY ACCURATE string of "2002-04-10 19:22:08.12345-04", with ODBC I need to run a separate query to get the session time zone to correct the string that was perfectly fine when ODBC was given it.
>
> Changing the query is nice for internal queries and is a good work around for this bug, but when non-internal queries are given to our application, we can't expect to ask the customers to work around driver bugs and change all their perfectly working queries. I expect the driver to give information as accurately as the server gave to the driver.  That is what I am asking here and that is what is not happing in the case of ODBC when asking for the string form of a timestamp with time zone.  This is why I see this as a severe bug as the driver is giving me CORRUPT data that is not the same or even equally the same as the data it retrieved from the server that the client tool has to "fix" by issuing another query.


You still have not shown what it is you are actually doing. Personally, 
less rant and more actual code would be useful. You originally asked for 
a solution and I would like to see that, but at this point there is not 
enough information to go on, for me at least.

So what exactly do you mean when you say 'asking for string form of 
timestamp with time zone'?

>
> Regards,
> Walter


-- 
Adrian Klaver
adrian.klaver@aklaver.com


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-10 04:15  Inoue, Hiroshi <inoue@tpf.co.jp>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Inoue, Hiroshi @ 2014-06-10 04:15 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; Walter Couto <Walter.Couto@EMBARCADERO.COM>; +Cc: David G Johnston <david.g.johnston@gmail.com>; pgsql-odbc

(2014/06/10 12:18), Adrian Klaver wrote:
> On 06/09/2014 07:49 PM, Walter Couto wrote:
>> I have to strongly disagree that this is an enhancement.  It is a
>> severe bug. In PostgreSQL, if you look at both the JDBC and ODBC
>> source code, for timestamp with time zone, the string that the server
>> gives to the driver for my example is "2002-04-11 02:33:08.12345+3"
>> if the session time zone is set to +3.
>>
>> Asking for a timestamp with time zone as a timestamp in either ODBC
>> and JDBC is done knowing you are accepting the lose of time zone info.
>> I have NO issue with this (as a side note the JDBC and ODBC driver did
>> behave the same at one point, in both cases they returned the
>> timestamp in the server time zone, but surprise change in a recent
>> version to correct this to be JDBC spec compliant caused some
>> headaches for some people using the driver as they wrote code assuming
>> this behaviour and now were all wrong).
>>
>> I have an issue with the retuned string value from ODBC....the driver
>> got a perfectly fine string, it could have given it to me. There is no
>> sane reason to have the time zone part stripped out before giving it
>> to me.  At least with JDBC it gave me an EQUALLY ACCURATE string of
>> "2002-04-10 19:22:08.12345-04", with ODBC I need to run a separate
>> query to get the session time zone to correct the string that was
>> perfectly fine when ODBC was given it.
>>
>> Changing the query is nice for internal queries and is a good work
>> around for this bug, but when non-internal queries are given to our
>> application, we can't expect to ask the customers to work around
>> driver bugs and change all their perfectly working queries. I expect
>> the driver to give information as accurately as the server gave to the
>> driver.  That is what I am asking here and that is what is not happing
>> in the case of ODBC when asking for the string form of a timestamp
>> with time zone.  This is why I see this as a severe bug as the driver
>> is giving me CORRUPT data that is not the same or even equally the
>> same as the data it retrieved from the server that the client tool has
>> to "fix" by issuing another query.

Currently psqlodbc retrieves TIMESTAMP WITH TIME ZONE pretty much
the same as TIMESTAMP WITHOUT TIME ZONE. Though there are some code
  about time zone handling, it is disabled.

The data type TIMESTAMP_STRUCT which correponds to SQL_C_TIMESTAMP
has no information about time zone. If we would retrieve time zone
explictly, a consensus is needed which time zone is used to store
TIMESTAMP_STRUCT type data.

1. UTC
2. client local time zone
3. server time zone

The driver's behavior has been 3. So UTC seems unfavorable.
Probably most people have used the driver under environment
2 == 3. Should we use client local time zone instead?

regards,
Hiroshi INoue


-- 
I am using the free version of SPAMfighter.
SPAMfighter has removed 10706 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

Do you have a slow PC? Try a Free scan 
http://www.spamfighter.com/SLOW-PCfighter?cid=sigen



-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-10 05:04  David Johnston <david.g.johnston@gmail.com>
  parent: Inoue, Hiroshi <inoue@tpf.co.jp>
  0 siblings, 1 reply; 12+ messages in thread

From: David Johnston @ 2014-06-10 05:04 UTC (permalink / raw)
  To: Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; Walter Couto <Walter.Couto@embarcadero.com>; pgsql-odbc

On Tuesday, June 10, 2014, Inoue, Hiroshi <inoue@tpf.co.jp> wrote:

> (2014/06/10 12:18), Adrian Klaver wrote:
>
>> On 06/09/2014 07:49 PM, Walter Couto wrote:
>>
>>> I have to strongly disagree that this is an enhancement.  It is a
>>> severe bug. In PostgreSQL, if you look at both the JDBC and ODBC
>>> source code, for timestamp with time zone, the string that the server
>>> gives to the driver for my example is "2002-04-11 02:33:08.12345+3"
>>> if the session time zone is set to +3.
>>>
>>> Asking for a timestamp with time zone as a timestamp in either ODBC
>>> and JDBC is done knowing you are accepting the lose of time zone info.
>>> I have NO issue with this (as a side note the JDBC and ODBC driver did
>>> behave the same at one point, in both cases they returned the
>>> timestamp in the server time zone, but surprise change in a recent
>>> version to correct this to be JDBC spec compliant caused some
>>> headaches for some people using the driver as they wrote code assuming
>>> this behaviour and now were all wrong).
>>>
>>> I have an issue with the retuned string value from ODBC....the driver
>>> got a perfectly fine string, it could have given it to me. There is no
>>> sane reason to have the time zone part stripped out before giving it
>>> to me.  At least with JDBC it gave me an EQUALLY ACCURATE string of
>>> "2002-04-10 19:22:08.12345-04", with ODBC I need to run a separate
>>> query to get the session time zone to correct the string that was
>>> perfectly fine when ODBC was given it.
>>>
>>> Changing the query is nice for internal queries and is a good work
>>> around for this bug, but when non-internal queries are given to our
>>> application, we can't expect to ask the customers to work around
>>> driver bugs and change all their perfectly working queries. I expect
>>> the driver to give information as accurately as the server gave to the
>>> driver.  That is what I am asking here and that is what is not happing
>>> in the case of ODBC when asking for the string form of a timestamp
>>> with time zone.  This is why I see this as a severe bug as the driver
>>> is giving me CORRUPT data that is not the same or even equally the
>>> same as the data it retrieved from the server that the client tool has
>>> to "fix" by issuing another query.
>>>
>>
> Currently psqlodbc retrieves TIMESTAMP WITH TIME ZONE pretty much
> the same as TIMESTAMP WITHOUT TIME ZONE. Though there are some code
>  about time zone handling, it is disabled.
>
> The data type TIMESTAMP_STRUCT which correponds to SQL_C_TIMESTAMP
> has no information about time zone. If we would retrieve time zone
> explictly, a consensus is needed which time zone is used to store
> TIMESTAMP_STRUCT type data.
>
> 1. UTC
> 2. client local time zone
> 3. server time zone
>
> The driver's behavior has been 3. So UTC seems unfavorable.
> Probably most people have used the driver under environment
> 2 == 3. Should we use client local time zone instead?
>
>
There is no functional difference between 2 and 3 if the information sent
from the server cannot be embedded into the stored typed.

That is the issue since what the driver is providing when a string is
requested is not the raw server data but the string  representation of the
server content after it has been converted into a local timestamp object
and the timezone stripped.

If indeed the timezone is silently dropped then it matters not what you
call resolving the issue - enhancement or bugfix. In the end someone has to
volunteer to dive into the open souce code and develop a patch.  Until then
you live with the limitation, write a wrapper to accomodate a local
workaround (say by caching the server timezone to avoid repetitive
queries), and/or choose a different driver/protocol.

Note I doubt any acceptable solution would be simply returning supposedly
raw text from the server. I think one problem is that the data is not
always in text format.  It is possible that an internal type could be
created but if you go that far you might as well go make the whole thing
work normally and not just via a getString method.

David J.

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-10 10:31  Walter Couto <Walter.Couto@EMBARCADERO.COM>
  parent: David Johnston <david.g.johnston@gmail.com>
  0 siblings, 1 reply; 12+ messages in thread

From: Walter Couto @ 2014-06-10 10:31 UTC (permalink / raw)
  To: David Johnston <david.g.johnston@gmail.com>; Inoue, Hiroshi <inoue@tpf.co.jp>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-odbc

Yes, I have to workaround this issue in my application since the existing issue as the current drivers have this bug. And to avoid overhead caching the server time zone is the best option to avoid repeated calls (thought their is a risk of you being wrong as you can changes the session time zone via a statement which will make the cached value wrong if it was run before that.



As apposed to showing my code to get a SQL_C_CHAR  I'll show you the ODBC code that is perplexing:



In convert.c's copy_and_convert_field() line 946: This case statement block states that for PG_TYPE_ABSTIME, PG_TYPE_DATETIME, PG_TYPE_TIMESTAMP_NO_TMZONE and PG_TYPE_TIMESTAMP that the string given by the server is:

1) -Infinity

2) -Infinity

3) invalid

4) %4d-%2d-%2d %2d:%2d:%2d%31s %15s (YYYY-MM-dd hh:mm:ss[.ffffff][-/+zh[:zm] [BC]) (max 35 characters for year < 10000)



What that code does for 1) - 3) is perfectly fine, you have to choose some timestamp value and those values are as good as anything else. 4) is dealt by the function timestamp2stime on line 224 of the convert_field.  The only bug I see in this code is how it handles the time zone parsing, it only handles +/-zh, but not the possible but rare +/-zh:zm format/ That bug is in the switch statement on line 245 of that file. The cases for '+', '-' and '.' all don't check for the existence of ":" in the string.  But doesn't matter currently as we throw away the time zone, so no fix is needed in this method at the current time, just a note that it is not handling a possible form of the string correctly.



Going back to copy_and_convert_field() on line 1147 this case happens if we are returning the text version of a value as indicated by the local variable text_handling. We then get to line 1170 where it handles PG_TYPE_ABSTIME, PG_TYPE_DATETIME, PG_TYPE_TIMESTAMP_NO_TMZONE and PG_TYPE_TIMESTAMP again and it calls a function, stime2timestamp, to rebuild the string in the format of 4) but with no zone information! (NOTE: stime2timestamp also has a bug with time zone it doesn`t handle offset that need the minute, i.e. -3:30 but not a concern as zone is never used currently)  If I was writing this part of the code I would have something like the logic shown below as I don`t understand what is wrong with the string the server gave us and why we would want to give it in an alternate form:



case PG_TYPE_ABSTIME:

case PG_TYPE_DATETIME:

case PG_TYPE_TIMESTAMP_NO_TMZONE:

case PG_TYPE_TIMESTAMP:

   len = 19;

   if (cbValueMax > len)

   {

      if ( (strnicmp(value, INFINITY_STRING, 8) == 0) ||

           (strnicmp(value, MINFINITY_STRING, 9) == 0) ||

           (strnicmp(value, "invalid", 7) == 0) // Keep old behaviour

      {

         /* sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d",

         std_time.y, std_time.m, std_time.d, std_time.hh, std_time.mm, std_time.ss); */

         stime2timestamp(&std_time, rgbValueBindRow, FALSE,

                         PG_VERSION_GE(conn, 7.2) ? (int) cbValueMax - len - 2 : 0);

         len = strlen(rgbValueBindRow);

      }

      else

      {

         len = strlen(value);

         if (cbValueMax > len)

         {

            // Just give back what the server gave us

            strcpy(rgbValueBindRow, value);

         }

         else

         {

            /* fall back to generating the string */

            stime2timestamp(&std_time, rgbValueBindRow, FALSE,

                         PG_VERSION_GE(conn, 7.2) ? (int) cbValueMax - len - 2 : 0);

            len = strlen(rgbValueBindRow);

         }

      }

   }

   break;



I hope that clears things up.



Walter



________________________________
From: David Johnston [david.g.johnston@gmail.com]
Sent: Tuesday, June 10, 2014 1:04 AM
To: Inoue, Hiroshi
Cc: Adrian Klaver; Walter Couto; pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE

On Tuesday, June 10, 2014, Inoue, Hiroshi <inoue@tpf.co.jp<mailto:inoue@tpf.co.jp>> wrote:
(2014/06/10 12:18), Adrian Klaver wrote:
On 06/09/2014 07:49 PM, Walter Couto wrote:
I have to strongly disagree that this is an enhancement.  It is a
severe bug. In PostgreSQL, if you look at both the JDBC and ODBC
source code, for timestamp with time zone, the string that the server
gives to the driver for my example is "2002-04-11 02:33:08.12345+3"
if the session time zone is set to +3.

Asking for a timestamp with time zone as a timestamp in either ODBC
and JDBC is done knowing you are accepting the lose of time zone info.
I have NO issue with this (as a side note the JDBC and ODBC driver did
behave the same at one point, in both cases they returned the
timestamp in the server time zone, but surprise change in a recent
version to correct this to be JDBC spec compliant caused some
headaches for some people using the driver as they wrote code assuming
this behaviour and now were all wrong).

I have an issue with the retuned string value from ODBC....the driver
got a perfectly fine string, it could have given it to me. There is no
sane reason to have the time zone part stripped out before giving it
to me.  At least with JDBC it gave me an EQUALLY ACCURATE string of
"2002-04-10 19:22:08.12345-04", with ODBC I need to run a separate
query to get the session time zone to correct the string that was
perfectly fine when ODBC was given it.

Changing the query is nice for internal queries and is a good work
around for this bug, but when non-internal queries are given to our
application, we can't expect to ask the customers to work around
driver bugs and change all their perfectly working queries. I expect
the driver to give information as accurately as the server gave to the
driver.  That is what I am asking here and that is what is not happing
in the case of ODBC when asking for the string form of a timestamp
with time zone.  This is why I see this as a severe bug as the driver
is giving me CORRUPT data that is not the same or even equally the
same as the data it retrieved from the server that the client tool has
to "fix" by issuing another query.

Currently psqlodbc retrieves TIMESTAMP WITH TIME ZONE pretty much
the same as TIMESTAMP WITHOUT TIME ZONE. Though there are some code
 about time zone handling, it is disabled.

The data type TIMESTAMP_STRUCT which correponds to SQL_C_TIMESTAMP
has no information about time zone. If we would retrieve time zone
explictly, a consensus is needed which time zone is used to store
TIMESTAMP_STRUCT type data.

1. UTC
2. client local time zone
3. server time zone

The driver's behavior has been 3. So UTC seems unfavorable.
Probably most people have used the driver under environment
2 == 3. Should we use client local time zone instead?


There is no functional difference between 2 and 3 if the information sent from the server cannot be embedded into the stored typed.

That is the issue since what the driver is providing when a string is requested is not the raw server data but the string  representation of the server content after it has been converted into a local timestamp object and the timezone stripped.

If indeed the timezone is silently dropped then it matters not what you call resolving the issue - enhancement or bugfix. In the end someone has to volunteer to dive into the open souce code and develop a patch.  Until then you live with the limitation, write a wrapper to accomodate a local workaround (say by caching the server timezone to avoid repetitive queries), and/or choose a different driver/protocol.

Note I doubt any acceptable solution would be simply returning supposedly raw text from the server. I think one problem is that the data is not always in text format.  It is possible that an internal type could be created but if you go that far you might as well go make the whole thing work normally and not just via a getString method.

David J.


CONFIDENTIALITY NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-11 03:38  Inoue, Hiroshi <inoue@tpf.co.jp>
  parent: Walter Couto <Walter.Couto@EMBARCADERO.COM>
  0 siblings, 1 reply; 12+ messages in thread

From: Inoue, Hiroshi @ 2014-06-11 03:38 UTC (permalink / raw)
  To: Walter Couto <Walter.Couto@EMBARCADERO.COM>; David Johnston <david.g.johnston@gmail.com>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-odbc

Hi Walter,

I would enable time zone related code and complete the coding.
When I make a patch, could you test it?

(2014/06/10 19:31), Walter Couto wrote:
> Yes, I have to workaround this issue in my application since the
> existing issue as the current drivers have this bug. And to avoid
> overhead caching the server time zone is the best option to avoid
> repeated calls (thought their is a risk of you being wrong as you can
> changes the session time zone via a statement which will make the cached
> value wrong if it was run before that.
>
> As apposed to showing my code to get a SQL_C_CHAR  I'll show you the
> ODBC code that is perplexing:
>
> In convert.c's copy_and_convert_field() line 946: This case statement
> block states that for PG_TYPE_ABSTIME, PG_TYPE_DATETIME,
> PG_TYPE_TIMESTAMP_NO_TMZONE and PG_TYPE_TIMESTAMP that the string given
> by the server is:
>
> 1) -Infinity
>
> 2) -Infinity
>
> 3) invalid
>
> 4) %4d-%2d-%2d %2d:%2d:%2d%31s %15s (YYYY-MM-dd
> hh:mm:ss[.ffffff][-/+zh[:zm] [BC]) (max 35 characters for year < 10000)
>
> What that code does for 1) - 3) is perfectly fine, you have to choose
> some timestamp value and those values are as good as anything else. 4)
> is dealt by the function timestamp2stime on line 224 of the
> convert_field.  The only bug I see in this code is how it handles the
> time zone parsing, it only handles +/-zh, but not the possible but rare
> +/-zh:zm format/ That bug is in the switch statement on line 245 of that
> file. The cases for '+', '-' and '.' all don't check for the existence
> of ":" in the string.

Thanks.
I was surprized that the time zone in old Japanese days was
	+09:18:59
.
In fact using psql I see the following results.

=# select cast('1887-12-31 23:59:59' as timestamp with time zone);
          timestamptz
------------------------------
  1887-12-31 23:59:59+09:18:59

=# select cast('1887-12-31 23:59:60' as timestamp with time zone);
       timestamptz
------------------------
  1888-01-01 00:00:00+09

So I would take the form -/+zh[:zm[:zs]] into account.

regards,
Hiroshi Inoue

  ­­


-- 
I am using the free version of SPAMfighter.
SPAMfighter has removed 10739 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

Do you have a slow PC? Try a Free scan 
http://www.spamfighter.com/SLOW-PCfighter?cid=sigen



-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-11 03:42  Walter Couto <Walter.Couto@EMBARCADERO.COM>
  parent: Inoue, Hiroshi <inoue@tpf.co.jp>
  0 siblings, 1 reply; 12+ messages in thread

From: Walter Couto @ 2014-06-11 03:42 UTC (permalink / raw)
  To: Inoue, Hiroshi <inoue@tpf.co.jp>; David Johnston <david.g.johnston@gmail.com>; +Cc: Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-odbc

Yes I can test it. I was looking at the parsing code to see how I would fix it so glad to test or help out.

Walter


-------- Original message --------
From: "Inoue, Hiroshi"
Date:06/10/2014 11:39 PM (GMT-05:00)
To: Walter Couto ,David Johnston
Cc: Adrian Klaver ,pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE

Hi Walter,

I would enable time zone related code and complete the coding.
When I make a patch, could you test it?

(2014/06/10 19:31), Walter Couto wrote:
> Yes, I have to workaround this issue in my application since the
> existing issue as the current drivers have this bug. And to avoid
> overhead caching the server time zone is the best option to avoid
> repeated calls (thought their is a risk of you being wrong as you can
> changes the session time zone via a statement which will make the cached
> value wrong if it was run before that.
>
> As apposed to showing my code to get a SQL_C_CHAR  I'll show you the
> ODBC code that is perplexing:
>
> In convert.c's copy_and_convert_field() line 946: This case statement
> block states that for PG_TYPE_ABSTIME, PG_TYPE_DATETIME,
> PG_TYPE_TIMESTAMP_NO_TMZONE and PG_TYPE_TIMESTAMP that the string given
> by the server is:
>
> 1) -Infinity
>
> 2) -Infinity
>
> 3) invalid
>
> 4) %4d-%2d-%2d %2d:%2d:%2d%31s %15s (YYYY-MM-dd
> hh:mm:ss[.ffffff][-/+zh[:zm] [BC]) (max 35 characters for year < 10000)
>
> What that code does for 1) - 3) is perfectly fine, you have to choose
> some timestamp value and those values are as good as anything else. 4)
> is dealt by the function timestamp2stime on line 224 of the
> convert_field.  The only bug I see in this code is how it handles the
> time zone parsing, it only handles +/-zh, but not the possible but rare
> +/-zh:zm format/ That bug is in the switch statement on line 245 of that
> file. The cases for '+', '-' and '.' all don't check for the existence
> of ":" in the string.

Thanks.
I was surprized that the time zone in old Japanese days was
        +09:18:59
.
In fact using psql I see the following results.

=# select cast('1887-12-31 23:59:59' as timestamp with time zone);
          timestamptz
------------------------------
  1887-12-31 23:59:59+09:18:59

=# select cast('1887-12-31 23:59:60' as timestamp with time zone);
       timestamptz
------------------------
  1888-01-01 00:00:00+09

So I would take the form -/+zh[:zm[:zs]] into account.

regards,
Hiroshi Inoue

  ­­


--
I am using the free version of SPAMfighter.
SPAMfighter has removed 10739 of my spam emails to date.
Get the free SPAMfighter here: http://www.spamfighter.com/len

Do you have a slow PC? Try a Free scan
http://www.spamfighter.com/SLOW-PCfighter?cid=sigen


CONFIDENTIALITY NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

^ permalink  raw  reply  [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-13 22:09  Hiroshi Inoue <inoue@tpf.co.jp>
  parent: Walter Couto <Walter.Couto@EMBARCADERO.COM>
  0 siblings, 1 reply; 12+ messages in thread

From: Hiroshi Inoue @ 2014-06-13 22:09 UTC (permalink / raw)
  To: Walter Couto <Walter.Couto@EMBARCADERO.COM>; +Cc: David Johnston <david.g.johnston@gmail.com>; Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-odbc

Hi Walter and all,

While reading the old and disabled code, I remembered the circumstances
back then a little.
Psqlodbc had followed the formatting rule e.g. described at the last
line in
  http://msdn.microsoft.com/en-us/library/ms712387%28v=vs.85%29.aspx
.
Also look at
  http://msdn.microsoft.com/en-us/library/ms712360%28v=vs.85%29.aspx
.
There's no time zone in ODBC world and I'm afraid the possibility
that some applications are broken by adding time zone expression.

So please vote which way to choose?

1. Keep the current behavior, i.e. simply drop the time zone part
    from server's output if exists.
2. Use local time zone instead of server time zone but omit the time
    zone expression.
3. Use local time zone with the time zone expression when the data
    type is TIMESTAMP WITH TIME ZONE.
4. The others.

Anyway I attached a patch which implements the above 3.
It's easy to change to 2.

regarts,
Hiroshi Inoue

> Walter
>
>
> -------- Original message --------
> From: "Inoue, Hiroshi"
> Date:06/10/2014 11:39 PM (GMT-05:00)
> To: Walter Couto ,David Johnston
> Cc: Adrian Klaver ,pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Re: Inconsistency between JDBC and ODBC drivers when
> dealing with TIMESTAMP WITH TIME ZONE
>
> Hi Walter,
>
> I would enable time zone related code and complete the coding.
> When I make a patch, could you test it?

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

with_time_zone.patch (text/x-patch, 25.3K) download diff --git a/columninfo.c b/columninfo.c index 7089fee..0d4583e 100644 --- a/columninfo.c +++ b/columninfo.c @@ -105,7 +105,7 @@ CI_read_fields(ColumnInfoClass *self, ConnectionClass *conn) /* Subtract the header length */ switch (new_adtid) { - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: case PG_TYPE_TIME: case PG_TYPE_TIME_WITH_TMZONE: diff --git a/convert.c b/convert.c index ca01a57..5834e03 100644 --- a/convert.c +++ b/convert.c @@ -52,11 +52,14 @@ CSTR NAN_STRING = "NaN"; CSTR INFINITY_STRING = "Infinity"; CSTR MINFINITY_STRING = "-Infinity"; +CSTR MINVALID_STRING = "-Invalid"; -#ifdef __CYGWIN__ +#if defined(WIN32) || defined(__CYGWIN__) #define TIMEZONE_GLOBAL _timezone -#elif defined(WIN32) || defined(HAVE_INT_TIMEZONE) +#define DAYLIGHT_GLOBAL _daylight +#elif defined(HAVE_INT_TIMEZONE) #define TIMEZONE_GLOBAL timezone +#define DAYLOGHT_GLOBAL daylight #endif /* @@ -218,54 +221,155 @@ static unsigned ODBCINT64 ATOI64U(const char *val) static void parse_to_numeric_struct(const char *wv, SQL_NUMERIC_STRUCT *ns, BOOL *overflow); /* - * TIMESTAMP <-----> SIMPLE_TIME + * conversion support routines + * timestamp string expression <-----> SIMPLE_TIME + * * precision support since 7.2. - * time zone support is unavailable(the stuff is unreliable) + * time zone support since 9.3.0500) + */ + +static BOOL use_local_time_zone = TRUE; +static BOOL use_time_zone_expression = TRUE; +#define TIME_ZONE_TYPE(pgtype) ((pgtype) == PG_TYPE_TIMESTAMP_W_TMZONE || (pgtype) == PG_TYPE_ABSTIME) + +/* + * Handle time zone expression zh[:zm[:zs]] + */ +static BOOL +get_zone_hhmmss(const char *zonestr, char *zonehh, char *zonemm, char *zoness) +{ + int hh, mm, ss; + int scnt = sscanf(zonestr, "%d:%d:%d", &hh, &mm, &ss); + switch (scnt) + { + case 3: + *zonehh = (char) hh; + *zonemm = (char) mm; + *zoness = (char) ss; + break; + case 2: + *zonehh = (char) hh; + *zonemm = (char) mm; + break; + case 1: + *zonehh = (char) hh; + break; + default: + return FALSE; + break; + } + return TRUE; +} + +/* + * TIMESTAMP string expression -----> SIMPLE_TIME */ +#define SECS_ONEDAY (24 * 60 * 60) +#define SECS_ONEHOUR (60 * 60) +#define SECS_ONEMIN 60 + static BOOL -timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL *bZone, int *zone) +timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL considerZone) { - char rest[64], bc[16], - *ptr; - int scnt, - i; + char rest[64], bc[16], *ptr; + int scnt, i; #ifdef TIMEZONE_GLOBAL long timediff; #endif - BOOL withZone = *bZone; + char withZone; + time_t t; + struct tm tm, *tm2; - *bZone = FALSE; - *zone = 0; + withZone = 0; st->fr = 0; st->infinity = 0; + st->invalid = 0; + st->withZone = 0; + st->hh = st->mm = st->ss = 0; + st->zonehh = st->zonemm = st->zoness = 0; rest[0] = '\0'; bc[0] = '\0'; - if ((scnt = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d%31s %15s", &st->y, &st->m, &st->d, &st->hh, &st->mm, &st->ss, rest, bc)) < 6) + scnt = sscanf(str, "%4d-%2d-%2d %2d:%2d:%2d%31s %15s", &st->y, &st->m, &st->d, &st->hh, &st->mm, &st->ss, rest, bc); + if (scnt < 3 || scnt == 4 || scnt == 5) /* incomplete date/time expression */ + { + if (strnicmp(str, INFINITY_STRING, 8) == 0) + { + st->infinity = 1; + st->m = 12; + st->d = 31; + st->y = 9999; + st->hh = 23; + st->mm = 59; + st->ss = 59; + + return TRUE; + } + if (strnicmp(str, MINFINITY_STRING, 9) == 0) + { + st->infinity = -1; + st->m = 1; + st->d = 1; + // st->y = -4713; + st->y = -9999; + st->hh = 0; + st->mm = 0; + st->ss = 0; + + return TRUE; + } + /* + * The timestamp is invalid so set something conspicuous, + * like the epoch + */ + t = 0; +#ifdef HAVE_LOCALTIME_R + tm2 = localtime_r(&t, &tm); +#else + tm2 = localtime(&t); +#endif /* HAVE_LOCALTIME_R */ + st->m = tm2->tm_mon + 1; + st->d = tm2->tm_mday; + st->y = tm2->tm_year + 1900; + st->hh = tm2->tm_hour; + st->mm = tm2->tm_min; + st->ss = tm2->tm_sec; + if (strnicmp(str, MINVALID_STRING, 9) == 0) + { + st->invalid = 1; + st->m = 1; + st->d = 1; + // st->y = -4713; + st->y = -9999; + st->hh = 0; + st->mm = 0; + st->ss = 0; + + return TRUE; + } return FALSE; + } else if (scnt == 6) return TRUE; switch (rest[0]) { case '+': - *bZone = TRUE; - *zone = atoi(&rest[1]); + if (considerZone && get_zone_hhmmss(rest + 1, &st->zonehh, &st->zonemm, &st->zoness)) + withZone = 1; break; case '-': - *bZone = TRUE; - *zone = -atoi(&rest[1]); + if (considerZone && get_zone_hhmmss(rest + 1, &st->zonehh, &st->zonemm, &st->zoness)) + withZone = -1; break; case '.': if ((ptr = strchr(rest, '+')) != NULL) { - *bZone = TRUE; - *zone = atoi(&ptr[1]); - *ptr = '\0'; + if (considerZone && get_zone_hhmmss(ptr + 1, &st->zonehh, &st->zonemm, &st->zoness)) + withZone = 1; } else if ((ptr = strchr(rest, '-')) != NULL) { - *bZone = TRUE; - *zone = -atoi(&ptr[1]); - *ptr = '\0'; + if (considerZone && get_zone_hhmmss(ptr + 1, &st->zonehh, &st->zonemm, &st->zoness)) + withZone = -1; } for (i = 1; i < 10; i++) { @@ -288,65 +392,88 @@ timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL *bZone, int *zone) { st->y *= -1; } - if (!withZone || !*bZone || st->y < 1970) + st->withZone = withZone; + if (!considerZone || !withZone || st->y < 1970) + { return TRUE; + } #ifdef TIMEZONE_GLOBAL - if (!tzname[0] || !tzname[0][0]) + timediff = TIMEZONE_GLOBAL + withZone * (st->zonehh * SECS_ONEHOUR + st->zonemm * SECS_ONEMIN + st->zoness); + if (!DAYLIGHT_GLOBAL && timediff == 0) /* the same timezone */ { - *bZone = FALSE; return TRUE; } - timediff = TIMEZONE_GLOBAL + (*zone) * 3600; - if (!daylight && timediff == 0) /* the same timezone */ + + tm.tm_year = st->y - 1900; + tm.tm_mon = st->m - 1; + tm.tm_mday = st->d; + tm.tm_hour = 0; + tm.tm_min = 0; + tm.tm_sec = 0; + tm.tm_isdst = -1; + t = mktime(&tm); + if (t < 0) + { + st->withZone = 0; return TRUE; - else + } + t -= TIMEZONE_GLOBAL; + if (t % SECS_ONEDAY != 0) { - struct tm tm, - *tm2; - time_t time0; - - *bZone = FALSE; - tm.tm_year = st->y - 1900; - tm.tm_mon = st->m - 1; - tm.tm_mday = st->d; - tm.tm_hour = st->hh; - tm.tm_min = st->mm; - tm.tm_sec = st->ss; - tm.tm_isdst = -1; - time0 = mktime(&tm); - if (time0 < 0) - return TRUE; - if (tm.tm_isdst > 0) - timediff -= 3600; - if (timediff == 0) /* the same time zone */ - return TRUE; - time0 -= timediff; + t = SECS_ONEDAY * (int) (t / SECS_ONEDAY); + if (TIMEZONE_GLOBAL < 0) + t += SECS_ONEDAY; + else + t -= SECS_ONEDAY; + } + t += (st->withZone * (SECS_ONEHOUR * (st->hh - st->zonehh) + SECS_ONEMIN * (st->mm - st->zonemm) + st->ss - st->zoness)); #ifdef HAVE_LOCALTIME_R - if (time0 >= 0 && (tm2 = localtime_r(&time0, &tm)) != NULL) + if (t >= 0 && (tm2 = localtime_r(&t, &tm)) != NULL) #else - if (time0 >= 0 && (tm2 = localtime(&time0)) != NULL) + if (t >= 0 && (tm2 = localtime(&t)) != NULL) #endif /* HAVE_LOCALTIME_R */ + { + st->y = tm2->tm_year + 1900; + st->m = tm2->tm_mon + 1; + st->d = tm2->tm_mday; + st->hh = tm2->tm_hour; + st->mm = tm2->tm_min; + st->ss = tm2->tm_sec; + if (TIMEZONE_GLOBAL < 0) { - st->y = tm2->tm_year + 1900; - st->m = tm2->tm_mon + 1; - st->d = tm2->tm_mday; - st->hh = tm2->tm_hour; - st->mm = tm2->tm_min; - st->ss = tm2->tm_sec; - *bZone = TRUE; + st->withZone = 1; + st->zonehh = (signed char) (-TIMEZONE_GLOBAL / SECS_ONEHOUR); + st->zonemm = (signed char) ((-TIMEZONE_GLOBAL % SECS_ONEHOUR) / SECS_ONEMIN); + st->zoness = (signed char) (-TIMEZONE_GLOBAL % SECS_ONEMIN); + if (tm2->tm_isdst) + st->zonehh++; + } + else + { + st->withZone = -1; + st->zonehh = (signed char) (TIMEZONE_GLOBAL / SECS_ONEHOUR); + st->zonemm = (signed char) ((TIMEZONE_GLOBAL % SECS_ONEHOUR) / SECS_ONEMIN); + st->zoness = (signed char) (TIMEZONE_GLOBAL % SECS_ONEMIN); + if (tm2->tm_isdst) + st->zonehh--; } } #endif /* TIMEZONE_GLOBAL */ + return TRUE; } +/* + * TIMESTAMP string expression <----- SIMPLE_TIME + */ static BOOL -stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision) +stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL useZone, int precision) { char precstr[16], zonestr[16]; int i; +mylog("!!! %s useZone=%d precision=%d\n", __FUNCTION__, useZone, precision); precstr[0] = '\0'; if (st->infinity > 0) { @@ -358,12 +485,22 @@ stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision) strcpy(str, MINFINITY_STRING); return TRUE; } + else if (st->invalid != 0) + { + strcpy(str, MINVALID_STRING); + return TRUE; + } if (precision > 0 && st->fr) { + int precmax; + sprintf(precstr, ".%09d", st->fr); if (precision < 9) precstr[precision + 1] = '\0'; - for (i = precision; i > 0; i--) + precmax = strlen(precstr); + if (precision < precmax) + precmax = precision; + for (i = precmax - 1; i > 0; i--) { if (precstr[i] != '0') break; @@ -373,33 +510,76 @@ stime2timestamp(const SIMPLE_TIME *st, char *str, BOOL bZone, int precision) precstr[i] = '\0'; } zonestr[0] = '\0'; -#ifdef TIMEZONE_GLOBAL - if (bZone && tzname[0] && tzname[0][0] && st->y >= 1970) + if (useZone) { - long zoneint; - struct tm tm; - time_t time0; - - zoneint = TIMEZONE_GLOBAL; - if (daylight && st->y >= 1900) + if (st->withZone > 0) { - tm.tm_year = st->y - 1900; - tm.tm_mon = st->m - 1; - tm.tm_mday = st->d; - tm.tm_hour = st->hh; - tm.tm_min = st->mm; - tm.tm_sec = st->ss; - tm.tm_isdst = -1; - time0 = mktime(&tm); - if (time0 >= 0 && tm.tm_isdst > 0) - zoneint -= 3600; + if (st->zoness != 0) + sprintf(zonestr, "+%02d:%02d:%02d", (int) st->zonehh, (int) st->zonemm, (int) st->zoness); + else if (st->zonemm != 0) + sprintf(zonestr, "+%02d:%02d", (int) st->zonehh, (int) st->zonemm); + else + sprintf(zonestr, "+%02d", (int) st->zonehh); + } + else if (st->withZone < 0) + { + if (st->zoness != 0) + sprintf(zonestr, "-%02d:%02d:%02d", (int) st->zonehh, (int) st->zonemm, (int) st->zoness); + else if (st->zonemm != 0) + sprintf(zonestr, "-%02d:%02d", (int) st->zonehh, (int) st->zonemm); + else + sprintf(zonestr, "-%02d", (int) st->zonehh); + } +#ifdef TIMEZONE_GLOBAL + else if (st->y >= 1970) + { + long zoneint; + int zonehh, zonemm, zoness; + struct tm tm; + time_t time0; + + zoneint = TIMEZONE_GLOBAL; + if (DAYLIGHT_GLOBAL) + { + tm.tm_year = st->y - 1900; + tm.tm_mon = st->m - 1; + tm.tm_mday = st->d; + tm.tm_hour = st->hh; + tm.tm_min = st->mm; + tm.tm_sec = st->ss; + tm.tm_isdst = -1; + time0 = mktime(&tm); + if (time0 >= 0 && tm.tm_isdst > 0) + zoneint -= SECS_ONEHOUR; + } + if (zoneint < 0) + { + zonehh = (-zoneint) / SECS_ONEHOUR; + zonemm = ((-zoneint) % SECS_ONEHOUR) / SECS_ONEMIN; + zoness = (-zoneint) % SECS_ONEMIN; + if (zoness != 0) + sprintf(zonestr, "+%02d:%02d:%02d", (int) zonehh, (int) zonemm, (int) zoness); + else if (zonemm != 0) + sprintf(zonestr, "+%02d:%02d", (int) zonehh, (int) zonemm); + else + sprintf(zonestr, "+%02d", (int) zonehh); + } + else + { + zonehh = zoneint / SECS_ONEHOUR; + zonemm = (zoneint % SECS_ONEHOUR) / SECS_ONEMIN; + zoness = zoneint % SECS_ONEMIN; + if (zoness != 0) + sprintf(zonestr, "-%02d:%02d:%02d", (int) zonehh, (int) zonemm, (int) zoness); + else if (zonemm != 0) + sprintf(zonestr, "-%02d:%02d", (int) zonehh, (int) zonemm); + else + sprintf(zonestr, "-%02d", (int) zonehh); + } } - if (zoneint > 0) - sprintf(zonestr, "-%02d", (int) zoneint / 3600); - else - sprintf(zonestr, "+%02d", -(int) zoneint / 3600); - } #endif /* TIMEZONE_GLOBAL */ + } + if (st->y < 0) sprintf(str, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s BC", -st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); else @@ -848,7 +1028,7 @@ mylog("null_cvt_date_string=%d\n", conn->connInfo.cvt_null_date_string); /* a speicial handling for FOXPRO NULL -> NULL_STRING */ if (conn->connInfo.cvt_null_date_string > 0 && (PG_TYPE_DATE == field_type || - PG_TYPE_DATETIME == field_type || + PG_TYPE_TIMESTAMP_W_TMZONE == field_type || PG_TYPE_TIMESTAMP_NO_TMZONE == field_type) && (SQL_C_CHAR == fCType || #ifdef UNICODE_SUPPORT @@ -942,64 +1122,11 @@ mylog("null_cvt_date_string=%d\n", conn->connInfo.cvt_null_date_string); break; case PG_TYPE_ABSTIME: - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: - case PG_TYPE_TIMESTAMP: - std_time.fr = 0; - std_time.infinity = 0; - if (strnicmp(value, INFINITY_STRING, 8) == 0) - { - std_time.infinity = 1; - std_time.m = 12; - std_time.d = 31; - std_time.y = 9999; - std_time.hh = 23; - std_time.mm = 59; - std_time.ss = 59; - } - if (strnicmp(value, MINFINITY_STRING, 9) == 0) - { - std_time.infinity = -1; - std_time.m = 1; - std_time.d = 1; - // std_time.y = -4713; - std_time.y = -9999; - std_time.hh = 0; - std_time.mm = 0; - std_time.ss = 0; - } - if (strnicmp(value, "invalid", 7) != 0) - { - BOOL bZone = (field_type != PG_TYPE_TIMESTAMP_NO_TMZONE && PG_VERSION_GE(conn, 7.2)); - int zone; - - /* - * sscanf(value, "%4d-%2d-%2d %2d:%2d:%2d", &std_time.y, &std_time.m, - * &std_time.d, &std_time.hh, &std_time.mm, &std_time.ss); - */ - bZone = FALSE; /* time zone stuff is unreliable */ - timestamp2stime(value, &std_time, &bZone, &zone); + case PG_TYPE_DEPRECATED_TIMESTAMP: + timestamp2stime(value, &std_time, use_local_time_zone && TIME_ZONE_TYPE(field_type)); inolog("2stime fr=%d\n", std_time.fr); - } - else - { - /* - * The timestamp is invalid so set something conspicuous, - * like the epoch - */ - time_t t = 0; -#ifdef HAVE_LOCALTIME_R - tim = localtime_r(&t, &tm); -#else - tim = localtime(&t); -#endif /* HAVE_LOCALTIME_R */ - std_time.m = tim->tm_mon + 1; - std_time.d = tim->tm_mday; - std_time.y = tim->tm_year + 1900; - std_time.hh = tim->tm_hour; - std_time.mm = tim->tm_min; - std_time.ss = tim->tm_sec; - } break; case PG_TYPE_BOOL: @@ -1170,16 +1297,20 @@ inolog("2stime fr=%d\n", std_time.fr); break; case PG_TYPE_ABSTIME: - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: len = 19; if (cbValueMax > len) { - /* sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", - std_time.y, std_time.m, std_time.d, std_time.hh, std_time.mm, std_time.ss); */ - stime2timestamp(&std_time, rgbValueBindRow, FALSE, - PG_VERSION_GE(conn, 7.2) ? (int) cbValueMax - len - 2 : 0); + int precmax = (int) cbValueMax - len - 2; + if (precision > 0 && + precision < precmax) + precmax = precision; + + stime2timestamp(&std_time, rgbValueBindRow + , use_time_zone_expression && TIME_ZONE_TYPE(field_type) + , PG_VERSION_GE(conn, 7.2) ? precmax : 0); len = strlen(rgbValueBindRow); } break; @@ -2557,7 +2688,7 @@ Prepare_and_convert(StatementClass *stmt, QueryParse *qp, QueryBuild *qb) if (QB_initialize(qb, qp->stmt_len, stmt, NULL) < 0) return SQL_ERROR; if (PROTOCOL_74(ci)) - return prep_params(stmt, qp, qb, FALSE); + return prep_params(stmt, qp, qb, TRUE); discardOutput = (0 != (qb->flags & FLGB_DISCARD_OUTPUT)); if (NOT_YET_PREPARED == stmt->prepared) /* not yet prepared */ { @@ -4498,7 +4629,7 @@ mylog("C_WCHAR=%s(%d)\n", buffer, used); mylog("cvt_null_date_string=%d pgtype=%d buf=%p\n", conn->connInfo.cvt_null_date_string, param_pgtype, buf); if (conn->connInfo.cvt_null_date_string > 0 && (PG_TYPE_DATE == param_pgtype || - PG_TYPE_DATETIME == param_pgtype || + PG_TYPE_TIMESTAMP_W_TMZONE == param_pgtype || PG_TYPE_TIMESTAMP_NO_TMZONE == param_pgtype) && NULL != buf && ( @@ -4543,6 +4674,10 @@ mylog("buf=%p flag=%d\n", buf, qb->flags); break; } } + if (0 == param_sqltype && + 0 != param_pgtype && + NULL != qb->stmt) + param_sqltype = pgtype_to_concise_type(qb->stmt, param_pgtype, PG_STATIC); switch (param_sqltype) { case SQL_CHAR: @@ -4638,13 +4773,9 @@ mylog("buf=%p flag=%d\n", buf, qb->flags); parse_datetime(cbuf, &st); } - /* - * sprintf(tmp, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", st.y, - * st.m, st.d, st.hh, st.mm, st.ss); - */ - /* Time zone stuff is unreliable */ - stime2timestamp(&st, tmp, USE_ZONE, PG_VERSION_GE(conn, 7.2) ? 6 : 0); - lastadd = "::timestamp"; + stime2timestamp(&st, tmp + , use_local_time_zone && TIME_ZONE_TYPE(param_pgtype) + , PG_VERSION_GE(conn, 7.2) ? 6 : 0); CVT_APPEND_STR(qb, tmp); break; @@ -5368,8 +5499,13 @@ parse_datetime(const char *buf, SIMPLE_TIME *st) y = m = d = hh = mm = ss = 0; st->fr = 0; st->infinity = 0; + st->invalid = 0; + st->withZone = 0; - /* escape sequence ? */ + /* + * If input is an escape sequence + * skip until a quote comes. + */ if (buf[0] == ODBC_ESCAPE_START) { while (*(++buf) && *buf != LITERAL_QUOTE); @@ -5377,6 +5513,25 @@ parse_datetime(const char *buf, SIMPLE_TIME *st) return FALSE; buf++; } + + /* check hh:mm:ss first */ + if (buf[2] == ':') + { + nf = sscanf(buf, "%2d:%2d:%2d", &hh, &mm, &ss); + if (nf == 2 || nf == 3) + { + st->hh = hh; + st->mm = mm; + st->ss = ss; + + return TRUE; + } + return FALSE; + } + + if (timestamp2stime(buf, st, use_local_time_zone)) + return TRUE; + if (buf[4] == '-') /* year first */ nf = sscanf(buf, "%4d-%2d-%2d %2d:%2d:%2d", &y, &m, &d, &hh, &mm, &ss); else @@ -5408,16 +5563,6 @@ parse_datetime(const char *buf, SIMPLE_TIME *st) return TRUE; } - nf = sscanf(buf, "%2d:%2d:%2d", &hh, &mm, &ss); - if (nf == 2 || nf == 3) - { - st->hh = hh; - st->mm = mm; - st->ss = ss; - - return TRUE; - } - return FALSE; } diff --git a/convert.h b/convert.h index 984eff5..476bd4e 100644 --- a/convert.h +++ b/convert.h @@ -28,7 +28,9 @@ extern "C" { typedef struct { - int infinity; + char infinity; + char invalid; + char withZone; int m; int d; int y; @@ -36,6 +38,9 @@ typedef struct int mm; int ss; int fr; + char zonehh; + char zonemm; + char zoness; } SIMPLE_TIME; int copy_and_convert_field_bindinfo(StatementClass *stmt, OID field_type, int atttypmod, void *value, int col); diff --git a/info.c b/info.c index 81bfe6d..46937ff 100644 --- a/info.c +++ b/info.c @@ -2539,7 +2539,7 @@ mylog(" and the data=%s\n", attdef); set_tuplefield_int4(&tuple[COLUMNS_DISPLAY_SIZE], column_size + 2); /* sign+dec.point */ } } - else if ((field_type == PG_TYPE_DATETIME) || + else if ((field_type == PG_TYPE_TIMESTAMP_W_TMZONE) || (field_type == PG_TYPE_TIMESTAMP_NO_TMZONE)) { if (PG_VERSION_GE(conn, 7.2)) @@ -2615,7 +2615,7 @@ mylog(" and the data=%s\n", attdef); /* Subtract the header length */ switch (field_type) { - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: case PG_TYPE_TIME: case PG_TYPE_TIME_WITH_TMZONE: diff --git a/parse.c b/parse.c index 5aa7723..eef11d8 100644 --- a/parse.c +++ b/parse.c @@ -57,7 +57,7 @@ Int4 FI_precision(const FIELD_INFO *fi) { case PG_TYPE_NUMERIC: return fi->column_size; - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: return fi->decimal_digits; } diff --git a/pgtypes.c b/pgtypes.c index d7bde0a..ca8469f 100644 --- a/pgtypes.c +++ b/pgtypes.c @@ -54,7 +54,7 @@ OID pgtypes_defined[][2] = { ,{PG_TYPE_DATE, 0} ,{PG_TYPE_TIME, 0} ,{PG_TYPE_TIME_WITH_TMZONE, 0} - ,{PG_TYPE_DATETIME, 0} + ,{PG_TYPE_TIMESTAMP_W_TMZONE, 0} ,{PG_TYPE_ABSTIME, 0} ,{PG_TYPE_TIMESTAMP_NO_TMZONE, 0} ,{PG_TYPE_TIMESTAMP, 0} @@ -619,9 +619,9 @@ pgtype_attr_to_concise_type(const ConnectionClass *conn, OID type, int atttypmod #endif /* ODBCVER */ return SQL_TIME; case PG_TYPE_ABSTIME: - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: #if (ODBCVER >= 0x0300) if (EN_is_odbc3(env)) return SQL_TYPE_TIMESTAMP; @@ -768,9 +768,9 @@ pgtype_attr_to_ctype(const ConnectionClass *conn, OID type, int atttypmod) #endif /* ODBCVER */ return SQL_C_TIME; case PG_TYPE_ABSTIME: - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: #if (ODBCVER >= 0x0300) if (EN_is_odbc3(env)) return SQL_C_TYPE_TIMESTAMP; @@ -867,7 +867,7 @@ inolog("pgtype_to_name int4\n"); return "time"; case PG_TYPE_ABSTIME: return "abstime"; - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: if (PG_VERSION_GT(conn, 7.1)) return "timestamptz"; else if (PG_VERSION_LT(conn, 7.0)) @@ -876,7 +876,7 @@ inolog("pgtype_to_name int4\n"); return "timestamp"; case PG_TYPE_TIMESTAMP_NO_TMZONE: return "timestamp without time zone"; - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: return "timestamp"; case PG_TYPE_MONEY: return "money"; @@ -994,9 +994,9 @@ pgtype_attr_column_size(const ConnectionClass *conn, OID type, int atttypmod, in return 8; case PG_TYPE_ABSTIME: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: return 22; - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: /* return 22; */ return getTimestampColumnSizeX(conn, type, atttypmod); @@ -1039,7 +1039,7 @@ pgtype_attr_precision(const ConnectionClass *conn, OID type, int atttypmod, int { case PG_TYPE_NUMERIC: return getNumericColumnSizeX(conn, type, atttypmod, adtsize_or_longest, handle_unknown_size_as); - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: return getTimestampDecimalDigitsX(conn, type, atttypmod); #ifdef PG_INTERVAL_AS_SQL_INTERVAL @@ -1138,8 +1138,8 @@ pgtype_attr_buffer_length(const ConnectionClass *conn, OID type, int atttypmod, return 6; /* sizeof(DATE(TIME)_STRUCT) */ case PG_TYPE_ABSTIME: - case PG_TYPE_DATETIME: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_TIMESTAMP_W_TMZONE: + case PG_TYPE_DEPRECATED_TIMESTAMP: case PG_TYPE_TIMESTAMP_NO_TMZONE: return 16; /* sizeof(TIMESTAMP_STRUCT) */ @@ -1223,9 +1223,9 @@ pgtype_attr_desclength(const ConnectionClass *conn, OID type, int atttypmod, int case PG_TYPE_DATE: case PG_TYPE_TIME: case PG_TYPE_ABSTIME: - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: case PG_TYPE_VARCHAR: case PG_TYPE_BPCHAR: return pgtype_attr_column_size(conn, type, atttypmod, adtsize_or_longestlen, handle_unknown_size_as); @@ -1254,9 +1254,9 @@ pgtype_attr_decimal_digits(const ConnectionClass *conn, OID type, int atttypmod, * "yyyy-mm=dd hh:mm:ss[.f...]" */ case PG_TYPE_ABSTIME: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: return 0; - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: /* return 0; */ return getTimestampDecimalDigitsX(conn, type, atttypmod); @@ -1413,7 +1413,7 @@ sqltype_to_pgtype(const ConnectionClass *conn, SQLSMALLINT fSqlType) #if (ODBCVER >= 0x0300) case SQL_TYPE_TIMESTAMP: #endif /* ODBCVER */ - pgType = PG_TYPE_DATETIME; + pgType = PG_TYPE_TIMESTAMP_W_TMZONE; break; case SQL_VARBINARY: @@ -1940,8 +1940,8 @@ pgtype_min_decimal_digits(const ConnectionClass *conn, OID type) case PG_TYPE_MONEY: case PG_TYPE_BOOL: case PG_TYPE_ABSTIME: - case PG_TYPE_TIMESTAMP: - case PG_TYPE_DATETIME: + case PG_TYPE_DEPRECATED_TIMESTAMP: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: case PG_TYPE_NUMERIC: return 0; @@ -1968,9 +1968,9 @@ pgtype_max_decimal_digits(const ConnectionClass *conn, OID type) case PG_TYPE_MONEY: case PG_TYPE_BOOL: case PG_TYPE_ABSTIME: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: return 0; - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: return 38; case PG_TYPE_NUMERIC: @@ -2053,9 +2053,9 @@ pgtype_auto_increment(const ConnectionClass *conn, OID type) case PG_TYPE_TIME_WITH_TMZONE: case PG_TYPE_TIME: case PG_TYPE_ABSTIME: - case PG_TYPE_DATETIME: + case PG_TYPE_TIMESTAMP_W_TMZONE: case PG_TYPE_TIMESTAMP_NO_TMZONE: - case PG_TYPE_TIMESTAMP: + case PG_TYPE_DEPRECATED_TIMESTAMP: return FALSE; default: diff --git a/pgtypes.h b/pgtypes.h index 6a9eead..5242c08 100644 --- a/pgtypes.h +++ b/pgtypes.h @@ -67,11 +67,11 @@ #define PG_TYPE_VARCHAR 1043 #define PG_TYPE_DATE 1082 #define PG_TYPE_TIME 1083 -#define PG_TYPE_TIMESTAMP_NO_TMZONE 1114 /* since 7.2 */ -#define PG_TYPE_DATETIME 1184 +#define PG_TYPE_TIMESTAMP_NO_TMZONE 1114 /* since 7.2 */ +#define PG_TYPE_TIMESTAMP_W_TMZONE 1184 /* DATETIME until 7.2 */ #define PG_TYPE_INTERVAL 1186 -#define PG_TYPE_TIME_WITH_TMZONE 1266 /* since 7.1 */ -#define PG_TYPE_TIMESTAMP 1296 /* deprecated since 7.0 */ +#define PG_TYPE_TIME_WITH_TMZONE 1266 /* since 7.1 */ +#define PG_TYPE_DEPRECATED_TIMESTAMP 1296 /* deprecated since 7.0 */ #define PG_TYPE_BIT 1560 #define PG_TYPE_NUMERIC 1700 #define PG_TYPE_REFCURSOR 1790
^ permalink raw reply [nested|flat] 12+ messages in thread

* Re: Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE
@ 2014-06-13 23:20  Walter Couto <Walter.Couto@EMBARCADERO.COM>
  parent: Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 0 replies; 12+ messages in thread

From: Walter Couto @ 2014-06-13 23:20 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: David Johnston <david.g.johnston@gmail.com>; Adrian Klaver <adrian.klaver@aklaver.com>; pgsql-odbc

I vote to leave the timestamp in the server's time zone. Maybe a driver option can be added in future to allow the user to choose between local and server.

On the string format, Microsoft has timestamp with timezone formats and old drivers or the new ones when you ask for the string will gives you the time zone in hh:mm. Teradata, Oracle and DB2 also return this format if the result is a string. I believe they all also clip the timezone (don't convert to local timezone) if you as for it as a SQL_TIMESTAMP.

Walter


-------- Original message --------
From: Hiroshi Inoue
Date:06/13/2014 6:09 PM (GMT-05:00)
To: Walter Couto
Cc: David Johnston ,Adrian Klaver ,pgsql-odbc@postgresql.org
Subject: Re: [ODBC] Re: Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE

Hi Walter and all,

While reading the old and disabled code, I remembered the circumstances
back then a little.
Psqlodbc had followed the formatting rule e.g. described at the last
line in
  http://msdn.microsoft.com/en-us/library/ms712387%28v=vs.85%29.aspx
.
Also look at
  http://msdn.microsoft.com/en-us/library/ms712360%28v=vs.85%29.aspx
.
There's no time zone in ODBC world and I'm afraid the possibility
that some applications are broken by adding time zone expression.

So please vote which way to choose?

1. Keep the current behavior, i.e. simply drop the time zone part
    from server's output if exists.
2. Use local time zone instead of server time zone but omit the time
    zone expression.
3. Use local time zone with the time zone expression when the data
    type is TIMESTAMP WITH TIME ZONE.
4. The others.

Anyway I attached a patch which implements the above 3.
It's easy to change to 2.

regarts,
Hiroshi Inoue

> Walter
>
>
> -------- Original message --------
> From: "Inoue, Hiroshi"
> Date:06/10/2014 11:39 PM (GMT-05:00)
> To: Walter Couto ,David Johnston
> Cc: Adrian Klaver ,pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Re: Inconsistency between JDBC and ODBC drivers when
> dealing with TIMESTAMP WITH TIME ZONE
>
> Hi Walter,
>
> I would enable time zone related code and complete the coding.
> When I make a patch, could you test it?


CONFIDENTIALITY NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.

^ permalink  raw  reply  [nested|flat] 12+ messages in thread


end of thread, other threads:[~2014-06-13 23:20 UTC | newest]

Thread overview: 12+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-06-09 19:15 Inconsistency between JDBC and ODBC drivers when dealing with TIMESTAMP WITH TIME ZONE Walter Couto <Walter.Couto@EMBARCADERO.COM>
2014-06-09 23:27 ` Adrian Klaver <adrian.klaver@aklaver.com>
2014-06-10 00:18 ` David G Johnston <david.g.johnston@gmail.com>
2014-06-10 02:49   ` Walter Couto <Walter.Couto@EMBARCADERO.COM>
2014-06-10 03:18     ` Adrian Klaver <adrian.klaver@aklaver.com>
2014-06-10 04:15       ` Inoue, Hiroshi <inoue@tpf.co.jp>
2014-06-10 05:04         ` David Johnston <david.g.johnston@gmail.com>
2014-06-10 10:31           ` Walter Couto <Walter.Couto@EMBARCADERO.COM>
2014-06-11 03:38             ` Inoue, Hiroshi <inoue@tpf.co.jp>
2014-06-11 03:42               ` Walter Couto <Walter.Couto@EMBARCADERO.COM>
2014-06-13 22:09                 ` Hiroshi Inoue <inoue@tpf.co.jp>
2014-06-13 23:20                   ` Walter Couto <Walter.Couto@EMBARCADERO.COM>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox