Prequel is a minimal SQLCMD-compatible preprocessor.
- Adds a 'SQLCMD mode' to your project with a couple lines of code.
- Supports
GO
,$(var)
,:setvar
, and:r
. - Does not require the SQLCMD utility to be present.
- Stable: in private use for years with very few reported defects.
- Tested: 100% coverage by automated tests.
- Documented: IntelliSense on everything.
Install this NuGet Package in your project.
SQL in, preprocessed batches out — it's as simple as that.
// Import the namespace
using Prequel;
// Create a preprocessor
var preprocessor = new SqlCmdPreprocessor();
// Optional: set some preprocessor variables
preprocessor.Variables["Foo"] = "Bar";
// Preprocess!
var batches = preprocessor.Process(sql);
// Do something with the batches
foreach (var batch in batches)
{
// ...
}
Prequel supports a limited subset of SQLCMD preprocessing features.
SELECT * FROM Foo; -- first batch
GO
SELECT * FROM Bar; -- second batch
SELECT $(Columns) FROM Foo;
:setvar Columns Name -- this works
:setvar Columns "Id, Name" -- also works; required if value contains space
:r OtherFile.sql -- this works
:r "Other File.sql" -- also works; required if path contains space
Preprocessor directives are case-insensitive.
A GO
batch separator must appear the the beginning of a line.
No other content may appear on that line.
A :setvar
or :r
directive must appear at the beginning of a line.
An optional line comment may follow the directive.
$(…)
may appear anywhere, including inside other preprocessor directives.