Moved SQL string to metadata

Also fixes bugs and catches uncaught pragma statements