New SQL Parser in dbscript

November 30, 2009

I wrote about my plans to add a new SQL parser engine into dbscript a couple of months ago. Now the time has come to actually implement it for T-SQL (MS SQL Server; Oracle and PostgreSQL will follow in future versions), and I found that I did not foresee all the consequences of my initial intent. The overall architecture remained the same though.

The grammar definition allows to define attributes on non-terminals. Using the SQL Server versions as attributes (2005, 2008), I can mark commands or clauses as their support or feature has been introduced in a specific version, and store the database version as property of the uploaded Project Version.

The parser skips the parts of the uploaded file that it cannot parse, and writes these parts to the upload log. Up to now, the parser would simply fail if it considered the SQL file somehow invalid.

The (C#) object representation of a parsed SQL command has a boolean flag IsHandled for each non-terminal. The code processing the object representation needs to mark every non-terminal object as being handled (i.e. translated into schema information stored in the database). Objects that have not been flagged will also be listed in the upload log.

Next, the new parser allowed me to rewrite the dependency analysis. Until now, dbscript only analyzed view dependencies to order the CREATE VIEW statements. Dependency analysis has now been extended to all database objects.

One more major issue that has been solved is parsing and interpreting EXECUTE statements. Thus an EXEC sp_addextendedproperty is interpreted as adding a description to a database object.

This obviously led to changes in the XML generation of database schemas. Each object now lists its descriptions and the dependencies on and references from other database objects.

The XSL stylesheets which translate a project version XML into markup or HTML have been revised to reflect the additional information in the generated XML.

All taken together, the new parser adds:

  • better feedback on which parts of the uploaded SQL file have been processed
  • dependency analysis
  • object and column descriptions

See the following links documenting AdventureWorks OLTP 2008 (version 2005) for the effects of the new functionality:

Single HTML file documentation

MediaWiki documentation

ScrewTurn Wiki documentation

In both wikis, compare the (old-style) “wikibot” section with the new section “automatically generated” to see the changes.

The next version of dbscript with the mythical version number “1.0″ will be released soon ;)


Generating Database Documentation for ScrewTurn wikis

August 29, 2009

Updated XSL style sheets for dbscript documentation generators creating ScrewTurn content.

See here for sample output:

MS SQL AdventureWorks

Oracle Demo Schema

PostgreSQL OpenNMS

ScrewTurn also allows external Page Providers (instead of stored static pages)

MS SQL AdventureWorks (by Page Provider)


New Features in dbscript 0.95

March 23, 2009

The latest version 0.95 of dbscript adds new functionality:

Data Diagram generation

dbscript 0.95 adds the capability to generate Data Diagrams from imported and uploaded SQL Server database schemas.

This allows you to get a quick overview of a database schema. It is also useful if you plan to manually create a data diagram in Management Studio, and need some visual help of how to layout the diagram.

ScrewTurn Wiki Page Provider

In addition to the ScrewTurn documentation generator introduced in dbscript 0.94, the latest version includes a Page Provider which you add in the Administration panel of your ScrewTurnWiki installation.

Configure the Documentation Generator plugin with the same ConnectionString you use in your dbscript web application.

Next, create a Documentation Generator of type ScrewTurn Page Provider, and define its contents. After you generate, ScrewTurn Wiki displays the selected Project Version information. (You may need to restart the ScrewTurn web application)

Summary of Output generated by dbscript

This is a list of output samples generated by dbscript based on MS AdventureWorks sample database:

Value Scripts

C# const int declarations of a dbscript Table

VB.Net Const Integer declarations of a dbscript Table

Project Version / Database Schema

Data Diagram of MS AdventureWorks database

Documentation Generators

MediaWiki Documentation of MS AdventureWorks database

Single Object documentation in MediaWiki format

Single HTML File documentation of MS AdventureWorks

ScrewTurn Wiki Documentation of MS AdventureWorks database

ScrewTurn Wiki Page Provider Documentation of MS AdventureWorks database

The latest version of dbscript is available for download here.


Generate ScrewTurn Documentation of MS SQL Database and Values

March 5, 2009

In addition to creating MediaWiki content, dbscript 0.94 now also supports ScrewTurn wikis to generate database documentation.

The steps to setup the documentation generator are essentially the same as described here and here for MediaWiki wikis, except that the respective ScrewTurn alternatives (generator type, XSLs) have to be selected.

To allow the built-in bot to post content to the ScrewTurn wiki, the wiki’s web.config has to be modified to disable viewstate validation:

<pages enableViewState="true" enableEventValidation="false" />

Follow this link to browse the ScrewTurn documentation of AdventureWorks as generated by dbscript.

The latest version of dbscript is available for download here.


New Features in dbscript 0.94

March 4, 2009

The latest version 0.94 of dbscript adds new functionality:

Multi-user capability

A user/role model has been implemented which allows the following definitions:

  • System administrator roles
  • Project-specific roles (project administrator, project user)
  • User/Role assignments

Each user can be assigned to several roles. A role is either a sysadmin role, or assigned to one or more projects. Within a project, a role is defined as project administrator or project user role. Users inherit sysadmin, project admin, and project user capability from their assigned roles.

Documentation Generators

New documentation generators create documentation as

Value Scripts

Adding to existing functionality creating C# const declarations:

  • C# public static const classes are now declared partial
  • new C# public static class with string ToString(int) to convert an int identifier into its string representation
  • VB.Net public const declarations
  • define optional WHERE condition on generated values

Database Schema Checks

Added the following checks on database tables:

  • Tables without Primary Key
  • Tables without Unique Constraint
  • Tables without Foreign Key Constraints
  • Unreferences Tables
  • Isolated Tables

The latest version of dbscript is available for download here.