View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
D Medved > TSQL-SplitStatement > TSQL::SplitStatement



Annotate this POD

View/Report Bugs
Module Version: 0.15   Source  


TSQL::SplitStatement - Implements similar functionality to SQL::SplitStatement, but for TSQL.


Version 0.15


This is a simple module which tries to split TSQL code into simple, recognisable code elements. It implements similar functionality to SQL::SplitStatement, but does so for TSQL. TSQL notoriously doesn't bother with statement separators or teminators. There is no overlap with or dependency on SQL::SplitStatement. But being lazy, I've loosely based the documentation on that for SQL::SplitStatement.


The module splits TSQL code into recognisable units..

It removes comments, distinguishes strings and quoted names from code, and then returns a list of TSQL statements and/or 'tokens'.

It splits the code by attempting to recognise the start of the statement following the current one. It uses a mix of Regular Expressions and Parse::RecDescent.

It's purely an adhoc, heuristic approach, and was written to suit my own immediate requirements. The futher reaches of TSQL, including the less commonly used DDL statements are not covered. There is some attempt to cover elements of TSQL introduced in SQL Server 2008, but there is nothing to cover SQL Server 2012. It is a work in progress. Bug reports are welcomed, but may not necessarily be acted upon. Contributors are more than welcome.


TSQL::SplitStatement depends on the following modules:


Ded MedVed, <dedmedved at>


Please report any bugs or feature requests to bug-tsql-splitstatment at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.



It creates and returns a new TSQL::SplitStatement object.


This is the method which actually splits the SQL code into its atomic components.

It returns a list containing the atomic statements, in the same order they appear in the original SQL code.

    my $sql_splitter = TSQL::SplitStatement->new();
    my @statements = $sql_splitter->splitSQL( 'SELECT 1;SELECT 2; );
    print 'The SQL code contains ' . scalar(@statements) . ' statements.';
    # The SQL code contains 2 statements.


This is the method which builds the regular expression that recognises the start of a TSQL statement. Internal only.


No limitations are currently known, as far as the intended usage is concerned. You *are* bound to uncover a large number of problems. The handling of create procedure/trigger/function statements is problematic.

Please report any problematic cases.


You can find documentation for this module with the perldoc command.

    perldoc TSQL::SplitStatement

You can also look for information at:


None yet.



Copyright 2012 Ded MedVed.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.

syntax highlighting: