Costin Iordache | 13 Nov 2008 04:43

possible bug in odbc++ library

Hi all,

 

I know that this is an unixODBC mail list and my question is related to ODBC++ library but it was impossible to me to find a forum dedicated to ODBC++ library. Sorry for any inconvenience.  I think Timestamp class has a bug  and I’d be glad if somebody could confirm (or not) my supposition. Any comment/suggestion is welcomed.

 

Next, I shortly describe the steps to reproduce the problem, the problem description and the proposed fix:

 

Steps to reproduce:

 

1.       Create one DB (MY_DB)with one TIMESTAMP column  called “timecol”

2.       Set the computer TimeZone to “GMT+01:00 Madrid” with DST activated

3.       Write into the DB the timestamp “1225027900”; it corresponds to:

GMT timezone:    Sun, 26 Oct 2008 13:31:40 UTC

Madrid timezone: Sunday, October 26, 2008 2:31:40 PM

 

The following piece of code is used to save the timestamp:

….

std::time_t t = 1225027900;

odbc::PreparedStatement *ins_stmt(prepareStatement("insert into MY_DB (\"timecol\") values (?)"));

ins_stmt->setTimestamp( 1, odbc::Timestamp(t));

ins_stmt->executeUpdate();

4.       Now, read from MY_DB:

 

odbc::PreparedStatement *sel_stmt(conn->get()->prepareStatement( "select * from MY_DB" ) );

      odbc::ResultSet rset( sel_stmt->executeQuery() );

           

      odbc::Timestamp ts( rset->getTimestamp(1));

std::time_t loadedFromDB = ts.getTime();

 

5.       The value retrieved from DB of loadedFromDB should be 1225027900 but instead its value is 3600 seconds less, that is, 1225024300!

 

Problem description:

 

Note: The 26th of October at 03:00 AM , Madrid’s TS, is when the transition from Daylight Saving Time (DST) to Standard Time (ST) takes place.

 

·         When writing data to the DB the Timezone constructor calls setTime(std::time_t) which in turn calls std::localtime. Thus, what we actually get saved into the DB is a local time, i.e, in our particular case: Sunday, October 26, 2008 2:31:40 PM which is correct taking into consideration that Madrid’s TZ is one hour ahead GMT.

·         When reading data back from the DB we first retrieve an object “ts” which holds exactly the date from the DB, i.e., Sunday, October 26, 2008 2:31:40 PM. So far, so good. Now comes into play odbc::Tiemstamp::getTime() method which is supposed to transform back the local time kept inside “ts” object into UTC. Basically what it does is (for the sake of simplicity I won’t show all code details):

 

time_t Time::getTime() const

{

tm stm;

stm.tm_year=year_-1900;

stm.tm_mon=month_-1;

stm.tm_mday=day_;

stm.tm_hour=0;  //red row

stm.tm_min=0;   //red row

stm.tm_sec=0;   //red row

  stm.tm_isdst=-1; //negative means not known

 

  return std::mktime(&stm) + second_ + minute_*60 + hour_*3600;

           }

 

                The problem we got here is easy to spot: std::mktime is passed 00:00 AM (see the rows highlighted in red) that is, three hours before the DST takes place. Therefore, std::mktime is unaware that the time we actually want to compute is ST. If we passed day 27th instead of 26th , std::mktime would return the correct result because the hours, minutes and seconds wouldn’t matter to decide whether we have to deal with DST or ST!

 

 

Proposed fix:

 

File

Code to be replaced

Replacement

Add

libodbc++-0.2.3\include\odbc++ \types.h

/** Gets the time_t value of this timestamp */

virtual std::time_t  Timestamp::getTime() {

return Date::getTime()+Time::getTime();

}

/** Gets the time_t value of this timestamp */

virtual std::time_t getTime();

-

libodbc++-0.2.3\src\ datetime.cpp

-

-

std::time_t Timestamp::getTime()

