marijnh / Postmodern

A Common Lisp PostgreSQL programming interface
http://marijnhaverbeke.nl/postmodern
Other
400 stars 90 forks source link

Fix some short-comings in execute-file #285

Closed sabracrolleton closed 3 years ago

sabracrolleton commented 3 years ago

When trying to run execute-file against an sql file, certain characters in sql comments would cause execute-file to fail. This commit fixes that by stripping all single and multi-line comments from sql files first before trying to parse them. It also adds some additional capability when the sql file includes additional sql files.

The existing parsing code is untouched with this commit.

This commit adds \include and \include_relative and follows the Postgresql practice that \i (and \include) and \ir (and \include_relative) resolve differently.

Specifically \i or \include which look for a file location relative to your default pathname (current working directory) or \ir or \include_relative which look for a file location relative to the initial sql file.

If the file is not found in the expected location, execute-file will look to see if the requested file is in the other command location. In other words, if not found where \i would expect it, is the file in the location that \ir would expect it? If the file is not found in either location, a restart will be triggered which allows you to provide a new name (including pathname) for the file.

Execute-file now allows more flexibility in formatting in that preceding spaces or tabs are now ignored at the beginning of an inclusion meta-command line or excess spaces or tabs between the meta-command and the filename of the file to be included.

Execute-file now tracks the files which have been included and will not include a file twice (which would lead to infinite loops).