示例#1
0
 def __init__(self, path, log, user=None, password=None, host=None, port=None, params={}):
     if path.startswith("/"):
         path = path[1:]
     if password == None:
         password = ""
     if port == None:
         port = 3306
     opts = {}
     for name, value in params.iteritems():
         if name in ("init_command", "read_default_file", "read_default_group", "unix_socket"):
             opts[name] = value
         elif name in ("compress", "named_pipe"):
             opts[name] = as_int(value, 0)
         else:
             self.log.warning("Invalid connection string parameter '%s'", name)
     cnx = MySQLdb.connect(db=path, user=user, passwd=password, host=host, port=port, charset="utf8", **opts)
     if hasattr(cnx, "encoders"):
         # 'encoders' undocumented but present since 1.2.1 (r422)
         cnx.encoders[Markup] = cnx.encoders[types.UnicodeType]
     cursor = cnx.cursor()
     cursor.execute("SHOW VARIABLES WHERE " " variable_name='character_set_database'")
     self.charset = cursor.fetchone()[1]
     if self.charset != "utf8":
         cnx.query("SET NAMES %s" % self.charset)
         cnx.store_result()
     ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
示例#2
0
    def __init__(self, path, log=None, params={}):
        assert have_pysqlite > 0
        self.cnx = None
        if path != ':memory:':
            if not os.access(path, os.F_OK):
                raise TracError(_('Database "%(path)s" not found.', path=path))

            dbdir = os.path.dirname(path)
            if not os.access(path, os.R_OK + os.W_OK) or \
                   not os.access(dbdir, os.R_OK + os.W_OK):
                raise TracError(
                    _('The user %(user)s requires read _and_ write '
                      'permissions to the database file %(path)s '
                      'and the directory it is located in.',
                      user=getuser(), path=path))

        self._active_cursors = weakref.WeakKeyDictionary()
        timeout = int(params.get('timeout', 10.0))
        self._eager = params.get('cursor', 'eager') == 'eager'
        # eager is default, can be turned off by specifying ?cursor=
        if isinstance(path, unicode): # needed with 2.4.0
            path = path.encode('utf-8')
        cnx = sqlite.connect(path, detect_types=sqlite.PARSE_DECLTYPES,
                             check_same_thread=sqlite_version < (3, 3, 1),
                             timeout=timeout)
        # load extensions
        extensions = params.get('extensions', [])
        if len(extensions) > 0:
            cnx.enable_load_extension(True)
            for ext in extensions:
                cnx.load_extension(ext)
            cnx.enable_load_extension(False)

        ConnectionWrapper.__init__(self, cnx, log)
 def __init__(self, path, log, user=None, password=None, host=None,
              port=None, params={}):
     if path.startswith('/'):
         path = path[1:]
     if password == None:
         password = ''
     if port == None:
         port = 3306
     opts = {}
     for name, value in params.iteritems():
         if name in ('init_command', 'read_default_file',
                     'read_default_group', 'unix_socket'):
             opts[name] = value
         elif name in ('compress', 'named_pipe'):
             opts[name] = as_int(value, 0)
         else:
             self.log.warning("Invalid connection string parameter '%s'",
                              name)
     cnx = MySQLdb.connect(db=path, user=user, passwd=password, host=host,
                           port=port, charset='utf8', **opts)
     if hasattr(cnx, 'encoders'):
         # 'encoders' undocumented but present since 1.2.1 (r422)
         cnx.encoders[Markup] = cnx.encoders[types.UnicodeType]
     ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