{

tm stm;

stm.tm_year=year_-1900;

stm.tm_mon=month_-1;

stm.tm_mday=day_;

stm.tm_hour=hour_;

stm.tm_min=minute_;

stm.tm_sec=second_;

stm.tm_isdst=-1; //negative means not known

return mktime(&stm);

}

 

 

Thanks for any help/suggestion,

Costin.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev
Nick Gorham | 14 Nov 2008 15:08
Favicon

Re: possible bug in odbc++ library

Costin Iordache wrote:

>Hi all,
>
> 
>
>I know that this is an unixODBC mail list and my question is related to
>ODBC++ library but it was impossible to me to find a forum dedicated to
>ODBC++ library. Sorry for any inconvenience.  I think Timestamp class has a
>bug  and I'd be glad if somebody could confirm (or not) my supposition. Any
>comment/suggestion is welcomed.
>  
>
from

http://libodbcxx.sourceforge.net/

I would try

libodbcxx-devel <at> lists.sourceforge.net 
<mailto:libodbcxx-devel <at> lists.sourceforge.net>

Looking at the archives, it seems active. Though as you were the last 
poster, maybe there isn't much going on.

--

-- 
Nick
_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

Costin Iordache | 14 Nov 2008 03:46

Re: possible bug in odbc++ library

Thanks Nick!

-----Original Message-----
From: unixodbc-dev-bounces <at> mailman.unixodbc.org
[mailto:unixodbc-dev-bounces <at> mailman.unixodbc.org] On Behalf Of Nick Gorham
Sent: Friday, November 14, 2008 3:09 PM
To: Development issues and topics for unixODBC
Subject: Re: [unixODBC-dev] possible bug in odbc++ library

Costin Iordache wrote:

>Hi all,
>
> 
>
>I know that this is an unixODBC mail list and my question is related to
>ODBC++ library but it was impossible to me to find a forum dedicated to
>ODBC++ library. Sorry for any inconvenience.  I think Timestamp class has a
>bug  and I'd be glad if somebody could confirm (or not) my supposition. Any
>comment/suggestion is welcomed.
>  
>
from

http://libodbcxx.sourceforge.net/

I would try

libodbcxx-devel <at> lists.sourceforge.net 
<mailto:libodbcxx-devel <at> lists.sourceforge.net>

Looking at the archives, it seems active. Though as you were the last 
poster, maybe there isn't much going on.

--

-- 
Nick
_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

Nick Gorham | 18 Nov 2008 11:02
Favicon

2.2.13

Ok, well, I think the time has come to release this into the wild....

ChangeLog:

    * There was a mutex around iconv that needed adding. Without this,
      there was a potential thread problem
    * Fix problem with SQLGetDiagRec/Field returning double driver
      errors
    * odbctest was using the wrong handle for SQLGetConnectOption
    * remove startup thread race condition
    * fix descriptor memory leak with UNICODE only drivers (thanks Ian)
    * Alter the default 64bit build mode, and change the flag to
      BUILD_LEGACY_64_BIT_MODE
    * Fix a couple of 64bit problems
    * create unixodbc_conf.h on install to contain compile settings
    * Allow the GUI parts to build with qt4
    * try and deal with drivers that call internal W functions and
      end up in the driver manager (informix for example). Enabled
      by --enable-handlemap=yes when configuring
    * Fix leak of iconv handles
    * Allow the setup API to call through to the wide driver functions
    * Fix potential seg fault in SQLGetPrivateProfileString
    * Fix a couple of broken casts, and some MS 64bit changes
    * Add check for postgres driver getting into a spin wait
    * Fix logging that reported the setting of env attrs failing
    * Add isql option to wrap strings with quotes
    * Add isql option -3 to make isql use ODBC 3 calls instead of 2
    * Add timestamp to logging output
    * Pull any errors from driver whern SQLBrowseConnect returns 
