PSqlDatabase Class Reference

Detailed Description

The PSqlDatabase class represents a connection to a SQL database (typically SQLite3 or PostgreSQL).

This class is intended to be used with PSqlQuery.

Definition at line 29 of file PSqlDatabase.h.

#include <PSqlDatabase.h>

Member Enumeration Documentation

◆ EDatabase

All the supported databases.

Enumerator
E_NONE 

Not yet chosen.

E_PSQL 

Postgre SQL (versions 7.3 or above)

E_SQLITE3 

SQLite 3.

Definition at line 35 of file PSqlDatabase.h.

Constructor & Destructor Documentation

◆ PSqlDatabase() [1/2]

PSqlDatabase::PSqlDatabase ( EDatabase  databaseType = E_SQLITE3)

Creates an empty, invalid PSqlDatabase object which represents a connection to a database.

Use Open() to provide credentials, name and other infos required to open your database.

If databaseType is not available, then IsValid() will return false;

◆ PSqlDatabase() [2/2]

PSqlDatabase::PSqlDatabase ( const PSqlDatabase other)

Constructs a shared copy of other.

◆ ~PSqlDatabase()

virtual PSqlDatabase::~PSqlDatabase ( )
virtual

Destroys this object.

Member Function Documentation

◆ Close()

void PSqlDatabase::Close ( )

Closes the database connection, freeing any resources acquired, and invalidating any existing PSqlQuery objects that are used with the database.

◆ Commit()

PResult PSqlDatabase::Commit ( )

Commits a transaction to the database if the driver supports transactions and a Transaction() has been started.

Returns PResult::C_OK if success, another result otherwise.

See also
Transaction()

◆ GetDriverName()

PString PSqlDatabase::GetDriverName ( ) const

Returns the connection's driver name.

◆ GetDrivers()

static PStringList PSqlDatabase::GetDrivers ( )
static

Returns a list of all the available database drivers.

◆ IsOpened()

bool PSqlDatabase::IsOpened ( ) const

Returns true if the database connection is valid and currently open; otherwise returns false.

◆ IsValid()

bool PSqlDatabase::IsValid ( ) const

Returns true if the database connection is valid (i.e.

there is a valid SQL driver).

◆ ListTables()

PStringList PSqlDatabase::ListTables ( ) const

Returns the list of tables in the database.

◆ Open() [1/3]

PResult PSqlDatabase::Open ( const PString dbHost,
papillon::int32  dbPort,
const PString username,
const PString password 
)

Opens the database connection without a database name (can be use to create a database).

Returns PResult::C_OK if success, another result otherwise.

◆ Open() [2/3]

PResult PSqlDatabase::Open ( const PString dbHost,
papillon::int32  dbPort,
const PString dbName,
const PString username,
const PString password 
)

Opens the database connection and the specified database.

Returns PResult::C_OK if success, another result otherwise.

◆ Open() [3/3]

PResult PSqlDatabase::Open ( )

Opens the database connection using the current connection values.

Returns PResult::C_OK if success, another result otherwise.

See also
SetHostName()
SetPort()
SetDatabaseName()
SetUserName()
SetPassword()

◆ operator=()

PSqlDatabase& PSqlDatabase::operator= ( const PSqlDatabase other)

Performs a shared copy of other to this object.

◆ Rollback()

PResult PSqlDatabase::Rollback ( )

Rolls back a transaction on the database, if the driver supports transactions and a Transaction() has been started.

Returns PResult::C_OK if success, another result otherwise.

See also
Transaction()

◆ SetConnectOptions()

void PSqlDatabase::SetConnectOptions ( const PString options)

Sets database-specific options.

This must be done before the connection is opened or it has no effect (or you can close() the connection, call this function and Open() the connection again).

The format of the options string is a semicolon separated list of option names or option=value pairs. The options depend on the database client used.

◆ SetDatabaseName()

void PSqlDatabase::SetDatabaseName ( const PString dbName)

Sets the connection's database name.

◆ SetHostName()

void PSqlDatabase::SetHostName ( const PString dbHost)

Sets the connection's host name.

◆ SetPassword()

void PSqlDatabase::SetPassword ( const PString password)

Sets the connection's password.

◆ SetPort()

void PSqlDatabase::SetPort ( papillon::int32  dbPort)

Sets the connection's port number.

◆ SetUserName()

void PSqlDatabase::SetUserName ( const PString username)

Sets the connection's user name.

◆ Transaction()

PResult PSqlDatabase::Transaction ( )

Begins a transaction on the database if the driver supports transactions.

Returns PResult::C_OK if success, another result otherwise.

See also
Commit()
Rollback()

Friends And Related Function Documentation

◆ PSqlQueryImpl

friend class PSqlQueryImpl
friend

Definition at line 189 of file PSqlDatabase.h.