Readme for hssqlppp-0.0.8

Summary: A parser, pretty printer, and type checker for PostGreSQL SQL and PL/pgSQL. BSD licensed. The current aims of the project is to provide a parser and type checker for a substantial portion of PostGreSQL SQL and PL/pgSQL. Status: it successfully parses and accurately pretty prints the three moderate sized SQL files from another project of mine, but there are lots of missing bits. Coverage of SQL is reasonable - it's possible that your SQL files will parse ok, but it's also possible that they won't parse at all - see below for more details on what is supported and unsupported. It also has the beginnings of a type checker, which currently can type check a large subset of expressions and selects that the parser can parse, and some aspects of all of the DDL statements that parse, but is in an early state. You can run the type checker on your SQL in various ways from the command line, see the 'usage' file for details. It comes with a small test suite. It is Cabal-installable, run: cabal update then cabal install hssqlppp to install the libraries and HsSqlSystem executable (and the test runner executable), if you want to try the utilities out, or run cabal unpack hssqlppp to download and view the source code easily. I think it should work on all GHC 6.10.x and possibly also GHC 6.8.x. See the file 'development' for some notes on how to work with the source. The main dependencies of this project are: Parsec 3, HUnit, HDBC, UUAGC and Data.Generics. The tests run without accessing PostGreSQL, but some of the utility functions do need it. ================================================================================ Homepage There isn't really a homepage or website yet, but you can view the Launchpad page where the code is hosted, and the HackageDB page. Launchpad: http://launchpad.net/hssqlppp/ HackageDB page: http://hackage.haskell.org/package/hssqlppp You can also browse the limited Haddock documentation online here. You can get the latest development code from Launchpad using Bazaar: bzr branch lp:~jakewheat/hssqlppp/trunk To get a snapshot release, see the downloads on the Launchpad page, or use cabal install. Contact Let me know if you're using/ interesting in using the library, if you have any problems or suggestions, etc.. All contributions, comments and criticism welcome: jakewheatmail@gmail.com You can also report problems on the bug tracker on Launchpad. ================================================================================ = Syntax supported/ not supported: == Parsing Partially supports: select statements (selectlists (*, qualified, aliased/correlation names, expressions) distinct, basic window functions, from (with explicit joins - natural, inner, cross, left, right, full outer, on and using), aliases, from functions where, group by, having, order by, limit, offset except, intersect, union expressions: subselects, in, row ctors, strings + dollar strings, integers, case, exists, boolean literals, null, arrays and subscripting (slightly limited), function calls, identifiers, cast(x as y), between (quite limited), substring(x from a for b) also partially supports: insert (with multiple values and select support), update, delete (all three with returning) create and drop table, type, view, domain create function for sql and plpgsql functions all constraint types sort of skips copy statements instead of erroring plpgsql statements: select into null continue perform execute assignment if return, return next, return query raise for (select and integer variants) while case statement Many things are missing at the moment, in particular selects: cte, implicit joins joins in updates (delete from, update using) alter statements create and drop apart from table, view, domain, type, function transaction commands triggers and trigger functions loop statement, labels error trapping cursors This is a non-exhaustive list. Expression support is patchy, should work pretty well for a lot of simple stuff though. There is a strong possibility that for some complex selects and expressions, the implicit precedence (that is, bits without enclosing parenthesis) may parse in the wrong direction. Please let me know if you encounter such an error. == Type checking Type checking supports a good subset of expressions and select statements that the parser parses, and has basic support for insert, update, delete and the various create statements that the parser supports. Development work is currently focused in this area. = Other current downsides: The design of the AST node types is pretty basic. Not much work has been done on correctly rejecting invalid SQL (although it does pretty well despite this) and not much thought has been put into error messages and error reporting yet, this is slowly improving, and at some point will become a major focus - I hope this code will provide substantial benefits when developing in PL/pgSQL in the future. Only supports PostGreSQL SQL and PL/pgSQL. Future plans (provisional): * use this system to develop a Lint-type checker for PL/pgSQL; * provide support to help developing SQL from an IDE (targeting Emacs mainly) * support type checking simple SQL statements that you'd embed in Haskell code, including with ? placeholders, to support generating type safe wrappers - could integrate with MetaHDBC?; * possibly a lightweight code generation/ simple macro support to help with developing more robust PL/pgSQL code.