The hssqlppp package

[Tags: bsd3, library]

Sql parser, pretty printer and type checker, targets PostGreSQL SQL and PL/pgSQL, uses Parsec and UUAGC.

Overview:

see the module Ast for the ast types;

Parser for converting text to asts;

PrettyPrinter for converting asts to text;

AnnotateSource for pretty printing annotations inline with original source;

Annotator for annotating asts (this does the type checking); and working with annotated trees;

SqlTypes for the data types which represent SQL types, the data type for type errors, and some support functions;

Annotation for the annotation data types and utilities, this also contains the data types for SQL types;

Environment 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, run this file with no arguments to get some help. See the project page https://launchpad.net/hssqlppp for more information and documentation links.


[Skip to ReadMe]

Properties

Versions0.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
Change logchangelog
Dependenciesbase (==4.*), containers, directory, haskell98, HDBC, HDBC-postgresql, HUnit, mtl, parsec (>=3), pretty, regex-posix, syb, test-framework, test-framework-hunit [details]
LicenseBSD3
CopyrightCopyright 2009 Jake Wheat
AuthorJake Wheat
Maintainerjakewheatmail@gmail.com
Stabilitypre-alpha
CategoryDatabase
Home pagehttps://launchpad.net/hssqlppp
Bug trackermailto:jakewheatmail@gmail.com
ExecutablesHsSqlPppTests, HsSqlSystem
UploadedTue Sep 29 11:16:39 UTC 2009 by JakeWheat
DistributionsNixOS:0.4.2
Downloads2211 total (90 in last 30 days)
Votes
0 []
StatusDocs uploaded by user
Build status unknown [no reports yet]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

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.