C# 클래스 Habanero.DB.DatabaseConnection

A super-class to manage a database connection and execute sql commands
상속: System.MarshalByRefObject, IDatabaseConnection
파일 보기 프로젝트 열기: Chillisoft/habanero 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
_sqlFormatter Habanero.Base.SqlFormatter

Private Properties

프로퍼티 타입 설명
AppendOrderBy void
CreateCommand IDbCommand
CreateDataColumns void
CreateDatabaseConnection IDbConnection
ExecuteSqlInternal int

공개 메소드들

메소드 설명
BeginTransaction ( IDbConnection openConnection ) : IDbTransaction

Creates a transaction using the IsolationLevel set as the IsolationLevel. If this doesn't work, creates a transaction using the default IsolationLevel. Uses the connection passed in to create the transaction on - this should be open (so use GetOpenConnectionForReading to get the connection first). Override this method to do special transaction creation logic.

CreateParameterNameGenerator ( ) : IParameterNameGenerator

Creates an IParameterNameGenerator for this database connection. This is used to create names for parameters added to an ISqlStatement because each database uses a different naming convention for their parameters.

CreateSqlStatement ( ) : ISqlStatement

Creates a ISqlStatement initialised with this IDatabaseConnection

ErrorSafeConnectString ( ) : string

Returns a connection string with the password removed. This method serves as a secure way of displaying an error message in the case of a connection error, without compromising confidentiality.

ExecuteRawSql ( string sql ) : int

Executes a sql command as before, but with the full sql string provided, rather than with a sql statement object

ExecuteRawSql ( string sql, IDbTransaction transaction ) : int

Executes a sql command that returns no result set and takes no parameters, using the provided connection. This method can be used effectively where the database vendor supports the execution of several sql statements in one ExecuteNonQuery. However, for database vendors like Microsoft Access and MySql, the sql statements will need to be split up and executed as separate transactions.

ExecuteRawSqlScalar ( string sql ) : object

Executes a raw sql statement. BEWARE OF SQL INJECTION ATTACKS. Use for hardcoded sql only.

ExecuteSql ( IEnumerable statements ) : int

Executes a sql command that returns no result set and takes no parameters, using the provided connection

ExecuteSql ( IEnumerable statements, IDbTransaction transaction ) : int

Executes a collection of sql commands that returns no result set and takes no parameters, using the provided connection. This method can be used effectively where the database vendor supports the execution of several sql statements in one ExecuteNonQuery. However, for database vendors like Microsoft Access and MySql, the sql statements will need to be split up and executed as separate transactions.

ExecuteSql ( ISqlStatement sql ) : int

Executes a single sql statement object

ExecuteStoredProcNonQuery ( string procName, IEnumerable @params ) : int

Executes a stored proc with the params given.

ExecuteStoredProcNonQuery ( string procName, IEnumerable @params, int timeout ) : int

Executes a stored proc with the params given using the timeout length given.

GetConnection ( ) : IDbConnection

Returns the first closed connection available or returns a new connection object. Throws an exception and adds a message to the log if there is an error opening a connection.

GetDataTable ( IDataReader reader ) : DataTable

Returns the DataTable for the DataReader.

GetDataTable ( IDataReader reader, string dataTableName ) : DataTable

Returns a dataTable with the data from the reader and the columns names and field types set up.

GetLastAutoIncrementingID ( string tableName, IDbTransaction tran, IDbCommand command ) : long

Gets the value of the last auto-incrementing number. This called after doing an insert statement so that the inserted auto-number can be retrieved. The table name, current IDbTransaction and IDbCommand are passed in so that they can be used if necessary. Note_, this must be overridden in subclasses to include support for this feature in different databases - otherwise a NotImplementedException will be thrown.

LoadDataReader ( ISqlStatement selectSql ) : IDataReader

Loads a data reader

LoadDataReader ( ISqlStatement selectSql, string strOrderByCriteria ) : IDataReader

Loads a data reader and specifies an order-by clause

LoadDataReader ( string selectSql ) : IDataReader

Loads a data reader with the given raw sql select statement

LoadDataReader ( string selectSql, IDbTransaction transaction ) : IDataReader

Loads a data reader with the given raw sql select statement for the specified transaction

LoadDataTable ( ISqlStatement selectSql, string strSearchCriteria, string strOrderByCriteria ) : DataTable

