Skip to main content

Posts

Showing posts from January, 2011

Use user-defined functions in with sqlalchemy

You may use user-defined functions with sqlalchemy. First how to create a function with sqlalchemy: cmd1 = 'DROP FUNCTION IF EXISTS `dummyfunc`' cmd2 = '''create function dummyfunc  ()   RETURNS INT   DETERMINISTIC    BEGIN     DECLARE ret INT;     SET ret = 0;     RETURN ret;    END''' metadata.bind.execute(cmd1) metadata.bind.execute(cmd2) Second, use the function you just created with func.function_name like: session.query(TestTable,func.dummyfunc()).first()   Very simple!

Solve KeyboardRandomPool not found in Crypto.Util.randpool

Errors like Crypto.Util.randpool.KeyboardRandomPool not found may occur if you update your pycrypto to a newer version(Like 2.3). Due to this article , randpool.KeyboardRandomPool has been marked deprecated in previous version. We should use Crypto.Random instead. Just change things like: Crypto.Util.randpool.KeyboardRandomPool().get_bytes(1) to: Crypto.Random.get_random_bytes(1)

One trick for building mysql master-slave chains

There are many tutorials for master-slave replication in Mysql( link1 , link2 ). But there is one trick if you want to build a slave for a slave. It is log-slave-updates, you may add it under [mysqld] in /etc/mysql/my.cnf or attach --log-slave-updates in mysqld. By default, the slave server doesn't write bin log for relication data, change log-slave-updates to yes will let slave replicate the bin log for master.