C# Class DataAccessFramework.DataTool

An abstract class providing helper functionality to connect to a database.

This class provides functions that can simplfy common database access functionality, e.g. executing a stored procedure.

The tool itself is not tied to any specific database provider. Using this tool to execute database operations separates the application from the actual database server software.

The client code should also use functions in this class to create parameters to pass to the stored procedure. That will ensure that the parameters are compatible with the database provider.

Inheritance: IDisposable
Afficher le fichier Open project: PeteProgrammer/DataAccessFramework

Méthodes publiques

Méthode Description
BeginTransaction ( ) : void

Starts a new transaction. Specialized classes should override this function and implement custom transaction handling

CommitTransaction ( ) : void

Commits the transaction. Specialized classes should override this function and implement custom transaction handling

CreateBinaryParameter ( string parameterName, Stream dataStream ) : IDataParameter
CreateBinaryParameter ( string parameterName, byte value, int length ) : IDataParameter

Creates database parameter for a binary value.

The implementation will check if the length of the string is actually within the acceptable length. If not, a BinaryParameterTooLongException is thrown.

CreateBoolParameter ( string parameterName, bool value ) : IDataParameter

Creates a database parameter for a Boolean value.

CreateDateTimeParameter ( string parameterName, System.DateTime value ) : IDataParameter

Creates a database parameter for a datetime value

CreateDecimalParameter ( string parameterName, decimal value ) : IDataParameter

Creates database parameter for a decimal value.

CreateGuidParameter ( string parameterName, System.Guid value ) : IDataParameter

Creates database parameter for a GUID value.

CreateIntParameter ( string parameterName, int value ) : IDataParameter

Creates database parameter for an integer value.

CreateLongParameter ( string parameterName, long value ) : IDataParameter

Creates database parameter for an 64 bit integer value.

CreateMoneyParameter ( string parameterName, decimal value ) : IDataParameter

Creates a database parameter for a decimal value used for carrying monetary amount.

CreateStampParameter ( string parameterName, object stamp ) : IDataParameter

Creates a database parameter for a stamp value.

CreateStringParameter ( string parameterName, string value, int length ) : IDataParameter

Creates database parameter for a string value.

The implementation will check if the length of the string is actually within the acceptable length. If not, a StringParameterTooLongException is thrown.

Dispose ( ) : void

Disposes the current instance.

ExecuteNonQuery ( string spName ) : int

Executes a stored procedure that does not return a result.

ExecuteQuery ( Query query ) : IDataReader

Executes a query represendted by a Query instance

ExecuteReader ( string spName ) : IDataReader

Executes a stored procedure that returns a single result set.

ExecuteReaderSingleRow ( string spName ) : IDataReader

Executes a stored procedure that returns a multiple result sets.

Executes a stored procedure that returns a single row.

ExecuteScalar ( string spName ) : object

Executes a stored procedure that returns a single value.

ExecuteSqlNonQuery ( string sql ) : int

Executes an sql statement that does not return a result.

ExecuteSqlReader ( string sql ) : IDataReader

Executes an SQL statement that returns an IDataReader

ExecuteSqlReaderSingleRow ( string sql ) : IDataReader

Executes an SQL statement that returns a single row.

ExecuteSqlScalar ( string sql ) : object

Executes an SQL text statement that returns a single value.

RollbackTransaction ( ) : void

Rolls back the transaction. Specialized classes should override this function and implement custom transaction handling

Méthodes protégées

Méthode Description
AssertNotDisposed ( ) : void

Verifies that the object has not been disposed.

CreateCommand ( ) : IDbCommand

Template function for creating a command object.

The DataTool class will call this internally when executing a query

Dispose ( bool disposing ) : void

Template function for disposing resources.

GetConnection ( ) : IDbConnection

Template function for getting a connection object.

The DataTool class will call this internally when executing a query

GetTransaction ( ) : IDbTransaction

Template function for getting a transaction

The DataTool class will call this internally when executing a query

Private Methods

Méthode Description
ExecuteNonQuery ( string commandText, CommandType commandType ) : int
ExecuteReader ( string sql, CommandType commandType, CommandBehavior behavior ) : IDataReader
ExecuteScalar ( string commandText, CommandType commandType ) : object

Method Details

AssertNotDisposed() protected méthode

Verifies that the object has not been disposed.
/// The object has been disposed. ///
protected AssertNotDisposed ( ) : void
Résultat void

BeginTransaction() public abstract méthode

Starts a new transaction. Specialized classes should override this function and implement custom transaction handling
public abstract BeginTransaction ( ) : void
Résultat void

CommitTransaction() public abstract méthode

Commits the transaction. Specialized classes should override this function and implement custom transaction handling
public abstract CommitTransaction ( ) : void
Résultat void

CreateBinaryParameter() public méthode

public CreateBinaryParameter ( string parameterName, Stream dataStream ) : IDataParameter
parameterName string
dataStream Stream
Résultat IDataParameter

CreateBinaryParameter() public abstract méthode

Creates database parameter for a binary value.
The implementation will check if the length of the string is actually within the acceptable length. If not, a BinaryParameterTooLongException is thrown.
/// The size of value exceeds that specified by /// length ///
public abstract CreateBinaryParameter ( string parameterName, byte value, int length ) : IDataParameter
parameterName string /// The name of the parameter. ///
value byte /// The value of the parameter ///
length int /// The length of the parameter as it is specified by the stored procedure. ///
Résultat IDataParameter

