OpenPetra
Free Administration Software for Non-Profits
Ict.Common.DB.TPostgreSQL Class Reference

Allows access to PostgreSQL databases using the 'Npgsql' .NET Data Provider. More...

Inheritance diagram for Ict.Common.DB.TPostgreSQL:
Ict.Common.DB.IDataBaseRDBMS

Public Member Functions

DbConnection GetConnection (String AServer, String APort, String ADatabaseName, String AUsername, ref String APassword, ref String AConnectionString, StateChangeEventHandler AStateChangeEventHandler)
 Creates a PostgreSQL connection using the 'Npgsql' .NET Data Provider. This works on Windows and on Linux. More...
 
void InitConnection (DbConnection AConnection)
 Initialises the connection after it was opened. Doesn't do anything with PostgreSQL! More...
 
bool LogException (Exception AException, ref string AErrorMessage)
 Formats an error message if the Exception is of Type 'PostgresException'. More...
 
String FormatQueryRDBMSSpecific (String ASqlQuery)
 Formats a SQL query so that it works for PostgreSQL. See also the comments for TDataBase.FormatQueryRDBMSSpecific. More...
 
DbParameter[] ConvertOdbcParameters (DbParameter[] AParameterArray, ref string ASqlStatement)
 Converts an Array of DbParameter (eg. OdbcParameter) to an Array of NpgsqlParameter. If the Parameters don't have a name yet, they are given one because PostgreSQL needs named Parameters. More...
 
DbCommand NewCommand (ref string ACommandText, DbConnection AConnection, DbParameter[] AParametersArray, TDBTransaction ATransaction)
 Creates a DbCommand object. This formats the sql query for PostgreSQL, and transforms the parameters. More...
 
DbDataAdapter NewAdapter ()
 Creates a DbDataAdapter for PostgreSQL. More...
 
void FillAdapter (DbDataAdapter TheAdapter, ref DataSet AFillDataSet, Int32 AStartRecord, Int32 AMaxRecords, string ADataTableName)
 Fills a DbDataAdapter that was created with the NewAdapter Method. More...
 
void FillAdapter (DbDataAdapter TheAdapter, ref DataTable AFillDataTable, Int32 AStartRecord, Int32 AMaxRecords)
 Fills a DbDataAdapter that was created with the NewAdapter Method. More...
 
bool AdjustIsolationLevel (ref IsolationLevel AIsolationLevel)
 Some RDMBS's have some problems with certain Isolation Levels - not so PostgreSQL. More...
 
System.Int64 GetNextSequenceValue (String ASequenceName, TDBTransaction ATransaction, TDataBase ADatabase)
 Returns the next Sequence Value for the given Sequence from the DB. - IMPORTANT: This increasing of the Value of the Sequence PERSISTS in the PostgreSQL implmentation even if the DB Transction gets rolled back!!! --> See https://wiki.openpetra.org/index.php/PostgreSQL:_Sequences_Not_Tied_to_DB_Transactions More...
 
System.Int64 GetCurrentSequenceValue (String ASequenceName, TDBTransaction ATransaction, TDataBase ADatabase)
 Returns the current sequence value for the given Sequence from the DB. More...
 
void RestartSequence (String ASequenceName, TDBTransaction ATransaction, TDataBase ADatabase, Int64 ARestartValue)
 Restart a sequence with the given value. More...
 
void UpdateDatabase (TFileVersionInfo ADBVersion, TFileVersionInfo AExeVersion, string AHostOrFile, string ADatabasePort, string ADatabaseName, string AUsername, string APassword)
 Updating of a Postgresql database has not been implemented yet, need to do this still manually. More...
 
void ClearConnectionPool (DbConnection ADBConnection)
 Clears (empties) the Connection Pool that the Npgsql driver for PostgreSQL provides for all connections that were created using the Connection String that is associated with ADBConnection . More...
 

Static Public Member Functions

static void ClearAllConnectionPools ()
 Clears (empties) all the Connection Pools that the Npgsql driver for PostgreSQL provides (irrespecive of the Connection String that is associated with any connection). More...
 

Detailed Description

Allows access to PostgreSQL databases using the 'Npgsql' .NET Data Provider.

Member Function Documentation

◆ AdjustIsolationLevel()

bool Ict.Common.DB.TPostgreSQL.AdjustIsolationLevel ( ref IsolationLevel  AIsolationLevel)
inline

Some RDMBS's have some problems with certain Isolation Levels - not so PostgreSQL.

Parameters
AIsolationLevelIsolation Level.
Returns
True if Isolation Level was modified.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ ClearAllConnectionPools()

static void Ict.Common.DB.TPostgreSQL.ClearAllConnectionPools ( )
inlinestatic

Clears (empties) all the Connection Pools that the Npgsql driver for PostgreSQL provides (irrespecive of the Connection String that is associated with any connection).

THERE IS NORMALLY NO NEED TO EXECUTE THIS METHOD - IN FACT THIS METHOD SHOULD NOT GET CALLED as it will have a negative performance impact when subsequent DB Connections are opened! Use this Method only for 'unit-testing' DB Connection-related issues (such as that DB Connections are really closed when they ought to be).

◆ ClearConnectionPool()

void Ict.Common.DB.TPostgreSQL.ClearConnectionPool ( DbConnection  ADBConnection)
inline

Clears (empties) the Connection Pool that the Npgsql driver for PostgreSQL provides for all connections that were created using the Connection String that is associated with ADBConnection .

THERE IS NORMALLY NO NEED TO EXECUTE THIS METHOD - IN FACT THIS METHOD SHOULD NOT GET CALLED as it will have a negative performance impact when subsequent DB Connections are opened! Use this Method only for 'unit-testing' DB Connection-related issues (such as that DB Connections are really closed when they ought to be).

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ ConvertOdbcParameters()

DbParameter[] Ict.Common.DB.TPostgreSQL.ConvertOdbcParameters ( DbParameter[]  AParameterArray,
ref string  ASqlStatement 
)
inline

Converts an Array of DbParameter (eg. OdbcParameter) to an Array of NpgsqlParameter. If the Parameters don't have a name yet, they are given one because PostgreSQL needs named Parameters.

Furthermore, the parameter placeholders '?' in the the passed in ASqlStatement are replaced with PostgreSQL ':paramX' placeholders (where 'paramX' is the name of the Parameter).

