[egenix-users] problem with mx.ODBC MS SQL-server and datetime

M.-A. Lemburg mal at lemburg.com
Thu Feb 7 17:34:44 CET 2002


Max M wrote:
> 
> I am trying out mx.ODBC on MS sql server, and so far it goes along nicely.
> 
> But I am having trouble with inserting dates ie. from mx.DateTime
> The error message is:
> ('01004', 0, '[Microsoft][ODBC SQL Server Driver]Fractional truncation',
> 4479)
> 
> The only thing i could find on the net was (one line only):
> 
> http://groups.google.com/groups?hl=da&frame=right&th=841f8af29973b8ba&seekm=mailman.989913322.21800.python-list%40python.org#link2
> 
> Where somebody has the same problem:
> 
> "Marc-Andre answer:
> Looks like MS SQL Server's ODBC driver is being too careful again.
> What you are seeing there is a SQL warning which mxODBC translates
> into an exception."
> 
> the advice is "recompiling the package with -DDONT_REPORT_WARNINGS"
> 
> I would find it a lot easier to just catch the exception. But I cannot
> see from the traceback which exception to catch. 

You'll have to catch the mx.ODBC.Windows.Warning exception and
then look at the first item of the reason tuple to tell which
warning was issued.

Then to fix the problem, I'd suggest to convert the DateTime
object to a datetime string value with only two digit fractions. 
str(datetime) does this for you.

> So I have made a quick
> hack:
> 
>         try: # it bitches about dates
>             c.execute(qs, localValues)
>         except:
>             pass
> 
> That's about as dirty as it gets. So I wondered what the better way to
> do it is? As far as i can tell it just raises a general exception. Not
> one that I can catch explicitly.
> 
> Do I really have to re-compile? And if so what is needed?

You'll need MS VC++ installed, the Python installation and the
mxODBC sources. Then 

python setup.py build build_ext -DDONT_REPORT_WARNINGS install

will do the trick and install the new versions on top of what you
probably already have installed.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Software:                   http://www.egenix.com/files/python/



More information about the egenix-users mailing list