示例#4
0
    def __init__(self, path, log=None, params={}):
        assert have_pysqlite > 0
        self.cnx = None
        if path != ':memory:':
            if not os.access(path, os.F_OK):
                raise TracError(_('Database "%(path)s" not found.', path=path))

            dbdir = os.path.dirname(path)
            if not os.access(path, os.R_OK + os.W_OK) or \
                   not os.access(dbdir, os.R_OK + os.W_OK):
                raise TracError(
                    _('The user %(user)s requires read _and_ write '
                      'permissions to the database file %(path)s '
                      'and the directory it is located in.',
                      user=getuser(), path=path))

        self._active_cursors = weakref.WeakKeyDictionary()
        timeout = int(params.get('timeout', 10.0))
        self._eager = params.get('cursor', 'eager') == 'eager'
        # eager is default, can be turned off by specifying ?cursor=
        if isinstance(path, unicode): # needed with 2.4.0
            path = path.encode('utf-8')
        cnx = sqlite.connect(path, detect_types=sqlite.PARSE_DECLTYPES,
                             check_same_thread=sqlite_version < (3, 3, 1),
                             timeout=timeout)
        # load extensions
        extensions = params.get('extensions', [])
        if len(extensions) > 0:
            cnx.enable_load_extension(True)
            for ext in extensions:
                cnx.load_extension(ext)
            cnx.enable_load_extension(False)
       
        ConnectionWrapper.__init__(self, cnx, log)
示例#5
0
    def __init__(self, path, params={}):
        assert have_pysqlite > 0
        self.cnx = None
        if path != ':memory:':
            if not os.access(path, os.F_OK):
                raise TracError, 'Database "%s" not found.' % path

            dbdir = os.path.dirname(path)
            if not os.access(path, os.R_OK + os.W_OK) or \
                   not os.access(dbdir, os.R_OK + os.W_OK):
                from getpass import getuser
                raise TracError('The user %s requires read _and_ write ' \
                                'permission to the database file %s and the ' \
                                'directory it is located in.' \
                                % (getuser(), path))

        if have_pysqlite == 2:
            self._active_cursors = weakref.WeakKeyDictionary()
            timeout = int(params.get('timeout', 10.0))
            cnx = sqlite.connect(path,
                                 detect_types=sqlite.PARSE_DECLTYPES,
                                 check_same_thread=sqlite_version < 30301,
                                 timeout=timeout)
        else:
            timeout = int(params.get('timeout', 10000))
            cnx = sqlite.connect(path, timeout=timeout, encoding='utf-8')

        ConnectionWrapper.__init__(self, cnx)
示例#6
0
    def __init__(self, path, params={}):
        assert have_pysqlite > 0
        self.cnx = None
        if path != ':memory:':
            if not os.access(path, os.F_OK):
                raise TracError, u'Base de données "%s" non trouvée.' % path

            dbdir = os.path.dirname(path)
            if not os.access(path, os.R_OK + os.W_OK) or \
                   not os.access(dbdir, os.R_OK + os.W_OK):
                from getpass import getuser
                raise TracError, u"L'utilisateur %s a besoin des permissions " \
                                 u"en lecture _et_ en écriture sur la base de " \
                                 u"données %s ainsi que sur le répertoire " \
                                 u"dans lequel elle est située." \
                                 % (getuser(), path)

        if have_pysqlite == 2:
            self._active_cursors = weakref.WeakKeyDictionary()
            timeout = int(params.get('timeout', 10.0))
            cnx = sqlite.connect(path, detect_types=sqlite.PARSE_DECLTYPES,
                                 check_same_thread=sqlite_version < 30301,
                                 timeout=timeout)
        else:
            timeout = int(params.get('timeout', 10000))
            cnx = sqlite.connect(path, timeout=timeout, encoding='utf-8')
            
        ConnectionWrapper.__init__(self, cnx)
