def autoschema(alias, schema=None, guesscache=True, module=None, sequence_mapper=None):
    """
    returns a dictionary of PyDO objects created automatically by
    schema introspection, keyed by class name.  Typical usage:

      globals().update(autoschema('myalias'))

    The PyDO objects created are extremely bare, but may be enough for
    quick scripts.   If you want to pickle them, pass in a module
    for them to live in for the "module" parameter.  
    """
    ns={}
    db=getConnection(alias)
    for table in db.listTables(schema):
        d=dict(guesscache=guesscache,
               guess_columns=True,
               connectionAlias=alias,
               schema=schema,
               table=table)
        if sequence_mapper:
            d['sequence_mapper'] = sequence_mapper
        Table=table.capitalize()
        obj=type(Table, (PyDO,), d)
        if module:
            moduleize(module, obj)
        ns[Table]=obj
    return ns
Exemple #2
0
def autoschema(alias,
               schema=None,
               guesscache=True,
               module=None,
               sequence_mapper=None):
    """
    returns a dictionary of PyDO objects created automatically by
    schema introspection, keyed by class name.  Typical usage:

      globals().update(autoschema('myalias'))

    The PyDO objects created are extremely bare, but may be enough for
    quick scripts.   If you want to pickle them, pass in a module
    for them to live in for the "module" parameter.  
    """
    ns = {}
    db = getConnection(alias)
    for table in db.listTables(schema):
        d = dict(guesscache=guesscache,
                 guess_columns=True,
                 connectionAlias=alias,
                 schema=schema,
                 table=table)
        if sequence_mapper:
            d['sequence_mapper'] = sequence_mapper
        Table = table.capitalize()
        obj = type(Table, (PyDO, ), d)
        if module:
            moduleize(module, obj)
        ns[Table] = obj
    return ns
Exemple #3
0
def test_swapConnection1():
    db = D.getConnection('pydotest')
    conn1 = db._connect()
    conn2 = db.conn
    assert not (conn1 is conn2)
    conn3 = db.swapConnection(conn1)
    assert conn3 is conn2
    assert conn1 is db.conn
def test_swapConnection1():
    db=D.getConnection('pydotest')
    conn1=db._connect()
    conn2=db.conn
    assert not (conn1 is conn2)
    conn3=db.swapConnection(conn1)
    assert conn3 is conn2
    assert conn1 is db.conn
def test_threads1():
    """
    tests that each thread gets its own dbapi connection.
    """
    db=D.getConnection('pydotest')
    id1=id(db.conn)

    class mythread(threading.Thread):
        def run(self):
            mydb=D.getConnection('pydotest')
            self.connid=id(mydb.conn)
    t=mythread()
    t.start()
    t.join()
    assert t.connid!=id1
    assert id(db.conn)==id1
Exemple #6
0
def test_threads1():
    """
    tests that each thread gets its own dbapi connection.
    """
    db = D.getConnection('pydotest')
    id1 = id(db.conn)

    class mythread(threading.Thread):
        def run(self):
            mydb = D.getConnection('pydotest')
            self.connid = id(mydb.conn)

    t = mythread()
    t.start()
    t.join()
    assert t.connid != id1
    assert id(db.conn) == id1
def autoschema(alias, schema=None, guesscache=True):
    """
    returns a dictionary of PyDO objects created automatically by
    schema introspection, keyed by class name.  Typical usage:

      globals().update(autoschema('myalias'))

    The PyDO objects created are extremely bare, but may be enough for
    quick scripts. 
    """
    ns = {}
    db = getConnection(alias)
    for table in db.listTables(schema):
        d = dict(guesscache=guesscache, guess_columns=True, connectionAlias=alias, schema=schema, table=table)
        Table = table.capitalize()
        obj = type(Table, (PyDO,), d)
        ns[Table] = obj
    return ns
def autoschema(alias, schema=None, guesscache=True):
    """
    returns a dictionary of PyDO objects created automatically by
    schema introspection, keyed by class name.  Typical usage:

      globals().update(autoschema('myalias'))

    The PyDO objects created are extremely bare, but may be enough for
    quick scripts. 
    """
    ns = {}
    db = getConnection(alias)
    for table in db.listTables(schema):
        d = dict(guesscache=guesscache,
                 guess_columns=True,
                 connectionAlias=alias,
                 schema=schema,
                 table=table)
        Table = table.capitalize()
        obj = type(Table, (PyDO, ), d)
        ns[Table] = obj
    return ns
Exemple #9
0
def test_pool1():
    stuff = D._aliases['pydotest'].copy()
    D.initAlias('pydotestpool', stuff['driver'], stuff['connectArgs'],
                D.ConnectionPool(max_poolsize=4, keep_poolsize=4),
                stuff['verbose'])
    db = D.getConnection('pydotestpool')
    try:
        assert len(db.pool._busy) == 0
        assert len(db.pool._free) == 0
        conn = db.conn
        assert len(db.pool._busy) == 1
        assert len(db.pool._free) == 0
        c = conn.cursor()
        c.execute('SELECT 1+1')
        res = c.fetchone()
        assert res[0] == 2
        c.close()
        conn.close()
        assert len(db.pool._busy) == 0
        assert len(db.pool._free) == 1
    finally:
        D.delAlias('pydotestpool')
def test_pool1():
    stuff=D._aliases['pydotest'].copy()
    D.initAlias('pydotestpool',
                stuff['driver'],
                stuff['connectArgs'],
                D.ConnectionPool(max_poolsize=4, keep_poolsize=4),
                stuff['verbose'])
    db=D.getConnection('pydotestpool')
    try:
        assert len(db.pool._busy)==0
        assert len(db.pool._free)==0
        conn=db.conn
        assert len(db.pool._busy)==1
        assert len(db.pool._free)==0
        c=conn.cursor()
        c.execute('SELECT 1+1')
        res=c.fetchone()
        assert res[0]==2
        c.close()
        conn.close()
        assert len(db.pool._busy)==0
        assert len(db.pool._free)==1
    finally:
        D.delAlias('pydotestpool')
 def fget(self):
     return getConnection("pydotest")
Exemple #12
0
 def getDBI(cls):
     """return the database interface"""
     conn = getConnection(cls.connectionAlias)
     return conn
 def fget(self):
     return getConnection('pydotest')
Exemple #14
0
 def run(self):
     mydb = D.getConnection('pydotest')
     self.connid = id(mydb.conn)
Exemple #15
0
 def run(self):
     mydb = D.getConnection('pydotestpool')
     self.connid = id(mydb.conn)
     while hold:
         time.sleep(0.1)
Exemple #16
0
def test_autocommit1():
    db = D.getConnection('pydotest')
    if config.DRIVER == 'mysql':
        assert db.autocommit
    else:
        assert not db.autocommit
 def run(self):
     mydb=D.getConnection('pydotestpool')
     self.connid=id(mydb.conn)
     while hold:
         time.sleep(0.1)
def test_autocommit1():
    db=D.getConnection('pydotest')
    if config.DRIVER=='mysql':
        assert db.autocommit
    else:
        assert not db.autocommit
Exemple #19
0
 def getDBI(cls):
     """return the database interface"""
     conn = getConnection(cls.connectionAlias)
     return conn
 def run(self):
     mydb=D.getConnection('pydotest')
     self.connid=id(mydb.conn)
 def fget(self):
     return getConnection('pydotest')