~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/dialects/mssql/pyodbc.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Jakub Wilk, Piotr Ożarowski
  • Date: 2013-07-06 20:53:52 UTC
  • mfrom: (1.4.23) (16.1.17 experimental)
  • Revision ID: package-import@ubuntu.com-20130706205352-ryppl1eto3illd79
Tags: 0.8.2-1
[ Jakub Wilk ]
* Use canonical URIs for Vcs-* fields.

[ Piotr Ożarowski ]
* New upstream release
* Upload to unstable
* Build depend on python3-all instead of -dev, extensions are not built for
  Python 3.X 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# mssql/pyodbc.py
2
 
# Copyright (C) 2005-2012 the SQLAlchemy authors and contributors <see AUTHORS file>
 
2
# Copyright (C) 2005-2013 the SQLAlchemy authors and contributors <see AUTHORS file>
3
3
#
4
4
# This module is part of SQLAlchemy and is released under
5
5
# the MIT License: http://www.opensource.org/licenses/mit-license.php
6
6
 
7
7
"""
8
 
Support for MS-SQL via pyodbc.
9
 
 
10
 
pyodbc is available at:
11
 
 
12
 
    http://pypi.python.org/pypi/pyodbc/
13
 
 
14
 
Connecting
15
 
^^^^^^^^^^
 
8
.. dialect:: mssql+pyodbc
 
9
    :name: PyODBC
 
10
    :dbapi: pyodbc
 
11
    :connectstring: mssql+pyodbc://<username>:<password>@<dsnname>
 
12
    :url: http://pypi.python.org/pypi/pyodbc/
 
13
 
 
14
Additional Connection Examples
 
15
-------------------------------
16
16
 
17
17
Examples of pyodbc connection string URLs:
18
18
 
81
81
    'dsn%3Dmydsn%3BDatabase%3Ddb'
82
82
 
83
83
Unicode Binds
84
 
^^^^^^^^^^^^^
 
84
-------------
85
85
 
86
86
The current state of PyODBC on a unix backend with FreeTDS and/or
87
87
EasySoft is poor regarding unicode; different OS platforms and versions of UnixODBC
111
111
 
112
112
"""
113
113
 
114
 
from sqlalchemy.dialects.mssql.base import MSExecutionContext, MSDialect
115
 
from sqlalchemy.connectors.pyodbc import PyODBCConnector
116
 
from sqlalchemy import types as sqltypes, util
 
114
from .base import MSExecutionContext, MSDialect
 
115
from ...connectors.pyodbc import PyODBCConnector
 
116
from ... import types as sqltypes, util
117
117
import decimal
118
118
 
 
119
 
119
120
class _MSNumeric_pyodbc(sqltypes.Numeric):
120
121
    """Turns Decimals with adjusted() < 0 or > 7 into strings.
121
122
 
122
 
    This is the only method that is proven to work with Pyodbc+MSSQL
123
 
    without crashing (floats can be used but seem to cause sporadic
124
 
    crashes).
 
123
    The routines here are needed for older pyodbc versions
 
124
    as well as current mxODBC versions.
125
125
 
126
126
    """
127
127
 
164
164
            result = "%s%s%s" % (
165
165
                    (value < 0 and '-' or ''),
166
166
                    "".join([str(s) for s in _int]),
167
 
                    "0" * (value.adjusted() - (len(_int)-1)))
 
167
                    "0" * (value.adjusted() - (len(_int) - 1)))
168
168
        else:
169
169
            if (len(_int) - 1) > value.adjusted():
170
170
                result = "%s%s.%s" % (
238
238
    colspecs = util.update_copy(
239
239
        MSDialect.colspecs,
240
240
        {
241
 
            sqltypes.Numeric:_MSNumeric_pyodbc
 
241
            sqltypes.Numeric: _MSNumeric_pyodbc
242
242
        }
243
243
    )
244
244
 
245
 
    def __init__(self, description_encoding='latin-1', **params):
 
245
    def __init__(self, description_encoding=None, **params):
246
246
        super(MSDialect_pyodbc, self).__init__(**params)
247
247
        self.description_encoding = description_encoding
248
248
        self.use_scope_identity = self.use_scope_identity and \