示例#7
0
    def __init__(self, path, params={}):
        assert have_pysqlite > 0
        self.cnx = None
        if path != ':memory:':
            if not os.access(path, os.F_OK):
                raise TracError, u'Base de données "%s" non trouvée.' % path

            dbdir = os.path.dirname(path)
            if not os.access(path, os.R_OK + os.W_OK) or \
                   not os.access(dbdir, os.R_OK + os.W_OK):
                from getpass import getuser
                raise TracError, u"L'utilisateur %s a besoin des permissions " \
                                 u"en lecture _et_ en écriture sur la base de " \
                                 u"données %s ainsi que sur le répertoire " \
                                 u"dans lequel elle est située." \
                                 % (getuser(), path)

        if have_pysqlite == 2:
            self._active_cursors = weakref.WeakKeyDictionary()
            timeout = int(params.get('timeout', 10.0))
            cnx = sqlite.connect(path,
                                 detect_types=sqlite.PARSE_DECLTYPES,
                                 check_same_thread=sqlite_version < 30301,
                                 timeout=timeout)
        else:
            timeout = int(params.get('timeout', 10000))
            cnx = sqlite.connect(path, timeout=timeout, encoding='utf-8')

        ConnectionWrapper.__init__(self, cnx)
示例#8
0
 def __init__(self, path, log, user=None, password=None, host=None,
              port=None, params={}):
     if path.startswith('/'):
         path = path[1:]
     if password == None:
         password = ''
     if port == None:
         port = 3306
     opts = {}
     for name, value in params.iteritems():
         if name in ('init_command', 'read_default_file',
                     'read_default_group', 'unix_socket'):
             opts[name] = value
         elif name in ('compress', 'named_pipe'):
             opts[name] = as_int(value, 0)
         else:
             self.log.warning("Invalid connection string parameter '%s'",
                              name)
     cnx = MySQLdb.connect(db=path, user=user, passwd=password, host=host,
                           port=port, charset='utf8', **opts)
     if hasattr(cnx, 'encoders'):
         # 'encoders' undocumented but present since 1.2.1 (r422)
         cnx.encoders[Markup] = cnx.encoders[types.UnicodeType]
     cursor = cnx.cursor()
     cursor.execute("SHOW VARIABLES WHERE "
                    " variable_name='character_set_database'")
     self.charset = cursor.fetchone()[1]
     if self.charset != 'utf8':
         cnx.query("SET NAMES %s" % self.charset)
         cnx.store_result()
     ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
    def __init__(self,
                 path,
                 log=None,
                 user=None,
                 password=None,
                 host=None,
                 port=None,
                 params={}):
        if path.startswith('/'):
            path = path[1:]
        if 'host' in params:
            host = params['host']

        cnx = psycopg.connect(assemble_pg_dsn(path, user, password, host,
                                              port))

        cnx.set_client_encoding('UNICODE')
        self.schema = None
        if 'schema' in params:
            self.schema = params['schema']
            try:
                cnx.cursor().execute('SET search_path TO %s', (self.schema, ))
                cnx.commit()
            except (DataError, ProgrammingError):
                cnx.rollback()
        ConnectionWrapper.__init__(self, cnx, log)
示例#10
0
    def __init__(self,
                 path,
                 user=None,
                 password=None,
                 host=None,
                 port=None,
                 params={}):
        if path.startswith('/'):
            path = path[1:]
        # We support both psycopg and PgSQL but prefer psycopg
        global psycopg
        global PgSQL
        global PGSchemaError

        if not psycopg and not PgSQL:
            try:
                import psycopg2 as psycopg
                import psycopg2.extensions
                from psycopg2 import ProgrammingError as PGSchemaError
                psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
            except ImportError:
                from pyPgSQL import PgSQL
                from pyPgSQL.libpq import OperationalError as PGSchemaError
        if 'host' in params:
            host = params['host']
        if psycopg:
            dsn = []
            if path:
                dsn.append('dbname=' + path)
            if user:
                dsn.append('user='******'password='******'host=' + host)
            if port:
                dsn.append('port=' + str(port))
            cnx = psycopg.connect(' '.join(dsn))
            cnx.set_client_encoding('UNICODE')
        else:
            # Don't use chatty, inefficient server-side cursors.
            # http://pypgsql.sourceforge.net/pypgsql-faq.html#id2787367
            PgSQL.fetchReturnsList = 1
            PgSQL.noPostgresCursor = 1
            cnx = PgSQL.connect('',
                                user,
                                password,
                                host,
                                path,
                                port,
                                client_encoding='utf-8',
                                unicode_results=True)
        try:
            self.schema = None
            if 'schema' in params:
                self.schema = params['schema']
                cnx.cursor().execute('SET search_path TO %s', (self.schema, ))
        except PGSchemaError:
            cnx.rollback()
        ConnectionWrapper.__init__(self, cnx)
示例#11
0
    def __init__(self, path, log=None, params={}):
        assert have_pysqlite > 0
        self.cnx = None
        if path != ':memory:':
            if not os.access(path, os.F_OK):
                raise TracError('Database "%s" not found.' % path)

            dbdir = os.path.dirname(path)
            if not os.access(path, os.R_OK + os.W_OK) or \
                   not os.access(dbdir, os.R_OK + os.W_OK):
                raise TracError('The user %s requires read _and_ write ' \
                                'permissions to the database file %s and the ' \
                                'directory it is located in.' \
                                % (getuser(), path))

        if have_pysqlite == 2:
            self._active_cursors = weakref.WeakKeyDictionary()
            timeout = int(params.get('timeout', 10.0))
            self._eager = params.get('cursor', 'eager') == 'eager'
            # eager is default, can be turned off by specifying ?cursor=
            if isinstance(path, unicode): # needed with 2.4.0
                path = path.encode('utf-8')
            cnx = sqlite.connect(path, detect_types=sqlite.PARSE_DECLTYPES,
                                 check_same_thread=sqlite_version < 30301,
                                 timeout=timeout)
        else:
            timeout = int(params.get('timeout', 10000))
            cnx = sqlite.connect(path, timeout=timeout, encoding='utf-8')
            
        ConnectionWrapper.__init__(self, cnx, log)
示例#12
0
 def __init__(self,
              path,
              log,
              user=None,
              password=None,
              host=None,
              port=None,
              params={}):
     if path.startswith('/'):
         path = path[1:]
     if password is None:
         password = ''
     if port is None:
         port = 3306
     opts = {'charset': 'utf8'}
     for name, value in params.items():
         if name == 'read_default_group':
             opts[name] = value
         elif name == 'init_command':
             opts[name] = value
         elif name in ('read_default_file', 'unix_socket'):
             opts[name] = value
         elif name in ('compress', 'named_pipe'):
             opts[name] = as_int(value, 0)
         elif name == 'charset':
             value = value.lower()
             if value in ('utf8', 'utf8mb4'):
                 opts[name] = value
             else:
                 self.log.warning(
                     "Invalid connection string parameter "
                     "'%s=%s'", name, value)
         else:
             self.log.warning("Invalid connection string parameter '%s'",
                              name)
     cnx = pymysql.connect(db=path,
                           user=user,
                           passwd=password,
                           host=host,
                           port=port,
                           **opts)
     cursor = cnx.cursor()
     cursor.execute("SHOW VARIABLES WHERE "
                    " variable_name='character_set_database'")
     self.charset = cursor.fetchone()[1]
     cursor.close()
     if self.charset != opts['charset']:
         cnx.close()
         opts['charset'] = self.charset
         cnx = pymysql.connect(db=path,
                               user=user,
                               passwd=password,
                               host=host,
                               port=port,
                               **opts)
     self.schema = path
     ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
示例#13
0
	def __init__(self, path, log, user=None, password=None, host=None, port=None, params={}):
		if path.startswith('/'):
			path = path[1:]
		if 'host' in params:
			host = params['host']

		cnx = pymssql.connect(database=path, user=user, password=password, host=host,
							  port=port)
		self.schema = path
		ConnectionWrapper.__init__(self, cnx, log)
		self._is_closed = False