CreateBoolParameter() public abstract méthode

Creates a database parameter for a Boolean value.
public abstract CreateBoolParameter ( string parameterName, bool value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value bool /// The value of the parameter ///
Résultat IDataParameter

CreateCommand() protected abstract méthode

Template function for creating a command object.
The DataTool class will call this internally when executing a query
protected abstract CreateCommand ( ) : IDbCommand
Résultat IDbCommand

CreateDateTimeParameter() public abstract méthode

Creates a database parameter for a datetime value
public abstract CreateDateTimeParameter ( string parameterName, System.DateTime value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value System.DateTime /// The value of the parameter ///
Résultat IDataParameter

CreateDecimalParameter() public abstract méthode

Creates database parameter for a decimal value.
public abstract CreateDecimalParameter ( string parameterName, decimal value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value decimal /// The value of the parameter ///
Résultat IDataParameter

CreateGuidParameter() public abstract méthode

Creates database parameter for a GUID value.
public abstract CreateGuidParameter ( string parameterName, System.Guid value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value System.Guid /// The value of the parameter ///
Résultat IDataParameter

CreateIntParameter() public abstract méthode

Creates database parameter for an integer value.
public abstract CreateIntParameter ( string parameterName, int value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value int /// The value of the parameter ///
Résultat IDataParameter

CreateLongParameter() public abstract méthode

Creates database parameter for an 64 bit integer value.
public abstract CreateLongParameter ( string parameterName, long value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value long /// The value of the parameter ///
Résultat IDataParameter

CreateMoneyParameter() public abstract méthode

Creates a database parameter for a decimal value used for carrying monetary amount.
public abstract CreateMoneyParameter ( string parameterName, decimal value ) : IDataParameter
parameterName string /// The name of the parameter. ///
value decimal /// The value of the parameter ///
Résultat IDataParameter

CreateStampParameter() public abstract méthode

Creates a database parameter for a stamp value.
public abstract CreateStampParameter ( string parameterName, object stamp ) : IDataParameter
parameterName string /// The name of the parameter. ///
stamp object /// The value of the parameter ///
Résultat IDataParameter

CreateStringParameter() public abstract méthode

Creates database parameter for a string value.
The implementation will check if the length of the string is actually within the acceptable length. If not, a StringParameterTooLongException is thrown.
/// The length of value exceeds that specified by /// length ///
public abstract CreateStringParameter ( string parameterName, string value, int length ) : IDataParameter
parameterName string /// The name of the parameter. ///
value string /// The value of the parameter ///
length int /// The length of the parameter as it is specified by the stored procedure. ///
Résultat IDataParameter

Dispose() public méthode

Disposes the current instance.
public Dispose ( ) : void
Résultat void

Dispose() protected méthode

Template function for disposing resources.
protected Dispose ( bool disposing ) : void
disposing bool /// Boolean value indicating if we are calling from dispose or the finalizer. /// true indicates we are calling from Dispose; false indicates /// we are calling from the finalizer. ///
Résultat void

ExecuteNonQuery() public méthode

Executes a stored procedure that does not return a result.
public ExecuteNonQuery ( string spName ) : int
spName string /// Name of the stored procedure to execute. ///
Résultat int

ExecuteQuery() public méthode

Executes a query represendted by a Query instance
public ExecuteQuery ( Query query ) : IDataReader
query DataAccessFramework.Querying.Query
Résultat IDataReader

ExecuteReader() public méthode

Executes a stored procedure that returns a single result set.
public ExecuteReader ( string spName ) : IDataReader
spName string /// Name of the stored procedure to execute. ///
Résultat IDataReader

ExecuteReaderSingleRow() public méthode

Executes a stored procedure that returns a multiple result sets. Executes a stored procedure that returns a single row.
public ExecuteReaderSingleRow ( string spName ) : IDataReader
spName string ///// Name of the stored procedure to execute. /////
Résultat IDataReader

ExecuteScalar() public méthode

Executes a stored procedure that returns a single value.
public ExecuteScalar ( string spName ) : object
spName string /// Name of the stored procedure to execute. ///
Résultat object

ExecuteSqlNonQuery() public méthode

Executes an sql statement that does not return a result.
public ExecuteSqlNonQuery ( string sql ) : int
sql string /// The SQL statement to execute ///
Résultat int

ExecuteSqlReader() public méthode

Executes an SQL statement that returns an IDataReader
public ExecuteSqlReader ( string sql ) : IDataReader
sql string
Résultat IDataReader

ExecuteSqlReaderSingleRow() public méthode

Executes an SQL statement that returns a single row.
public ExecuteSqlReaderSingleRow ( string sql ) : IDataReader
sql string
Résultat IDataReader

ExecuteSqlScalar() public méthode

Executes an SQL text statement that returns a single value.
public ExecuteSqlScalar ( string sql ) : object
sql string
Résultat object

GetConnection() protected abstract méthode

Template function for getting a connection object.
The DataTool class will call this internally when executing a query
protected abstract GetConnection ( ) : IDbConnection
Résultat IDbConnection

GetTransaction() protected abstract méthode

Template function for getting a transaction
The DataTool class will call this internally when executing a query
protected abstract GetTransaction ( ) : IDbTransaction
Résultat IDbTransaction

RollbackTransaction() public abstract méthode

Rolls back the transaction. Specialized classes should override this function and implement custom transaction handling
public abstract RollbackTransaction ( ) : void
Résultat void