Master reconciliation and statement import ama

another general remark: never use %d in queries. Use %s every time (http://initd.org/psycopg/docs/usage.html#passing-parameters-to-sql-queries)