SQL_NEED_DATA
    * isql now displays any warnings from SQLMoreResults
    * Add include path to odbc_config --cflags output
    * Fix some SQLLEN/SQLINTEGER conflicts in the cursor lib
    * isql now checks if the driver has SQLMoreResults before calling it
    * A couple of tweeks in the txt driver
    * Fix More than 1 log msg relevant in odbcinst now
    * Changed UI plugin technique for odbcinst see...
      ODBCConfig > main.cpp, and
      odbcinst > SQLManageDataSources.c and
      odbcinstQ4 > SQLManageDataSources.cpp
    * Add more 64 bit changes, remove SQLROWCOUNT and its frends from 64 bit
      land
    * Couple of descriptor typo's fixed (Thanks Jess)
    * Add odbcinstQ4 to support pure Qt4 SQLCreateDataSource and
      SQLManageDataSources
    * Add ODBCCreateDataSourceQ4 as Qt4 based exec to SQLCreateDataSource
    * Add ODBCManageDataSourcesQ4 as Qt4 based exec to SQLManageDataSources
    * Add "-c" option to odbcinst to call SQLCreateDataSource
    * Add "-m" option to odbcinst to call SQLManageDataSources
    * Add ODBCDataManagerQ4
    * Add Wrappers (C++, QtCore 4, QtGui 4 - thin wrappers to ODBC)
    * Add more complete set of driver config options to GUI config
    * Fix incorrect export file in odbcinstQ
    * Added some extra features to isql (thanks to Ron Norman for the
          ideas)
    * Add diag support lib for driver development  and possibly DM
      This is very 'black-boxed' on purpose.
    * Fix Replaced diag code in txt driver to use new diag lib.
    * Add New odbctrac library.
    * Add Threading can not be config via Qt(4) based GUI
    * Add New ODBCString library.
    * Add odbcinst.ini -> ODBC -> TraceLibrary and corresponding GUI Qt(4)
      config.
    * prevent the cursor lib from seg faulting if the query isn't a select
    * Add SQLULEN size display to the output of odbcinst -j
    * Add mutexes in odbcinst/_logging.c
    * Remove the MySQL Driver, its woefully out of date now
    * Remove incorrect path in vms_odbc.opt
    * rename trace.h to odbctrace.h to avoid potential name conflicts
      and move to include dir
    * update unixODBC.spec file
    * Add README.CYGWIN
    * Fix build problem with QT4 without QWizard support
    * Alter how the Ansi-Unicode mapping is done, so a unicode function 
can be
      passed to the driver (if it supports it) even if a non unicode 
connect was done
    * Fix buffer overrun in SQLDriverConnectW and SQLColAttributesW
    * I have cut back on a lot of the GUI parts that are being added. 
The goal is to
      create a distinct set of files that contains these and other parts 
that are
      not part of the core goal of providing ODBC. Likewise the drivers 
will go on the
      next release, as most DB's now have their own folk working on 
their drivers
      and they all interoperate with unixODBC so its just adding 
confusion including them
      here (IMHO that is)
    * Prevent a potential buffer overrun in the DM
    * The processing of --enable-rtldgroup had been dropped, back now
    * Allow the cursor lib to handle multiple result sets

Any problems, let me know.

Ta.

--

-- 
Nick Gorham
_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

Arun K.Desai | 18 Nov 2008 11:13
Picon
Favicon

Re: 2.2.13

Great!
Download link still points to 2.2.12. Is it uploaded to some other location?

Best,
Arun

Nick Gorham wrote:

