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

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/dialects/mysql/cymysql.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
# mysql/cymysql.py
 
2
# Copyright (C) 2005-2013 the SQLAlchemy authors and contributors <see AUTHORS file>
 
3
#
 
4
# This module is part of SQLAlchemy and is released under
 
5
# the MIT License: http://www.opensource.org/licenses/mit-license.php
 
6
 
 
7
"""
 
8
 
 
9
.. dialect:: mysql+cymysql
 
10
    :name: CyMySQL
 
11
    :dbapi: cymysql
 
12
    :connectstring: mysql+cymysql://<username>:<password>@<host>/<dbname>[?<options>]
 
13
    :url: https://github.com/nakagami/CyMySQL
 
14
 
 
15
"""
 
16
 
 
17
from .mysqldb import MySQLDialect_mysqldb
 
18
from .base import (BIT, MySQLDialect)
 
19
from ... import util
 
20
 
 
21
class _cymysqlBIT(BIT):
 
22
    def result_processor(self, dialect, coltype):
 
23
        """Convert a MySQL's 64 bit, variable length binary string to a long.
 
24
        """
 
25
 
 
26
        def process(value):
 
27
            if value is not None:
 
28
                # Py2K
 
29
                v = 0L
 
30
                for i in map(ord, value):
 
31
                    v = v << 8 | i
 
32
                # end Py2K
 
33
                # Py3K
 
34
                #v = 0
 
35
                #for i in value:
 
36
                #    v = v << 8 | i
 
37
                return v
 
38
            return value
 
39
        return process
 
40
 
 
41
 
 
42
class MySQLDialect_cymysql(MySQLDialect_mysqldb):
 
43
    driver = 'cymysql'
 
44
 
 
45
    description_encoding = None
 
46
    supports_sane_rowcount = False
 
47
 
 
48
    colspecs = util.update_copy(
 
49
        MySQLDialect.colspecs,
 
50
        {
 
51
            BIT: _cymysqlBIT,
 
52
        }
 
53
    )
 
54
 
 
55
    @classmethod
 
56
    def dbapi(cls):
 
57
        return __import__('cymysql')
 
58
 
 
59
    def _extract_error_code(self, exception):
 
60
        return exception.errno
 
61
 
 
62
    def is_disconnect(self, e, connection, cursor):
 
63
        if isinstance(e, self.dbapi.OperationalError):
 
64
            return self._extract_error_code(e) in \
 
65
                        (2006, 2013, 2014, 2045, 2055)
 
66
        elif isinstance(e, self.dbapi.InterfaceError):
 
67
            # if underlying connection is closed,
 
68
            # this is the error you get
 
69
            return True
 
70
        else:
 
71
            return False
 
72
 
 
73
dialect = MySQLDialect_cymysql