mirror of
https://github.com/hanzoai/pymssql.git
synced 2026-10-30 14:54:29 +00:00
This is a combination of 23 commits: More reST markup. Add project history document (ported from Google Code wiki). Reformat for readability. Typos. Small reST tweaks. Port another couple of docs. Add build dir to Git ignore list. Correct pymssql class names. Implement new RTD HTML theme. Link module references from main page body. Add statement about Python 3 and Unicode. Stolen from psycopg2 docs :) Further content re-shuffle and refactor. Add 'quickly-contribute-to-pymssql-docs-via-GitHub-PR' link to each page. Include content from up-to-date reST files at project root. Refactor. Add note + link to 1.x documentation wiki. Add Marc to 2.0 credits. Update year in © Expand pymssql reference. Also, tweak it and _mssql's Main page tweak. Add docs To-do items. Use sphinx.ext.todo for this. Add code-block directive so _mssql exception handling example gets syntax highlighting Prepare for publishing at the Web site. Use 'seealso' reST directive. Update packaging files for docs.
57 lines
2.2 KiB
ReStructuredText
57 lines
2.2 KiB
ReStructuredText
=================
|
|
FreeTDS and dates
|
|
=================
|
|
|
|
Explanation of how pymssql and FreeTDS can break dates.
|
|
|
|
Summary
|
|
=======
|
|
|
|
Make sure that FreeTDS is compiled with ``--enable-msdblib`` ``configure``
|
|
option, or your queries will return wrong dates -- ``"2010-00-01"`` instead of
|
|
``"2010-01-01"``.
|
|
|
|
Details
|
|
=======
|
|
|
|
There's an obscure problem on Linux/\*nix that results in dates shifted back by
|
|
1 month. This behaviour is caused by different ``dbdatecrack()`` prototypes in
|
|
*Sybase Open Client DB-Library/C* and the *Microsoft SQL DB Library for C*. The
|
|
first one returns month as 0..11 whereas the second gives month as 1..12. See
|
|
this `FreeTDS mailing list post`_, `Microsoft manual for dbdatecrack()`_,
|
|
and `Sybase manual for dbdatecrack()`_ for details.
|
|
|
|
FreeTDS, which is used on Linux/\*nix to connect to *Sybase* and *MS SQL*
|
|
servers, tries to imitate both modes:
|
|
|
|
* Default behaviour, when compiled without ``--enable-msdblib``, gives
|
|
``dbdatecrack()`` which is Sybase-compatible,
|
|
* When configured with ``--enable-msdblib``, the ``dbdatecrack()`` function is
|
|
compatible with *MS SQL* specs.
|
|
|
|
pymssql requires *MS SQL* mode, evidently. Unfortunately at runtime we can't
|
|
reliably detect which mode FreeTDS was compiled in (as of FreeTDS 0.63). Thus at
|
|
runtime it may turn out that dates are not correct. If there was a way to detect
|
|
the setting, pymssql would be able to correct dates on the fly.
|
|
|
|
If you can do nothing about FreeTDS, there's a workaround. You can redesign your
|
|
queries to return string instead of bare date:
|
|
|
|
.. code-block:: sql
|
|
|
|
SELECT datecolumn FROM tablename
|
|
|
|
can be rewritten into:
|
|
|
|
.. code-block:: sql
|
|
|
|
SELECT CONVERT(CHAR(10),datecolumn,120) AS datecolumn FROM tablename
|
|
|
|
This way SQL will send you string representing the date instead of binary date
|
|
in datetime or smalldatetime format, which has to be processed by FreeTDS and
|
|
pymssql.
|
|
|
|
.. _FreeTDS mailing list post: http://lists.ibiblio.org/pipermail/freetds/2002q3/008336.html
|
|
.. _Microsoft manual for dbdatecrack(): http://msdn.microsoft.com/en-us/library/aa937027(SQL.80).aspx
|
|
.. _Sybase manual for dbdatecrack(): http://manuals.sybase.com/onlinebooks/group-cnarc/cng1110e/dblib/@Generic__BookTextView/15108
|