Re: unixODBC-dev Digest, Vol 104, Issue 6

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: unixODBC-dev Digest, Vol 104, Issue 6

Satheesh Subramanian
Hey Nick, 
 Thanks a lot for looking into it.

 We are using the unicode driver. do_attr method of the version which I was using(2.3.1) was not setting the connect attribute to the unicode driver

static void do_attr( DMHDBC connection, int value,
        int value_set, int attr3, int attr2  )
{
    if ( value_set )
    {
        if (CHECK_SQLSETCONNECTATTR( connection ))
        {
            SQLSETCONNECTATTR(connection,
                        connection -> driver_dbc,
                        attr3,
                        value,
                        sizeof( value ));
        }
        else if (CHECK_SQLSETCONNECTOPTION(connection) && attr2 )
        {
            SQLSETCONNECTOPTION(connection,
                        connection -> driver_dbc,
                        attr2,
                        value );
        }
    }
}

But when I looked at the latest version of the code (2.3.4), it is indeed setting the value to the unicode driver

static void do_attr( DMHDBC connection, int value,
        int value_set, int attr3, int attr2  )
{
    if ( value_set )
    {
        if (CHECK_SQLSETCONNECTATTR( connection ))
        {
            SQLSETCONNECTATTR(connection,
                        connection -> driver_dbc,
                        attr3,
                        value,
                        sizeof( value ));
        }
        else if (CHECK_SQLSETCONNECTOPTION(connection) && attr2 )
        {
            SQLSETCONNECTOPTION(connection,
                        connection -> driver_dbc,
                        attr2,
                        value );
        }
        else if (CHECK_SQLSETCONNECTATTRW( connection ))     /* they are int values, so this should be safe */
        {
            SQLSETCONNECTATTRW(connection,
                        connection -> driver_dbc,
                        attr3,
                        value,
                        sizeof( value ));
        }
        else if (CHECK_SQLSETCONNECTOPTIONW(connection) && attr2 )
        {
            SQLSETCONNECTOPTIONW(connection,
                        connection -> driver_dbc,
                        attr2,
                        value );
        }
    }
}

I have built the new version of the driver and it worked. 

Thanks a lot for  your help

On Tue, Mar 22, 2016 at 5:00 AM, <[hidden email]> wrote:
Send unixODBC-dev mailing list submissions to
        [hidden email]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev
or, via email, send a message with subject or body 'help' to
        [hidden email]

You can reach the person managing the list at
        [hidden email]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of unixODBC-dev digest..."


Today's Topics:

   1. SQL_ATTR_LOGIN_TIMEOUT behaviour (Satheesh Subramanian)
   2. Re: SQL_ATTR_LOGIN_TIMEOUT behaviour (Satheesh Subramanian)
   3. Re: SQL_ATTR_LOGIN_TIMEOUT behaviour (Nick Gorham)


----------------------------------------------------------------------

Message: 1
Date: Tue, 22 Mar 2016 00:34:09 -0700
From: Satheesh Subramanian <[hidden email]>
Subject: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour
To: [hidden email]
Message-ID:
        <[hidden email]>
Content-Type: text/plain; charset="utf-8"

Hi,
 We ran into a problem where connection to mysql database is not timing out
within specified SQL_ATTR_LOGIN_TIMEOUT value even when the database is not
reachable.

 We use UNixODBC driver manager and mysql odbc driver to connect to the
mysql database. In order to make a connection to the database we do the
following
1) Allocate Handle
2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr
3) Call SQLDriverConnect to make the connection.

To debug the issue, I first enabled the trace logs and then started to look
at the source code of unix odbc driver manager.

By looking at the SQLDriverConnectW.c code, looks like the
attribute SQL_ATTR_LOGIN_TIMEOUT is only saved to an internal variable as
long as the connection state is C2.

And SQLDriverConnectW.c is trying to load the driver as part pf
"part_one_connection" and then trying to make SQLDriverConnectW call to the
mysql odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOUT is being ignored
and will never be passed on to mysql driver unless the connection state is
something other than C2. Looking at the code connection state would be
moved out of S2 state only after a successful connect request to the driver

I believe this is the reason why login timeout is not getting honoured.

So, to confirm that, I made a change in SQLDriverConnectW to call the mysql
driver to set the login timeout(which was saved to internal variable in  an
earlier call) after loading the driver but before making the actual
connection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT started
to work.

I am not convinced driver manager would ignore the timeout and I suspect I
am doing something wrong. I could not find the reason after going through
the code multiple times over last few days.

Can someone please point me to the right direction? How does the driver
manager set the connection timeout to mysql driver? Any help is much
appreciated!.

Thanks in advance
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20160322/0b6b7e28/attachment-0001.html>

------------------------------

Message: 2
Date: Tue, 22 Mar 2016 01:12:21 -0700
From: Satheesh Subramanian <[hidden email]>
Subject: Re: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour
To: [hidden email]
Message-ID:
        <[hidden email]>
Content-Type: text/plain; charset="utf-8"

Please note we are using
unixODBC version : 2.3.1
mysql odbc driver version : 5.3.4

On Tue, Mar 22, 2016 at 12:34 AM, Satheesh Subramanian <
[hidden email]> wrote:

> Hi,
>  We ran into a problem where connection to mysql database is not timing
> out within specified SQL_ATTR_LOGIN_TIMEOUT value even when the database is
> not reachable.
>
>  We use UNixODBC driver manager and mysql odbc driver to connect to the
> mysql database. In order to make a connection to the database we do the
> following
> 1) Allocate Handle
> 2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr
> 3) Call SQLDriverConnect to make the connection.
>
> To debug the issue, I first enabled the trace logs and then started to
> look at the source code of unix odbc driver manager.
>
> By looking at the SQLDriverConnectW.c code, looks like the
> attribute SQL_ATTR_LOGIN_TIMEOUT is only saved to an internal variable as
> long as the connection state is C2.
>
> And SQLDriverConnectW.c is trying to load the driver as part pf
> "part_one_connection" and then trying to make SQLDriverConnectW call to the
> mysql odbc driver. So, looks like SQL_ATTR_LOGIN_TIMEOUT is being ignored
> and will never be passed on to mysql driver unless the connection state is
> something other than C2. Looking at the code connection state would be
> moved out of S2 state only after a successful connect request to the driver
>
> I believe this is the reason why login timeout is not getting honoured.
>
> So, to confirm that, I made a change in SQLDriverConnectW to call the
> mysql driver to set the login timeout(which was saved to internal variable
> in  an earlier call) after loading the driver but before making the actual
> connection. Afer this change, value set for SQL_ATTR_LOGIN_TIMEOUT started
> to work.
>
> I am not convinced driver manager would ignore the timeout and I suspect I
> am doing something wrong. I could not find the reason after going through
> the code multiple times over last few days.
>
> Can someone please point me to the right direction? How does the driver
> manager set the connection timeout to mysql driver? Any help is much
> appreciated!.
>
> Thanks in advance
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20160322/94ebbdad/attachment-0001.html>

------------------------------

Message: 3
Date: Tue, 22 Mar 2016 10:01:24 +0000
From: Nick Gorham <[hidden email]>
Subject: Re: [unixODBC-dev] SQL_ATTR_LOGIN_TIMEOUT behaviour
To: [hidden email]
Message-ID: <[hidden email]>
Content-Type: text/plain; charset="windows-1252"; Format="flowed"

On 22/03/16 07:34, Satheesh Subramanian wrote:
> Hi,
>  We ran into a problem where connection to mysql database is not
> timing out within specified SQL_ATTR_LOGIN_TIMEOUT value even when the
> database is not reachable.
>
>  We use UNixODBC driver manager and mysql odbc driver to connect to
> the mysql database. In order to make a connection to the database we
> do the following
> 1) Allocate Handle
> 2) Set SQL_ATTR_LOGIN_TIMEOUT to 5 seconds by calling SQLSetConnectAttr
> 3) Call SQLDriverConnect to make the connection.
>
> To debug the issue, I first enabled the trace logs and then started to
> look at the source code of unix odbc driver manager.

Well, checking here with the current build (and I dont see any changes
that would affect this) __connect_part_one() contains

     /*
      * set any connection atributes
      */

     DO_ATTR( connection, access_mode, SQL_ATTR_ACCESS_MODE,
SQL_ACCESS_MODE );
*    DO_ATTR( connection, login_timeout, SQL_ATTR_LOGIN_TIMEOUT,
SQL_LOGIN_TIMEOUT );*
     DO_ATTR( connection, auto_commit, SQL_ATTR_AUTOCOMMIT,
SQL_AUTOCOMMIT );
     DO_ATTR( connection, async_enable, SQL_ATTR_ASYNC_ENABLE,
SQL_ASYNC_ENABLE );
     DO_ATTR( connection, auto_ipd, SQL_ATTR_AUTO_IPD, 0 );
     DO_ATTR( connection, connection_timeout,
SQL_ATTR_CONNECTION_TIMEOUT, 0 );
     DO_ATTR( connection, metadata_id, SQL_ATTR_METADATA_ID, 0 );
     DO_ATTR( connection, packet_size, SQL_ATTR_PACKET_SIZE,
SQL_PACKET_SIZE );
     DO_ATTR( connection, quite_mode, SQL_ATTR_QUIET_MODE, SQL_QUIET_MODE );
     DO_ATTR( connection, txn_isolation, SQL_ATTR_TXN_ISOLATION,
SQL_TXN_ISOLATION );

And SQLSetConnectAttr.c contains

     /*
      * we need to save this even if connected so we can use it for the
next connect
      */
     if ( attribute == SQL_ATTR_LOGIN_TIMEOUT )
     {
         connection -> login_timeout = ( SQLLEN ) value;
         connection -> login_timeout_set = 1;
     }

And the comment when this was changed

  * Revision 1.4  2002/01/10 11:17:20  lurcher
  *
  * Allow SQL_ATTR_LOGIN_TIMEOUT to be set when connected to mirror what the
  * MS DM does


2002 is release 2.2.0, so thats been there for some time.

I just tried with one of our (Easysoft) drivers to check, and it seems
to work as I would expect, calling SQLSetConnect in the driver between
the SQLAllocEnv( SQL_CONNECT ) and the SQLConnect/SQLDriverConnect

--
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.unixodbc.org/pipermail/unixodbc-dev/attachments/20160322/7fd504f7/attachment-0001.html>

------------------------------

_______________________________________________
unixODBC-dev mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev


End of unixODBC-dev Digest, Vol 104, Issue 6
********************************************


_______________________________________________
unixODBC-dev mailing list
[hidden email]
http://mailman.unixodbc.org/mailman/listinfo/unixodbc-dev