示例#14
0
 def __init__(self, path, log, user=None, password=None, host=None,
              port=None, params={}):
     if path.startswith('/'):
         path = path[1:]
     if password == None:
         password = ''
     if port == None:
         port = 3306
     cnx = MySQLdb.connect(db=path, user=user, passwd=password,
                           host=host, port=port, charset='utf8')
     ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
 def __init__(self, path, user=None, password=None, host=None, port=None,
              params={}):
     if path.startswith('/'):
         path = path[1:]
     # We support both psycopg and PgSQL but prefer psycopg
     global psycopg
     global PgSQL
     global PGSchemaError
     
     if not psycopg and not PgSQL:
         try:
             import psycopg2 as psycopg
             import psycopg2.extensions
             from psycopg2 import ProgrammingError as PGSchemaError
             psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
         except ImportError:
             from pyPgSQL import PgSQL
             from pyPgSQL.libpq import OperationalError as PGSchemaError
     if 'host' in params:
         host = params['host']
     if psycopg:
         dsn = []
         if path:
             dsn.append('dbname=' + path)
         if user:
             dsn.append('user='******'password='******'host=' + host)
         if port:
             dsn.append('port=' + str(port))
         cnx = psycopg.connect(' '.join(dsn))
         cnx.set_client_encoding('UNICODE')
     else:
         # Don't use chatty, inefficient server-side cursors.
         # http://pypgsql.sourceforge.net/pypgsql-faq.html#id2787367
         PgSQL.fetchReturnsList = 1
         PgSQL.noPostgresCursor = 1
         cnx = PgSQL.connect('', user, password, host, path, port, 
                             client_encoding='utf-8', unicode_results=True)
     try:
         self.schema = None
         if 'schema' in params:
             self.schema = params['schema']
             cnx.cursor().execute('SET search_path TO %s', (self.schema,))
     except PGSchemaError:
         cnx.rollback()
     ConnectionWrapper.__init__(self, cnx)
示例#16
0
 def __init__(self, path, log, user=None, password=None, host=None,
              port=None, params={}):
     if path.startswith('/'):
         path = path[1:]
     if password == None:
         password = ''
     if port == None:
         port = 3306
     cnx = MySQLdb.connect(db=path, user=user, passwd=password,
                           host=host, port=port, charset='utf8')
     if hasattr(cnx, 'encoders'):
         # 'encoders' undocumented but present since 1.2.1 (r422)
         cnx.encoders[Markup] = cnx.encoders[types.UnicodeType]
     ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
示例#17
0
    def __init__(self, path, log=None, params={}):
        if have_pysqlite == 0:
            raise TracError(_("Cannot load Python bindings for SQLite"))
        self.cnx = None
        if path != ':memory:':
            if not os.access(path, os.F_OK):
                raise ConfigurationError(
                    _('Database "%(path)s" not found.', path=path))

            dbdir = os.path.dirname(path)
            if not os.access(path, os.R_OK + os.W_OK) or \
                   not os.access(dbdir, os.R_OK + os.W_OK):
                raise ConfigurationError(
                    tag_(
                        "The user %(user)s requires read _and_ write permissions "
                        "to the database file %(path)s and the directory it is "
                        "located in.",
                        user=tag.tt(getuser()),
                        path=tag.tt(path)))

        self._active_cursors = weakref.WeakKeyDictionary()
        timeout = int(params.get('timeout', 10.0))
        self._eager = params.get('cursor', 'eager') == 'eager'
        # eager is default, can be turned off by specifying ?cursor=
        if isinstance(path, unicode):  # needed with 2.4.0
            path = path.encode('utf-8')
        cnx = sqlite.connect(path,
                             detect_types=sqlite.PARSE_DECLTYPES,
                             isolation_level=None,
                             check_same_thread=sqlite_version < (3, 3, 1),
                             timeout=timeout)
        # load extensions
        extensions = params.get('extensions', [])
        if len(extensions) > 0:
            cnx.enable_load_extension(True)
            for ext in extensions:
                cnx.load_extension(ext)
            cnx.enable_load_extension(False)

        cursor = cnx.cursor()
        _set_journal_mode(cursor, params.get('journal_mode'))
        _set_synchronous(cursor, params.get('synchronous'))
        cursor.close()
        cnx.isolation_level = 'DEFERRED'
        ConnectionWrapper.__init__(self, cnx, log)