Parameters
AParameterArrayArray of DbParameter that is to be converted.
ASqlStatementSQL Statement. It will be converted!
Returns
Array of NpgsqlParameter (converted from AParameterArray .

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ FillAdapter() [1/2]

void Ict.Common.DB.TPostgreSQL.FillAdapter ( DbDataAdapter  TheAdapter,
ref DataSet  AFillDataSet,
Int32  AStartRecord,
Int32  AMaxRecords,
string  ADataTableName 
)
inline

Fills a DbDataAdapter that was created with the NewAdapter Method.

Parameters
TheAdapter
AFillDataSet
AStartRecord
AMaxRecords
ADataTableName

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ FillAdapter() [2/2]

void Ict.Common.DB.TPostgreSQL.FillAdapter ( DbDataAdapter  TheAdapter,
ref DataTable  AFillDataTable,
Int32  AStartRecord,
Int32  AMaxRecords 
)
inline

Fills a DbDataAdapter that was created with the NewAdapter Method.

Overload of FillAdapter, just for one table.

Parameters
TheAdapter
AFillDataTable
AStartRecord
AMaxRecords

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ FormatQueryRDBMSSpecific()

String Ict.Common.DB.TPostgreSQL.FormatQueryRDBMSSpecific ( String  ASqlQuery)
inline

Formats a SQL query so that it works for PostgreSQL. See also the comments for TDataBase.FormatQueryRDBMSSpecific.

Parameters
ASqlQuerySQL Query.
Returns
Formatted SQL Query.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ GetConnection()

DbConnection Ict.Common.DB.TPostgreSQL.GetConnection ( String  AServer,
String  APort,
String  ADatabaseName,
String  AUsername,
ref String  APassword,
ref String  AConnectionString,
StateChangeEventHandler  AStateChangeEventHandler 
)
inline

Creates a PostgreSQL connection using the 'Npgsql' .NET Data Provider. This works on Windows and on Linux.

Parameters
AServerDatabase Server.
APortPort that the DB server is running on.
ADatabaseNameName of the database that we want to connect to.
AUsernameUsername for opening the PostgreSQL connection.
APasswordPassword for opening the PostgreSQL connection.
AConnectionStringConnection string; if it is not empty, it will overrule the previous parameters.
AStateChangeEventHandlerEvent Handler for connection state changes (NOTE: This doesn't work yet with the Npgsql driver - see code comments in this Methods' source code)!
Returns
Instantiated NpgsqlConnection, but not opened yet (null if connection could not be established).

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ GetCurrentSequenceValue()

System.Int64 Ict.Common.DB.TPostgreSQL.GetCurrentSequenceValue ( String  ASequenceName,
TDBTransaction  ATransaction,
TDataBase  ADatabase 
)
inline

Returns the current sequence value for the given Sequence from the DB.

Parameters
ASequenceNameName of the Sequence.
ATransactionAn instantiated Transaction in which the Query to the DB will be enlisted.
ADatabaseDatabase object that can be used for querying.
Returns
Sequence Value.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ GetNextSequenceValue()

System.Int64 Ict.Common.DB.TPostgreSQL.GetNextSequenceValue ( String  ASequenceName,
TDBTransaction  ATransaction,
TDataBase  ADatabase 
)
inline

Returns the next Sequence Value for the given Sequence from the DB. - IMPORTANT: This increasing of the Value of the Sequence PERSISTS in the PostgreSQL implmentation even if the DB Transction gets rolled back!!! --> See https://wiki.openpetra.org/index.php/PostgreSQL:_Sequences_Not_Tied_to_DB_Transactions

Parameters
ASequenceNameName of the Sequence.
ATransactionAn instantiated Transaction in which the Query to the DB will be enlisted.
ADatabaseDatabase object that can be used for querying.
Returns
Sequence Value.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ InitConnection()

void Ict.Common.DB.TPostgreSQL.InitConnection ( DbConnection  AConnection)
inline

Initialises the connection after it was opened. Doesn't do anything with PostgreSQL!

Parameters
AConnectionDB Connection.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ LogException()

bool Ict.Common.DB.TPostgreSQL.LogException ( Exception  AException,
ref string  AErrorMessage 
)
inline

Formats an error message if the Exception is of Type 'PostgresException'.

Parameters
AException
AErrorMessage
Returns
True if this is an NpgsqlException.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ NewAdapter()

DbDataAdapter Ict.Common.DB.TPostgreSQL.NewAdapter ( )
inline

Creates a DbDataAdapter for PostgreSQL.

Important: Since an object that derives from DbDataAdapter is returned you ought to call .Dispose() on the returned object to release its resouces! (DbDataAdapter inherits from DataAdapter which itself inherits from Component, which implements IDisposable!)

Returns
Instantiated NpgsqlDataAdapter.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ NewCommand()

DbCommand Ict.Common.DB.TPostgreSQL.NewCommand ( ref string  ACommandText,
DbConnection  AConnection,
DbParameter[]  AParametersArray,
TDBTransaction  ATransaction 
)
inline

Creates a DbCommand object. This formats the sql query for PostgreSQL, and transforms the parameters.

Parameters
ACommandText
AConnection
AParametersArray
ATransaction
Returns
Instantiated NpgsqlCommand.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ RestartSequence()

void Ict.Common.DB.TPostgreSQL.RestartSequence ( String  ASequenceName,
TDBTransaction  ATransaction,
TDataBase  ADatabase,
Int64  ARestartValue 
)
inline

Restart a sequence with the given value.

Implements Ict.Common.DB.IDataBaseRDBMS.

◆ UpdateDatabase()

void Ict.Common.DB.TPostgreSQL.UpdateDatabase ( TFileVersionInfo  ADBVersion,
TFileVersionInfo  AExeVersion,
string  AHostOrFile,
string  ADatabasePort,
string  ADatabaseName,
string  AUsername,
string  APassword 
)
inline

Updating of a Postgresql database has not been implemented yet, need to do this still manually.


The documentation for this class was generated from the following file: