hssqlppp: Sql parser and type checker

[ bsd3, database, language, library ] [ Propose Tags ]

Sql parser, pretty printer and type checker, targets PostGreSQL SQL and PL/pgSQL, uses Parsec and UUAGC. Overview: see the module Database.HsSqlPpp.TypeChecking.Ast for the ast types; Parser for converting text to asts; PrettyPrinter for converting asts to text; TypeChecker for annotating asts (this does the type checking), and working with annotated trees; Scope to read a catalog from a database to type check against, or to generate catalog information; DatabaseLoader for the beginnings of a routine to load SQL into a database (e.g. to generate an ast then load it into a database without loading it via psql). The loader just about does the job but error handling is a bit crap at the moment. Comes with a HUnit test suite which you can run using the HsSqlPppTests executable, and command line access to some functions via a exe called HsSqlSystem. See the project page https://launchpad.net/hssqlppp for more information and documentation links.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.4, 0.0.5, 0.0.6, 0.0.7, 0.0.8, 0.0.9, 0.0.10, 0.1.0, 0.2.0, 0.3.0, 0.3.1, 0.4.0, 0.4.1, 0.4.2, 0.6.0, 0.6.1, 0.6.2
Change log changelog
Dependencies base (>=3 && <5), containers, directory, haskell98, HDBC, HDBC-postgresql, HUnit, mtl, parsec (>=3), pretty, regex-posix, test-framework, test-framework-hunit [details]
License BSD-3-Clause
Copyright Copyright 2009 Jake Wheat
Author Jake Wheat
Maintainer jakewheatmail@gmail.com
Category Database
Home page https://launchpad.net/hssqlppp
Bug tracker mailto:jakewheatmail@gmail.com
Uploaded by JakeWheat at 2009-09-19T18:59:10Z
Distributions
Reverse Dependencies 4 direct, 0 indirect [details]
Executables HsSqlPppTests, HsSqlSystem
Downloads 13424 total (41 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for hssqlppp-0.0.6

[back to package description]
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, 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, but is in an early state. You can run the type checker on your
SQL, see the 'usage' file for details.

There is a command line wrapper, HsSqlSystem.lhs, which provides some
utility functions to access some of the library code.

It comes with a small test suite.

There is not much documentation at the moment. See the 'usage' file
where there are instructions on how to parse files, and type check
them to see how well the code supports your SQL source.

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 and
UUAGC.

================================================================================

Homepage

The project is hosted on Launchpad
http://launchpad.net/hssqlppp/

You can get the latest code using Bazaar:
bzr branch lp:~jakewheat/hssqlppp/trunk

HackageDB page:
http://hackage.haskell.org/package/hssqlppp
This should hopefully have some basic Haddock documentation to view
when version 0.0.6 is uploaded.

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 AST node types aren't well designed, in particular they contain
patchy location information, and limited other annotations. This is
being worked on.

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.

Supporting other SQL dialects: I think it might be realistic to
support portable select, insert, update and delete with ?
placeholders. I think cross platform DDL isn't ever going to be
sensible in non toy databases, and if you wanted to use this utility
e.g. support MySQL or MS SQL Server, it might be best to start by
forking the code, I would be happy to help support this in any way I
can.

Future plans:

* use this system to develop a Lint-type checker for PL/pgSQL;

* 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.