示例#18
0
 def __enter__(self):
     db = self.dbmgr._transaction_local.wdb  # outermost writable db
     if not db:
         db = self.dbmgr._transaction_local.rdb  # reuse wrapped connection
         if db:
             db = ConnectionWrapper(db.cnx, db.log)
         else:
             db = self.dbmgr.get_connection()
         self.dbmgr._transaction_local.wdb = self.db = db
     return db
示例#19
0
 def __enter__(self):
     db = self.dbmgr._transaction_local.rdb  # outermost readonly db
     if not db:
         db = self.dbmgr._transaction_local.wdb  # reuse wrapped connection
         if db:
             db = ConnectionWrapper(db.cnx, db.log, readonly=True)
         else:
             db = self.dbmgr.get_connection(readonly=True)
         self.dbmgr._transaction_local.rdb = self.db = db
     return db
示例#20
0
    def __init__(self, path, user=None, password=None, host=None, port=None, params={}):
        if path.startswith("/"):
            path = path[1:]
        # We support both psycopg and PgSQL but prefer psycopg
        global psycopg
        global PgSQL
        global PGSchemaError

        if not psycopg and not PgSQL:
            try:
                import psycopg2 as psycopg
                import psycopg2.extensions
                from psycopg2 import ProgrammingError as PGSchemaError

                psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
            except ImportError:
                from pyPgSQL import PgSQL
                from pyPgSQL.libpq import OperationalError as PGSchemaError
        if psycopg:
            dsn = []
            if path:
                dsn.append("dbname=" + path)
            if user:
                dsn.append("user="******"password="******"host=" + host)
            if port:
                dsn.append("port=" + str(port))
            cnx = psycopg.connect(" ".join(dsn))
            cnx.set_client_encoding("UNICODE")
        else:
            cnx = PgSQL.connect("", user, password, host, path, port, client_encoding="utf-8", unicode_results=True)
        try:
            self.schema = None
            if "schema" in params:
                self.schema = params["schema"]
                cnx.cursor().execute("SET search_path TO %s", (self.schema,))
        except PGSchemaError:
            cnx.rollback()
        ConnectionWrapper.__init__(self, cnx)
示例#21
0
    def __init__(self, path, log=None, user=None, password=None, host=None,
                 port=None, params={}):
        if path.startswith('/'):
            path = path[1:]
        if 'host' in params:
            host = params['host']

        cnx = psycopg.connect(assemble_pg_dsn(path, user, password, host,
                                              port))

        cnx.set_client_encoding('UNICODE')
        self.schema = None
        if 'schema' in params:
            self.schema = params['schema']
            try:
                cnx.cursor().execute('SET search_path TO %s', (self.schema,))
                cnx.commit()
            except (DataError, ProgrammingError):
                cnx.rollback()
        ConnectionWrapper.__init__(self, cnx, log)
示例#22
0
    def get_connection(self, readonly=False):
        """Get a database connection from the pool.

        If `readonly` is `True`, the returned connection will purposely
        lack the `rollback` and `commit` methods.
        """
        if not self._cnx_pool:
            connector, args = self.get_connector()
            self._cnx_pool = ConnectionPool(5, connector, **args)
        db = self._cnx_pool.get_cnx(self.timeout or None)
        if readonly:
            db = ConnectionWrapper(db, readonly=True)
        return db
