Rewrite all SQL statements