def __init__(self, pykotatool, host, dbname, user, passwd) :
     """Opens the MySQL database connection."""
     BaseStorage.__init__(self, pykotatool)
     try :
         (host, port) = host.split(":")
         port = int(port)
     except ValueError :    
         port = 3306           # Use the default MySQL port
     
     self.tool.logdebug("Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..." % (host, port, dbname, user))
     try :
         self.database = MySQLdb.connect(host=host, port=port, db=dbname, user=user, passwd=passwd, charset="utf8")
     except TypeError :    
         self.tool.logdebug("'charset' argument not allowed with this version of python-mysqldb, retrying without...")
         self.database = MySQLdb.connect(host=host, port=port, db=dbname, user=user, passwd=passwd)
         
     try :
         self.database.autocommit(1)
     except AttributeError :    
         raise PyKotaStorageError, _("Your version of python-mysqldb is too old. Please install a newer release.")
     self.cursor = self.database.cursor()
     self.cursor.execute("SET NAMES 'utf8';")
     self.cursor.execute("SET TRANSACTION ISOLATION LEVEL READ COMMITTED;") # Same as PostgreSQL and Oracle's default
     self.closed = 0
     self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" % (host, port, dbname, user))
Beispiel #2
0
 def __init__(self, pykotatool, host, dbname, user, passwd) :
     """Opens the SQLite database connection."""
     BaseStorage.__init__(self, pykotatool)
     
     self.tool.logdebug("Trying to open database (dbname=%s)..." % dbname)
     self.database = sqlite.connect(dbname, isolation_level=None)
     self.cursor = self.database.cursor()
     self.closed = 0
     self.tool.logdebug("Database opened (dbname=%s)" % dbname)
Beispiel #3
0
    def __init__(self, pykotatool, host, dbname, user, passwd):
        """Opens the SQLite database connection."""
        BaseStorage.__init__(self, pykotatool)

        self.tool.logdebug("Trying to open database (dbname=%s)..." % dbname)
        self.database = sqlite.connect(dbname, isolation_level=None)
        self.cursor = self.database.cursor()
        self.closed = 0
        self.tool.logdebug("Database opened (dbname=%s)" % dbname)
Beispiel #4
0
    def __init__(self, pykotatool, host, dbname, user, passwd) :
        """Opens the MySQL database connection."""
        BaseStorage.__init__(self, pykotatool)
        try :
            (host, port) = host.split(":")
            port = int(port)
        except ValueError :
            port = 3306           # Use the default MySQL port

        self.tool.logdebug("Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..." \
                               % (repr(host),
                                  repr(port),
                                  repr(dbname),
                                  repr(user)))
        try :
            self.database = MySQLdb.connect(host=host,
                                            port=port,
                                            db=dbname,
                                            user=user,
                                            passwd=passwd,
                                            charset="utf8")
        except TypeError :
            self.tool.logdebug("'charset' argument not allowed with this version of python-mysqldb, retrying without...")
            self.database = MySQLdb.connect(host=host,
                                            port=port,
                                            db=dbname,
                                            user=user,
                                            passwd=passwd)

        try :
            self.database.autocommit(1)
        except AttributeError :
            raise PyKotaStorageError, _("Your version of python-mysqldb is too old. Please install a newer release.")
        self.cursor = self.database.cursor()
        self.cursor.execute("SET NAMES 'utf8';")
        self.cursor.execute("SET TRANSACTION ISOLATION LEVEL READ COMMITTED;") # Same as PostgreSQL and Oracle's default
        self.closed = False
        self.tool.logdebug("Database opened (host=%s, port=%s, dbname=%s, user=%s)" \
                               % (repr(host),
                                  repr(port),
                                  repr(dbname),
                                  repr(user)))
        try :
            # Here we try to select a string (an é) which is
            # already encoded in UTF-8. If python-mysqldb suffers from
            # the double encoding problem, we will catch the exception
            # and activate a workaround.
            self.cursor.execute("SELECT '%s';" % (chr(0xc3) + chr(0xa9))) # é in UTF-8
            self.cursor.fetchall()
        except UnicodeDecodeError :
            self.needsworkaround = True
            self.tool.logdebug("Database needs encoding workaround.")
        else :
            self.needsworkaround = False
            self.tool.logdebug("Database doesn't need encoding workaround.")
Beispiel #5
0
    def __init__(self, pykotatool, host, dbname, user, passwd) :
        """Opens the PostgreSQL database connection."""
        BaseStorage.__init__(self, pykotatool)
        try :
            (host, port) = host.split(":")
            port = int(port)
        except ValueError :
            port = 5432         # Use PostgreSQL's default tcp/ip port (5432).

        self.tool.logdebug("Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..." % (host, port, dbname, user))
        try :
            self.database = pg.DB(host=host, port=port, dbname=dbname, user=user, passwd=passwd)
        except PGError, msg :
            msg = "%(msg)s --- the most probable cause of your problem is that PostgreSQL is down, or doesn't accept incoming connections because you didn't configure it as explained in PyKota's documentation." % locals()
            raise PGError, msg
Beispiel #6
0
    def __init__(self, pykotatool, host, dbname, user, passwd):
        """Opens the MySQL database connection."""
        BaseStorage.__init__(self, pykotatool)
        try:
            (host, port) = host.split(":")
            port = int(port)
        except ValueError:
            port = 3306  # Use the default MySQL port

        self.tool.logdebug(
            "Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..."
            % (host, port, dbname, user))
        try:
            self.database = MySQLdb.connect(host=host,
                                            port=port,
                                            db=dbname,
                                            user=user,
                                            passwd=passwd,
                                            charset="utf8")
        except TypeError:
            self.tool.logdebug(
                "'charset' argument not allowed with this version of python-mysqldb, retrying without..."
            )
            self.database = MySQLdb.connect(host=host,
                                            port=port,
                                            db=dbname,
                                            user=user,
                                            passwd=passwd)

        try:
            self.database.autocommit(1)
        except AttributeError:
            raise PyKotaStorageError, _(
                "Your version of python-mysqldb is too old. Please install a newer release."
            )
        self.cursor = self.database.cursor()
        self.cursor.execute("SET NAMES 'utf8';")
        self.cursor.execute("SET TRANSACTION ISOLATION LEVEL READ COMMITTED;"
                            )  # Same as PostgreSQL and Oracle's default
        self.closed = 0
        self.tool.logdebug(
            "Database opened (host=%s, port=%s, dbname=%s, user=%s)" %
            (host, port, dbname, user))
Beispiel #7
0
    def __init__(self, pykotatool, host, dbname, user, passwd):
        """Opens the PostgreSQL database connection."""
        BaseStorage.__init__(self, pykotatool)
        try:
            (host, port) = host.split(":")
            port = int(port)
        except ValueError:
            port = 5432  # Use PostgreSQL's default tcp/ip port (5432).

        self.tool.logdebug(
            "Trying to open database (host=%s, port=%s, dbname=%s, user=%s)..."
            % (host, port, dbname, user))
        try:
            self.database = pg.DB(host=host,
                                  port=port,
                                  dbname=dbname,
                                  user=user,
                                  passwd=passwd)
        except PGError, msg:
            msg = "%(msg)s --- the most probable cause of your problem is that PostgreSQL is down, or doesn't accept incoming connections because you didn't configure it as explained in PyKota's documentation." % locals(
            )
            raise PGError, msg