示例#23
0
    def __init__(self, path, log=None, params={}):
        if have_pysqlite == 0:
            raise TracError(_("Cannot load Python bindings for SQLite"))
        self.cnx = None
        if path != ':memory:':
            if not os.access(path, os.F_OK):
                raise ConfigurationError(_('Database "%(path)s" not found.',
                                           path=path))

            dbdir = os.path.dirname(path)
            if not os.access(path, os.R_OK + os.W_OK) or \
                   not os.access(dbdir, os.R_OK + os.W_OK):
                raise ConfigurationError(tag_(
                    "The user %(user)s requires read _and_ write permissions "
                    "to the database file %(path)s and the directory it is "
                    "located in.", user=tag.tt(getuser()), path=tag.tt(path)))

        self._active_cursors = weakref.WeakKeyDictionary()
        timeout = int(params.get('timeout', 10.0))
        self._eager = params.get('cursor', 'eager') == 'eager'
        # eager is default, can be turned off by specifying ?cursor=
        if isinstance(path, unicode): # needed with 2.4.0
            path = path.encode('utf-8')
        cnx = sqlite.connect(path, detect_types=sqlite.PARSE_DECLTYPES,
                             check_same_thread=sqlite_version < (3, 3, 1),
                             timeout=timeout)
        # load extensions
        extensions = params.get('extensions', [])
        if len(extensions) > 0:
            cnx.enable_load_extension(True)
            for ext in extensions:
                cnx.load_extension(ext)
            cnx.enable_load_extension(False)

        cursor = cnx.cursor()
        _set_journal_mode(cursor, params.get('journal_mode'))
        _set_synchronous(cursor, params.get('synchronous'))
        ConnectionWrapper.__init__(self, cnx, log)
示例#24
0
    def __init__(self, path, user=None, password=None, host=None,
                 port=None, params={}):
        import MySQLdb

        if path.startswith('/'):
            path = path[1:]
        if password == None:
            password = ''
        if port == None:
            port = 3306

        # python-mysqldb 1.2.1 added a 'charset' arg that is required for
        # unicode stuff.  We hack around that here for older versions; at
        # some point, this hack should be removed, and a strict requirement
        # on 1.2.1 made.  -dilinger
        if (self._mysqldb_gt_or_eq((1, 2, 1))):
            cnx = MySQLdb.connect(db=path, user=user, passwd=password,
                                  host=host, port=port, charset='utf8')
        else:
            cnx = MySQLdb.connect(db=path, user=user, passwd=password,
                                  host=host, port=port, use_unicode=True)
            self._set_character_set(cnx, 'utf8')
        ConnectionWrapper.__init__(self, cnx)
示例#25
0
 def __init__(self, path, log, user=None, password=None, host=None,
              port=None, params={}):
     if path.startswith('/'):
         path = path[1:]
     if password == None:
         password = ''
     if port == None:
         port = 3306
     opts = {}
     for name, value in params.iteritems():
         key = name.encode('utf-8')
         if name == 'read_default_group':
             opts[key] = value
         elif name == 'init_command':
             opts[key] = value.encode('utf-8')
         elif name in ('read_default_file', 'unix_socket'):
             opts[key] = value.encode(sys.getfilesystemencoding())
         elif name in ('compress', 'named_pipe'):
             opts[key] = as_int(value, 0)
         else:
             self.log.warning("Invalid connection string parameter '%s'",
                              name)
     cnx = MySQLdb.connect(db=path, user=user, passwd=password, host=host,
                           port=port, charset='utf8', **opts)
     self.schema = path
     if hasattr(cnx, 'encoders'):
         # 'encoders' undocumented but present since 1.2.1 (r422)
         cnx.encoders[Markup] = cnx.encoders[types.UnicodeType]
     cursor = cnx.cursor()
     cursor.execute("SHOW VARIABLES WHERE "
                    " variable_name='character_set_database'")
     self.charset = cursor.fetchone()[1]
     if self.charset != 'utf8':
         cnx.query("SET NAMES %s" % self.charset)
         cnx.store_result()
     ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
示例#26
0
 def __init__(self, path, log=None, user=None, password=None, host=None,
              port=None, params={}):
     if path.startswith('/'):
         path = path[1:]
     if 'host' in params:
         host = params['host']
     if has_psycopg:
         dsn = []
         if path:
             dsn.append('dbname=' + path)
         if user:
             dsn.append('user='******'password='******'host=' + host)
         if port:
             dsn.append('port=' + str(port))
         cnx = psycopg.connect(' '.join(dsn))
         cnx.set_client_encoding('UNICODE')
     elif has_pgsql:
         # Don't use chatty, inefficient server-side cursors.
         # http://pypgsql.sourceforge.net/pypgsql-faq.html#id2787367
         PgSQL.fetchReturnsList = 1
         PgSQL.noPostgresCursor = 1
         cnx = PgSQL.connect('', user, password, host, path, port, 
                             client_encoding='utf-8', unicode_results=True)
     try:
         self.schema = None
         if 'schema' in params:
             self.schema = params['schema']
             cnx.cursor().execute('SET search_path TO %s', (self.schema,))
             cnx.commit()
     except PGSchemaError:
         cnx.rollback()
     ConnectionWrapper.__init__(self, cnx, log)
