Showing posts with label sqlalchmy. Show all posts
Showing posts with label sqlalchmy. Show all posts

2008/07/08

Release memory when using SqlAlchemy for a long time contextual session

First
session.flush()
then
session.close()

The close() method issues a clear(), and releases any transactional/connection resources. When connections are returned to the connection pool, whatever transactional state exists is rolled back.

When close() is called, the Session is in the same state as when it was first created, and is safe to be used again. close() is especially important when using a contextual session, which remains in memory after usage. By issuing close(), the session will be clean for the next request that makes use of it.

Join example in SQLalchemy

We have 2 tables

CREATE TABLE `zincnew01`.`zincmol` ( `zincid` int(8) unsigned NOT NULL, `pacname` char(3) NOT NULL, `numatoms` tinyint(3) unsigned NOT NULL, `numc` tinyint(3) unsigned NOT NULL, `numn` tinyint(3) unsigned NOT NULL, `numo` tinyint(3) unsigned NOT NULL, `numhal` tinyint(3) unsigned NOT NULL, `nums` tinyint(3) unsigned NOT NULL, `nump` tinyint(3) unsigned NOT NULL, `numarombnd` tinyint(3) unsigned NOT NULL, `numdoubbnd` tinyint(3) unsigned NOT NULL, `numtribnd` tinyint(3) unsigned NOT NULL, `numamibnd` tinyint(3) unsigned NOT NULL, `numacc` tinyint(3) unsigned NOT NULL, `numdon` tinyint(3) unsigned NOT NULL, `numring` tinyint(3) unsigned NOT NULL, `totringsize` tinyint(3) unsigned NOT NULL, `longestchain` tinyint(3) unsigned NOT NULL, `wienerind4` float(16,14) NOT NULL, `numbnd` tinyint(3) unsigned NOT NULL, `numfrg` tinyint(3) unsigned NOT NULL, `numrotbnd` tinyint(3) unsigned NOT NULL, `mw` float(8,3) unsigned NOT NULL, `clogp` float(5,2) NOT NULL, `charge` int(2) NOT NULL, `mol2file` blob, `tag` char(20) default NULL, PRIMARY KEY (`zincid`), KEY `pacname` (`pacname`), KEY `tag` (`tag`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1

and

CREATE TABLE `zincnew01`.`Pose` ( `id` int(11) NOT NULL auto_increment, `pose` int(4) default NULL, `ele` float default NULL, `elee` float default NULL, `vdw` float default NULL, `vdwe` float default NULL, `pdbfile` blob, `mol_zincid` int(8) unsigned default NULL, `tag` char(20) default NULL, PRIMARY KEY (`id`), KEY `ix_Pose_mol_zincid` (`mol_zincid`) ) ENGINE=MyISAM AUTO_INCREMENT=39261434 DEFAULT CHARSET=latin1

I want to query lile select * from Pose,zincmol where zincid=mol_zincid and pacname="xaa" In SQLalchemy (elixir) I use Pose.query.filter(Pose.tag==None).join('mol').filter(Mol.pacname=='xaa') to get the same results.

Use regular expression in sqlalchmy with Mysql

writing...