Logo Search packages:      
Sourcecode: python-biopython version File versions

def BioSQL::BioSeqDatabase::open_database (   driver = "MySQLdb",
  kwargs 
)

Main interface for loading a existing BioSQL-style database.

This function is the easiest way to retrieve a connection to a
database, doing something like:
    
    >>> from BioSeq import BioSeqDatabase
    >>> server = BioSeqDatabase.open_database(user = "root", db="minidb")

the various options are:
driver -> The name of the database driver to use for connecting. The
driver should implement the python DB API. By default, the MySQLdb
driver is used.
user -> the username to connect to the database with.
password, passwd -> the password to connect with
host -> the hostname of the database
database or db -> the name of the database

Definition at line 10 of file BioSeqDatabase.py.

00010                                                :
    """Main interface for loading a existing BioSQL-style database.

    This function is the easiest way to retrieve a connection to a
    database, doing something like:
        
        >>> from BioSeq import BioSeqDatabase
        >>> server = BioSeqDatabase.open_database(user = "root", db="minidb")

    the various options are:
    driver -> The name of the database driver to use for connecting. The
    driver should implement the python DB API. By default, the MySQLdb
    driver is used.
    user -> the username to connect to the database with.
    password, passwd -> the password to connect with
    host -> the hostname of the database
    database or db -> the name of the database
    """
    module = __import__(driver)
    connect = getattr(module, "connect")

    # Different drivers use different keywords...
    kw = kwargs.copy()
    if driver == "MySQLdb":
        if kw.has_key("database"):
            kw["db"] = kw["database"]
            del kw["database"]
        if kw.has_key("password"):
            kw["passwd"] = kw["password"]
            del kw["password"]
    else:
        # DB-API recommendations
        if kw.has_key("db"):
            kw["database"] = kw["db"]
            del kw["db"]
        if kw.has_key("passwd"):
            kw["password"] = kw["passwd"]
            del kw["passwd"]
    if driver == "psycopg" and not kw.get("database"):
        kw["database"] = "template1"
    try:
        conn = connect(**kw)
    except module.InterfaceError:
        # Ok, so let's try building a DSN
        # (older releases of psycopg need this)
        if kw.has_key("database"):
            kw["dbname"] = kw["database"]
            del kw["database"]
        elif kw.has_key("db"):
            kw["dbname"] = kw["db"]
            del kw["db"]
        
        dsn = ' '.join(['='.join(i) for i in kw.items()])
        conn = connect(dsn)
    
    return DBServer(conn, module)

class DBServer:


Generated by  Doxygen 1.6.0   Back to index