示例#27
0
 def __init__(self,
              path,
              log,
              user=None,
              password=None,
              host=None,
              port=None,
              params={}):
     if path.startswith('/'):
         path = path[1:]
     if password == None:
         password = ''
     if port == None:
         port = 3306
     opts = {}
     for name, value in params.iteritems():
         if name in ('init_command', 'read_default_file',
                     'read_default_group', 'unix_socket'):
             opts[name] = value
         elif name in ('compress', 'named_pipe'):
             opts[name] = as_int(value, 0)
         else:
             self.log.warning("Invalid connection string parameter '%s'",
                              name)
     cnx = MySQLdb.connect(db=path,
                           user=user,
                           passwd=password,
                           host=host,
                           port=port,
                           charset='utf8',
                           **opts)
     if hasattr(cnx, 'encoders'):
         # 'encoders' undocumented but present since 1.2.1 (r422)
         cnx.encoders[Markup] = cnx.encoders[types.UnicodeType]
     ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
示例#28
0
    def __init__(self,
                 path,
                 user=None,
                 password=None,
                 host=None,
                 port=None,
                 params={}):
        import MySQLdb

        if path.startswith('/'):
            path = path[1:]
        if password == None:
            password = ''
        if port == None:
            port = 3306

        # python-mysqldb 1.2.1 added a 'charset' arg that is required for
        # unicode stuff.  We hack around that here for older versions; at
        # some point, this hack should be removed, and a strict requirement
        # on 1.2.1 made.  -dilinger
        if (self._mysqldb_gt_or_eq((1, 2, 1))):
            cnx = MySQLdb.connect(db=path,
                                  user=user,
                                  passwd=password,
                                  host=host,
                                  port=port,
                                  charset='utf8')
        else:
            cnx = MySQLdb.connect(db=path,
                                  user=user,
                                  passwd=password,
                                  host=host,
                                  port=port,
                                  use_unicode=True)
            self._set_character_set(cnx, 'utf8')
        ConnectionWrapper.__init__(self, cnx)
示例#29
0
 def __init__(self,
              path,
              log,
              user=None,
              password=None,
              host=None,
              port=None,
              params={}):
     if path.startswith('/'):
         path = path[1:]
     if 'host' in params:
         host = params['host']
     cnx = pymssql.connect(database=path,
                           user=user,
                           password=password,
                           host=host,
                           port=port)
     self.schema = path
     conn = ConnectionWrapper.__init__(self, cnx, log)
     self._is_closed = False
示例#30
0
 def __init__(self, pool, cnx, tid):
     ConnectionWrapper.__init__(self, cnx)
     self._pool = pool
     self._tid = tid
示例#31
0
 def __init__(self, pool, cnx, tid):
     ConnectionWrapper.__init__(self, cnx)
     self._pool = pool
     self._tid = tid
示例#32
0
文件: pool.py 项目: timgraham/trac
 def __init__(self, pool, cnx, key, tid, log=None):
     ConnectionWrapper.__init__(self, cnx, log)
     self._pool = pool
     self._key = key
     self._tid = tid
示例#33
0
 def __init__(self, pool, cnx, key, tid, log=None):
     ConnectionWrapper.__init__(self, cnx, log)
     self._pool = pool
     self._key = key
     self._tid = tid
示例#34
0
 def __init__(self, path, log=None, params={}):
     cnx = pyodbc.connect(path)
     ConnectionWrapper.__init__(self, cnx, log)