[freetds] SQLPrepare() can't arrange error infomation when DBshutdown occured after SQLConnect()

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Wed Jun 7 08:45:57 EDT 2006


> 
> Hello~
> I'm tring to build a system with
> 
> - sqlrelay ver. 0.37
> - unixODBC ver. 2.2.11
> - FreeTDS  ver. 0.63
> 
> I had been sufferd from some problem.
> It was that SQLError() couldn't  get correct error message after
> SQLPrepare() failed
> and the error message returned by SQLError() was not valid 
> null-terminated
> string.
> 
> Finding a thread about same situation (
> http://lists.ibiblio.org/pipermail/freetds/2005q3/018897.html) ,
> the problem was mostly fixed by applying attached patch file .
> 
> Unfortunately It seems not to be perfectly fixed.
> If SQLConnect() had succeeded and client lost the connection 
> to the SQL
> server (shutdown maybe) after that
> then following SQLPrepare() failed but it could  not arrange 
> detailed error
> informations  which will be retrieved by SQLError().
> 
> sqlrelay call SQLConnect() once and use SQLPrepare()  repeatedly.
> It also retry to connect to the DBMS when connection is lost.
> so detecting lost connection  is important to sqlrelay .
> 
> In constrat to SQLPrepare() , SQLExecDirect() might be able 
> to catch error
> correctly.
> 
> For convenience , I reproduced it using PHP.
> 
> In PHP , odbc_do() call SQLExecDirect() and odbc_prepare() 
> use SQLPrepare().
> 
> do.php use odbc_do() and  prepare.php use odbc_prepare().
> 
> both scripts do sleep() after odbc_connect() and DBMS is 
> shutted down before
> they are awakened
> 
> $php prepare.php
> ----------------
> state = 00000
> msg = A@暉@H?월?
> /tmp/php-5.0.5/ext/odbc/php_odbc.c(849) :  Freeing 0x0834F984 
> (36 bytes),
> script=prepare.php
> === Total 1 memory leaks detected ===
> 

Memory leak :( I hope not a FreeTDS one :)

> 
> $ php do.php
> ----------------
> state = 08S01
> msg = [unixODBC][FreeTDS][SQL Server]Write to SQL Server failed.
> 
> 
> ---contents of prepare.php---
> $conn = odbc_connect('FreeTDS','sqlr','sqlr');
> $query = 'select 1;';
> sleep (10) ;
> # shutdown database
> $s = @odbc_prepare($conn,$query); # odbc_do in do.php
> echo "----------------\n";
> if($e=odbc_error())
> {
>         echo "state = $e\n";
>         echo "msg = ".odbc_errormsg($conn)."\n";
> }
> ----------------------------------------
> 
> I could find the patch file mentioned above in the mailing 
> list archive .
>  It might be more convenient  if patch files reside with 
> source tarballs at
> FTP site.
> 

Currently you can find patch at http://freetds.sourceforge.net/ (post 0.63 patch)
In this case there is a sligth difference between what patch fix and what you want. The patch catch error that server returns preparing statement while the broken connection error is not sended by server but detected by library. I don't know if 0.63 or 0.64 can handle this situation... I'll try to reproduce the problem...

freddy77



More information about the FreeTDS mailing list