> Ok, well, I think the time has come to release this into the wild....
>
> ChangeLog:
>
>    * There was a mutex around iconv that needed adding. Without this,
>      there was a potential thread problem
>    * Fix problem with SQLGetDiagRec/Field returning double driver
>      errors
>    * odbctest was using the wrong handle for SQLGetConnectOption
>    * remove startup thread race condition
>    * fix descriptor memory leak with UNICODE only drivers (thanks Ian)
>    * Alter the default 64bit build mode, and change the flag to
>      BUILD_LEGACY_64_BIT_MODE
>    * Fix a couple of 64bit problems
>    * create unixodbc_conf.h on install to contain compile settings
>    * Allow the GUI parts to build with qt4
>    * try and deal with drivers that call internal W functions and
>      end up in the driver manager (informix for example). Enabled
>      by --enable-handlemap=yes when configuring
>    * Fix leak of iconv handles
>    * Allow the setup API to call through to the wide driver functions
>    * Fix potential seg fault in SQLGetPrivateProfileString
>    * Fix a couple of broken casts, and some MS 64bit changes
>    * Add check for postgres driver getting into a spin wait
>    * Fix logging that reported the setting of env attrs failing
>    * Add isql option to wrap strings with quotes
>    * Add isql option -3 to make isql use ODBC 3 calls instead of 2
>    * Add timestamp to logging output
>    * Pull any errors from driver whern SQLBrowseConnect returns 
> SQL_NEED_DATA
>    * isql now displays any warnings from SQLMoreResults
>    * Add include path to odbc_config --cflags output
>    * Fix some SQLLEN/SQLINTEGER conflicts in the cursor lib
>    * isql now checks if the driver has SQLMoreResults before calling it
>    * A couple of tweeks in the txt driver
>    * Fix More than 1 log msg relevant in odbcinst now
>    * Changed UI plugin technique for odbcinst see...
>      ODBCConfig > main.cpp, and
>      odbcinst > SQLManageDataSources.c and
>      odbcinstQ4 > SQLManageDataSources.cpp
>    * Add more 64 bit changes, remove SQLROWCOUNT and its frends from 
> 64 bit
>      land
>    * Couple of descriptor typo's fixed (Thanks Jess)
>    * Add odbcinstQ4 to support pure Qt4 SQLCreateDataSource and
>      SQLManageDataSources
>    * Add ODBCCreateDataSourceQ4 as Qt4 based exec to SQLCreateDataSource
>    * Add ODBCManageDataSourcesQ4 as Qt4 based exec to 
> SQLManageDataSources
>    * Add "-c" option to odbcinst to call SQLCreateDataSource
>    * Add "-m" option to odbcinst to call SQLManageDataSources
>    * Add ODBCDataManagerQ4
>    * Add Wrappers (C++, QtCore 4, QtGui 4 - thin wrappers to ODBC)
>    * Add more complete set of driver config options to GUI config
>    * Fix incorrect export file in odbcinstQ
>    * Added some extra features to isql (thanks to Ron Norman for the
>          ideas)
>    * Add diag support lib for driver development  and possibly DM
>      This is very 'black-boxed' on purpose.
>    * Fix Replaced diag code in txt driver to use new diag lib.
>    * Add New odbctrac library.
>    * Add Threading can not be config via Qt(4) based GUI
>    * Add New ODBCString library.
>    * Add odbcinst.ini -> ODBC -> TraceLibrary and corresponding GUI Qt(4)
>      config.
>    * prevent the cursor lib from seg faulting if the query isn't a select
>    * Add SQLULEN size display to the output of odbcinst -j
>    * Add mutexes in odbcinst/_logging.c
>    * Remove the MySQL Driver, its woefully out of date now
>    * Remove incorrect path in vms_odbc.opt
>    * rename trace.h to odbctrace.h to avoid potential name conflicts
>      and move to include dir
>    * update unixODBC.spec file
>    * Add README.CYGWIN
>    * Fix build problem with QT4 without QWizard support
>    * Alter how the Ansi-Unicode mapping is done, so a unicode function 
> can be
>      passed to the driver (if it supports it) even if a non unicode 
> connect was done
>    * Fix buffer overrun in SQLDriverConnectW and SQLColAttributesW
>    * I have cut back on a lot of the GUI parts that are being added. 
> The goal is to
>      create a distinct set of files that contains these and other 
> parts that are
>      not part of the core goal of providing ODBC. Likewise the drivers 
> will go on the
>      next release, as most DB's now have their own folk working on 
> their drivers
>      and they all interoperate with unixODBC so its just adding 
> confusion including them
>      here (IMHO that is)
>    * Prevent a potential buffer overrun in the DM
>    * The processing of --enable-rtldgroup had been dropped, back now
>    * Allow the cursor lib to handle multiple result sets
>
> Any problems, let me know.
>
> Ta.
>