Loads data from the database into a DataTable object, using the sql statement object provided

SetTimeoutPeriod ( int timeoutSeconds ) : void

Set the time-out period in seconds, after which the connection attempt will fail

보호된 메소드들

메소드 설명
CreateCommand ( IDbConnection dbConnection ) : IDbCommand

Creates an IDbCommand using the provided IDbConnection. Sets the timout for the command based on what you have set using SetTimeoutPeriod

DatabaseConnection ( ) : System

Constructor that initialises a new set of null connections

DatabaseConnection ( string assemblyName, string className ) : System

Constructor that allows an assembly name and class name to be specified

DatabaseConnection ( string assemblyName, string className, string connectString ) : System

Constructor to initialise the connection with the assembly name, class name and connection string provided

DoAfterExecute ( SqlStatement statement, IDbCommand command, IDbTransaction transaction ) : void

Executes the necessary after execute logic for a particular SqlStatement.

GetOpenConnection ( IDbTransaction transaction = null ) : IDbConnection

Returns an open connection. If a IDbTransaction is provided then the connection for the transaction is used and opened if necessary.

GetOpenConnectionForReading ( ) : IDbConnection

Either finds a closed connection and opens and returns it, or creates a new connection and returns that. Throws an exception and adds a message to the log if there is an error opening a connection.

SetupCommand ( ISqlStatement statement, IDbCommand command, IDbTransaction transaction ) : void

Sets up an IDbCommand object with the provided statement.

SetupReadTransaction ( IDbCommand dbCommand ) : void

Setup the transaction on the connection to be used for read operations. This may be overridden for a specific provider (eg. sqlLite)

비공개 메소드들

메소드 설명
AppendOrderBy ( ISqlStatement statement, string orderByCriteria ) : void

Appends an order-by clause to the sql statement. " ORDER BY " is automatically prefixed by this method.

CreateCommand ( IDbConnection connection, IDbTransaction transaction ) : IDbCommand

Creates an IDbCommand using the provided IDbConnection. The created command is subscribed to the provided IDbTransaction.

CreateDataColumns ( IDataRecord reader, DataTable dt ) : void
CreateDatabaseConnection ( ) : IDbConnection

Creates a database connection using the assembly name and class name provided.

ExecuteSqlInternal ( IEnumerable statements, IDbConnection openConnection, IDbTransaction transaction ) : int

메소드 상세

BeginTransaction() 공개 메소드

Creates a transaction using the IsolationLevel set as the IsolationLevel. If this doesn't work, creates a transaction using the default IsolationLevel. Uses the connection passed in to create the transaction on - this should be open (so use GetOpenConnectionForReading to get the connection first). Override this method to do special transaction creation logic.
public BeginTransaction ( IDbConnection openConnection ) : IDbTransaction
openConnection IDbConnection
리턴 IDbTransaction

CreateCommand() 보호된 메소드

Creates an IDbCommand using the provided IDbConnection. Sets the timout for the command based on what you have set using SetTimeoutPeriod
protected CreateCommand ( IDbConnection dbConnection ) : IDbCommand
dbConnection IDbConnection The connection to create the command with
리턴 IDbCommand

CreateParameterNameGenerator() 공개 추상적인 메소드

Creates an IParameterNameGenerator for this database connection. This is used to create names for parameters added to an ISqlStatement because each database uses a different naming convention for their parameters.
public abstract CreateParameterNameGenerator ( ) : IParameterNameGenerator
리턴 IParameterNameGenerator

CreateSqlStatement() 공개 메소드

Creates a ISqlStatement initialised with this IDatabaseConnection
public CreateSqlStatement ( ) : ISqlStatement
리턴 ISqlStatement

DatabaseConnection() 보호된 메소드

Constructor that initialises a new set of null connections
protected DatabaseConnection ( ) : System
리턴 System

DatabaseConnection() 보호된 메소드

Constructor that allows an assembly name and class name to be specified
protected DatabaseConnection ( string assemblyName, string className ) : System
assemblyName string The assembly name
className string The database class name
리턴 System

DatabaseConnection() 보호된 메소드

Constructor to initialise the connection with the assembly name, class name and connection string provided
protected DatabaseConnection ( string assemblyName, string className, string connectString ) : System
assemblyName string The assembly name
className string The class name
connectString string The connection string. This can be /// generated by the various GetConnectionString() methods, tailored /// for the appropriate database vendors.
리턴 System

