rewrite of code.google.com/p/w-pysql