_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

Nick Gorham | 18 Nov 2008 11:19
Favicon

Re: 2.2.13

Arun K.Desai wrote:

> Great!
> Download link still points to 2.2.12. Is it uploaded to some other 
> location?
>
It doesn't now :-)

--

-- 
Nick
_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

Nick Gorham | 20 Nov 2008 10:51
Favicon

2.2.14

Well, just when you thought it was safe. 2.2.13 had a missing prototype 
that caused some 64 bit builds to be unusable. So its been replaced by 
2,2,14.

Oh, well, it gets the averages up.

--

-- 
Nick
_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

Tom Lane | 25 Nov 2008 18:12
Picon

text driver disappeared from 2.2.13/14 ???

Nick Gorham <nick <at> lurcher.org> writes:
> ChangeLog:
>     * A couple of tweeks in the txt driver

Apparently, "a couple of tweeks" means "remove it entirely".
I hope this is not intentional ... I know I've got users that will
be unhappy if the text driver disappears from Fedora.

			regards, tom lane
_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

Nick Gorham | 25 Nov 2008 18:23
Favicon

Re: text driver disappeared from 2.2.13/14 ???

Tom Lane wrote:

>Nick Gorham <nick <at> lurcher.org> writes:
>  
>
>>ChangeLog:
>>    * A couple of tweeks in the txt driver
>>    
>>
>
>Apparently, "a couple of tweeks" means "remove it entirely".
>I hope this is not intentional ... I know I've got users that will
>be unhappy if the text driver disappears from Fedora.
>
>			regards, tom lane
>_______________________________________________
>unixODBC-dev mailing list
>unixODBC-dev <at> mailman.unixodbc.org
>http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev
>
>
>  
>
The intention is to split the driver manager core parts from the rest, 
the text driver falls with the rest. AFAIK, its had almost no changes 
for years now, so there is no reason to change.

TBH, based on the lasck of feedback I get, I assumed that no one used 
it. Seems I was wrong.

Its all still in the CVS, so can be packaged up on its own.

--

-- 
Nick Gorham
Easysoft Limited
http://www.easysoft.com, http://www.unixODBC.org

_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev

Tom Lane | 25 Nov 2008 18:31
Picon

Re: text driver disappeared from 2.2.13/14 ???

Nick Gorham <nick.gorham <at> easysoft.com> writes:
> Tom Lane wrote:
>> I hope this is not intentional ... I know I've got users that will
>> be unhappy if the text driver disappears from Fedora.

> TBH, based on the lasck of feedback I get, I assumed that no one used 
> it. Seems I was wrong.

Well, Red Hat's gotten bug reports on it from paying customers, eg
https://bugzilla.redhat.com/show_bug.cgi?id=162676
so *somebody* out there is using it.

To my mind the text driver is useful because it allows testing unixODBC
without any dependency on any external database solution; though I grant
it might be too simplistic to be good for very much in that line.

> Its all still in the CVS, so can be packaged up on its own.

That would be a feasible solution I guess.

BTW, how come you removed the mysql driver as obsolete (which it was)
and kept the postgres driver (which is too)?  For Fedora/RHEL I'd prefer
to be shipping just the separately maintained mysql and postgres
drivers.

			regards, tom lane
_______________________________________________
unixODBC-dev mailing list
unixODBC-dev <at> mailman.unixodbc.org
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev


Gmane