DoAfterExecute() 보호된 메소드

Executes the necessary after execute logic for a particular SqlStatement.
protected DoAfterExecute ( SqlStatement statement, IDbCommand command, IDbTransaction transaction ) : void
statement SqlStatement The for which the after execute logic must be run.
command IDbCommand The that was used to execute the .
transaction IDbTransaction The under which the 's command was run.
리턴 void

ErrorSafeConnectString() 공개 메소드

Returns a connection string with the password removed. This method serves as a secure way of displaying an error message in the case of a connection error, without compromising confidentiality.
public ErrorSafeConnectString ( ) : string
리턴 string

ExecuteRawSql() 공개 메소드

Executes a sql command as before, but with the full sql string provided, rather than with a sql statement object
public ExecuteRawSql ( string sql ) : int
sql string The sql statement as a string
리턴 int

ExecuteRawSql() 공개 메소드

Executes a sql command that returns no result set and takes no parameters, using the provided connection. This method can be used effectively where the database vendor supports the execution of several sql statements in one ExecuteNonQuery. However, for database vendors like Microsoft Access and MySql, the sql statements will need to be split up and executed as separate transactions.
Thrown if there is an /// error writing to the database. Also outputs error messages to the log. ///
public ExecuteRawSql ( string sql, IDbTransaction transaction ) : int
sql string A valid sql statement (typically "insert", /// "update" or "delete") as a string. Note_ that this assumes that the /// sqlCommand is not a stored procedure.
transaction IDbTransaction A valid transaction object in which the /// sql must be executed, or null
리턴 int

ExecuteRawSqlScalar() 공개 메소드

Executes a raw sql statement. BEWARE OF SQL INJECTION ATTACKS. Use for hardcoded sql only.
public ExecuteRawSqlScalar ( string sql ) : object
sql string The sql statement to run as a scalar
리턴 object

ExecuteSql() 공개 메소드

Executes a sql command that returns no result set and takes no parameters, using the provided connection
public ExecuteSql ( IEnumerable statements ) : int
statements IEnumerable A valid sql statement (typically "insert", /// "update" or "delete"). Note_ that this assumes that the /// sqlCommand is not a stored procedure.
리턴 int

ExecuteSql() 공개 메소드

Executes a collection of sql commands that returns no result set and takes no parameters, using the provided connection. This method can be used effectively where the database vendor supports the execution of several sql statements in one ExecuteNonQuery. However, for database vendors like Microsoft Access and MySql, the sql statements will need to be split up and executed as separate transactions.
Thrown if there is an /// error writing to the database. Also outputs error messages to the log. ///
public ExecuteSql ( IEnumerable statements, IDbTransaction transaction ) : int
statements IEnumerable A valid sql statement object (typically "insert", /// "update" or "delete"). Note_ that this assumes that the /// sqlCommand is not a stored procedure.
transaction IDbTransaction A valid transaction object in which the /// sql must be executed, or null
리턴 int

ExecuteSql() 공개 메소드

Executes a single sql statement object
public ExecuteSql ( ISqlStatement sql ) : int
sql ISqlStatement The sql statement object
리턴 int

ExecuteStoredProcNonQuery() 공개 메소드

Executes a stored proc with the params given.
public ExecuteStoredProcNonQuery ( string procName, IEnumerable @params ) : int
procName string The stored proc name
@params IEnumerable
리턴 int

ExecuteStoredProcNonQuery() 공개 메소드

Executes a stored proc with the params given using the timeout length given.
public ExecuteStoredProcNonQuery ( string procName, IEnumerable @params, int timeout ) : int
procName string The stored proc name
@params IEnumerable
timeout int The timeout in seconds
리턴 int

GetConnection() 공개 메소드

Returns the first closed connection available or returns a new connection object. Throws an exception and adds a message to the log if there is an error opening a connection.
public GetConnection ( ) : IDbConnection
리턴 IDbConnection

GetDataTable() 공개 메소드

Returns the DataTable for the DataReader.
public GetDataTable ( IDataReader reader ) : DataTable
reader IDataReader
리턴 System.Data.DataTable

GetDataTable() 공개 정적인 메소드

Returns a dataTable with the data from the reader and the columns names and field types set up.
public static GetDataTable ( IDataReader reader, string dataTableName ) : DataTable
reader IDataReader the Reader that the dataTable will be made from
dataTableName string the name of the DataTable
리턴 System.Data.DataTable

GetLastAutoIncrementingID() 공개 메소드

Gets the value of the last auto-incrementing number. This called after doing an insert statement so that the inserted auto-number can be retrieved. The table name, current IDbTransaction and IDbCommand are passed in so that they can be used if necessary. Note_, this must be overridden in subclasses to include support for this feature in different databases - otherwise a NotImplementedException will be thrown.
public GetLastAutoIncrementingID ( string tableName, IDbTransaction tran, IDbCommand command ) : long
tableName string The name of the table inserted into
tran IDbTransaction The current transaction, the one the insert was done in
command IDbCommand The Command the did the insert statement
리턴 long

GetOpenConnection() 보호된 메소드

Returns an open connection. If a IDbTransaction is provided then the connection for the transaction is used and opened if necessary.
protected GetOpenConnection ( IDbTransaction transaction = null ) : IDbConnection
transaction IDbTransaction The to use for the connection.
리턴 IDbConnection

GetOpenConnectionForReading() 보호된 메소드

Either finds a closed connection and opens and returns it, or creates a new connection and returns that. Throws an exception and adds a message to the log if there is an error opening a connection.
protected GetOpenConnectionForReading ( ) : IDbConnection
리턴 IDbConnection

LoadDataReader() 공개 메소드

Loads a data reader
Thrown when an error /// occurred while setting up the data reader. Also sends error /// output to the log.
public LoadDataReader ( ISqlStatement selectSql ) : IDataReader
selectSql ISqlStatement The sql statement object
리턴 IDataReader

LoadDataReader() 공개 메소드

Loads a data reader and specifies an order-by clause
public LoadDataReader ( ISqlStatement selectSql, string strOrderByCriteria ) : IDataReader
selectSql ISqlStatement The sql statement object
strOrderByCriteria string A sql order-by clause
리턴 IDataReader

LoadDataReader() 공개 메소드

Loads a data reader with the given raw sql select statement
Thrown when an error /// occurred while setting up the data reader. Also sends error /// output to the log.
public LoadDataReader ( string selectSql ) : IDataReader
selectSql string The sql statement as a string
리턴 IDataReader

LoadDataReader() 공개 메소드

Loads a data reader with the given raw sql select statement for the specified transaction
Thrown when an error /// occurred while setting up the data reader. Also sends error /// output to the log.
public LoadDataReader ( string selectSql, IDbTransaction transaction ) : IDataReader
selectSql string The sql statement as a string
transaction IDbTransaction Thransaction that gives the context within which the sql statement should be executed
리턴 IDataReader

LoadDataTable() 공개 메소드

Loads data from the database into a DataTable object, using the sql statement object provided
Thrown if there is an /// error reading the database. Also outputs error messages to the log. ///
public LoadDataTable ( ISqlStatement selectSql, string strSearchCriteria, string strOrderByCriteria ) : DataTable
selectSql ISqlStatement The sql statement object
strSearchCriteria string The search criteria as a string /// to append
strOrderByCriteria string The order by criteria as a string /// to append
리턴 System.Data.DataTable

SetTimeoutPeriod() 공개 메소드

Set the time-out period in seconds, after which the connection attempt will fail
public SetTimeoutPeriod ( int timeoutSeconds ) : void
timeoutSeconds int The time-out period in seconds
리턴 void

SetupCommand() 보호된 메소드

Sets up an IDbCommand object with the provided statement.
protected SetupCommand ( ISqlStatement statement, IDbCommand command, IDbTransaction transaction ) : void
statement ISqlStatement The to setup the command with.
command IDbCommand The to set up.
transaction IDbTransaction The that the command runs under.
리턴 void

SetupReadTransaction() 보호된 메소드

Setup the transaction on the connection to be used for read operations. This may be overridden for a specific provider (eg. sqlLite)
protected SetupReadTransaction ( IDbCommand dbCommand ) : void
dbCommand IDbCommand The connection to be set up with a transaction
리턴 void

프로퍼티 상세

_sqlFormatter 보호되어 있는 프로퍼티

The SqlFormatter that is used to format the Swl for the database type represented by this database connection
protected SqlFormatter,Habanero.Base _sqlFormatter
리턴 Habanero.Base.SqlFormatter