C# Class Subtext.Scripting.SqlScriptRunner

Class used to manage and execute SQL scripts. Can also be used to hand
Inheritance: IScript, ITemplateScript
Show file Open project: ayende/Subtext Class Usage Examples

Public Methods

Method Description
Execute ( SqlTransaction transaction ) : int

Executes the script.

Use script.Execute(transaction) to do the work. We will also pull the status of our script exection from here.

SqlScriptRunner ( Assembly assemblyWithEmbeddedScript, Type scopingType, string scriptName, Encoding encoding ) : System

Initializes a new instance of the SqlScriptRunner class.

SqlScriptRunner ( Assembly assemblyWithEmbeddedScript, string fullScriptName, Encoding encoding ) : System

Initializes a new instance of the SqlScriptRunner class. Initializes the script to execute.

SqlScriptRunner ( ScriptCollection scripts ) : System

Initializes a new instance of the SqlScriptRunner class.

SqlScriptRunner ( Stream scriptStream, Encoding encoding ) : System

Initializes a new instance of the SqlScriptRunner class.

SqlScriptRunner ( Type scopingType, string scriptName, Encoding encoding ) : System

Initializes a new instance of the SqlScriptRunner class. Initializes the script to execute.

SqlScriptRunner ( string scriptText ) : System

Initializes a new instance of the SqlScriptRunner class.

Private Methods

Method Description
IsCrudScript ( Script script ) : bool
ReadStream ( Stream stream, Encoding encoding ) : string
SetNoCountOff ( SqlTransaction transaction ) : void

Temporarily set NOCOUNT OFF on the connection. We must do this b/c the SqlScriptRunner depends on all CRUD statements returning the number of effected rows to determine if an error occured. This isn't a perfect solution, but it's what we've got.

UnpackEmbeddedScript ( Assembly assembly, Type scopingType, string scriptName ) : Stream
UnpackEmbeddedScript ( Assembly assembly, string fullScriptName ) : Stream
UnpackEmbeddedScript ( Type scopingType, string scriptName ) : Stream

Method Details

Execute() public method

Executes the script.
Use script.Execute(transaction) to do the work. We will also pull the status of our script exection from here.
public Execute ( SqlTransaction transaction ) : int
transaction System.Data.SqlClient.SqlTransaction The current transaction.
return int

SqlScriptRunner() public method

Initializes a new instance of the SqlScriptRunner class.
public SqlScriptRunner ( Assembly assemblyWithEmbeddedScript, Type scopingType, string scriptName, Encoding encoding ) : System
assemblyWithEmbeddedScript System.Reflection.Assembly The assembly containing the script as an embedded resource.
scopingType System.Type /// Used to scope the script name within the embedded resource. ///
scriptName string Name of the script.
encoding System.Text.Encoding The encoding.
return System

SqlScriptRunner() public method

Initializes a new instance of the SqlScriptRunner class. Initializes the script to execute.
public SqlScriptRunner ( Assembly assemblyWithEmbeddedScript, string fullScriptName, Encoding encoding ) : System
assemblyWithEmbeddedScript System.Reflection.Assembly The assembly with the script as an embedded resource.
fullScriptName string Fully qualified resource name of the script.
encoding System.Text.Encoding The encoding.
return System

SqlScriptRunner() public method

Initializes a new instance of the SqlScriptRunner class.
public SqlScriptRunner ( ScriptCollection scripts ) : System
scripts ScriptCollection The scripts.
return System

SqlScriptRunner() public method

Initializes a new instance of the SqlScriptRunner class.
public SqlScriptRunner ( Stream scriptStream, Encoding encoding ) : System
scriptStream Stream The stream containing the script to execute.
encoding System.Text.Encoding The encoding.
return System

SqlScriptRunner() public method

Initializes a new instance of the SqlScriptRunner class. Initializes the script to execute.
public SqlScriptRunner ( Type scopingType, string scriptName, Encoding encoding ) : System
scopingType System.Type /// A type whose assembly contains the script as an embedded resource. /// Also used to scope the script name. See remarks. ///
scriptName string Name of the script.
encoding System.Text.Encoding The encoding.
return System

SqlScriptRunner() public method

Initializes a new instance of the SqlScriptRunner class.
public SqlScriptRunner ( string scriptText ) : System
scriptText string The full script text to execute.
return System