sqlalchemy / lib / sqlalchemy / dialects / mysql /

# mysql/
# Copyright (C) 2005-2012 the SQLAlchemy authors and contributors <see AUTHORS file>
# This module is part of SQLAlchemy and is released under
# the MIT License:
.. dialect:: mysql+gaerdbms
    :name: Google Cloud SQL
    :dbapi: rdbms
    :connectstring: mysql+gaerdbms:///<dbname>?instance=instancename

    This dialect is based primarily on the :mod:`.mysql.mysqldb` dialect with minimal

    .. versionadded:: 0.7.8


Google App Engine connections appear to be randomly recycled,
so the dialect does not pool connections.  The :class:`.NullPool`
implementation is installed within the :class:`.Engine` by


from .mysqldb import MySQLDialect_mysqldb
from ...pool import NullPool
import re

class MySQLDialect_gaerdbms(MySQLDialect_mysqldb):

    def dbapi(cls):
        from google.appengine.api import rdbms
        return rdbms

    def get_pool_class(cls, url):
        # Cloud SQL connections die at any moment
        return NullPool

    def create_connect_args(self, url):
        return [[], {'database': url.database}]

    def _extract_error_code(self, exception):
        match = re.compile(r"^(\d+):").match(str(exception))
        code =
        if code:
            return int(code)

dialect = MySQLDialect_gaerdbms