PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PODBC Class Reference

ODBC Support for PWLIB. More...

#include <podbc.h>

Inheritance diagram for PODBC:
Collaboration diagram for PODBC:

Classes

struct  ConnectData
 
This class is a multipurpose use

class for storing parameters when initiating connection to DataSource. More...

 
class  Field
 Class for Field Data. More...
 
class  RecordSet
 
PODBC::RecordSet

This is the main Class to access Data returned by a Select Query. More...

 
class  Row
 Database Row Class This class functions as a simple wrapper of the Statement class to fetch/Save data to the Datasource. More...
 

Public Types

enum  { UndefinedRowIndex = 0 }
 
typedef unsigned RowIndex
 Type for row index, may become 64 bit one day. More...
 
typedef RecordSet Table
 
- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 

Public Member Functions

bool DataSource (DriverType driver, ConnectData Data)
 
Constructor/Destructor
 PODBC ()
 Constructs ODBC connection. More...
 
 ~PODBC ()
 Destroys ODBC connection. More...
 
Connection/Disconnect
bool Connect (const PString &source, const PString &username, const PString &password)
 
Connect to the MDAC using a pre-existing MDAC Defined DataSource

This is different than calling PODBC::DataSource in that the Data Source is known defined externally within MDAC, More...

 
bool Connect_DB2 (const PFilePath &dbPath)
 Connect to IBM DB2 DataSource. More...
 
bool Connect_XLS (const PFilePath &xlsPath, const PString &defDir=PString::Empty())
 Connect to MS Office excel spreadsheet. More...
 
bool Connect_TXT (const PFilePath &txtPath)
 Connect to an ascii text or cvs file. More...
 
bool Connect_FOX (const PFilePath &dbPath, const PString &user=PString::Empty(), const PString &pass=PString::Empty(), const PString &type="DBF", bool exclusive=false)
 Connect to a Foxpro dataSource. More...
 
bool Connect_MDB (const PFilePath &mdbPath, const PString &user=PString::Empty(), const PString &pass=PString::Empty(), bool exclusive=false)
 Connect to a MS Access *.mdb DataSource. More...
 
bool Connect_PDOX (const PDirectory &dbPath, const PDirectory &defaultDir, int version=5)
 Connect to a paradox database datastore. More...
 
bool Connect_Oracle (const PString &server, const PString &user=PString::Empty(), const PString &pass=PString::Empty())
 Connect to an Oracle Datasource. More...
 
bool Connect_DBASE (const PDirectory &dbPath)
 Connect to a DBase DataStore. More...
 
bool Connect_MSSQL (const PString &user=PString::Empty(), const PString &pass=PString::Empty(), const PString &host="(local)", bool trusted=true, MSSQLProtocols Proto=MSSQLNamedPipes)
 Connect to a MS SQL Server. More...
 
bool Connect_mySQL (const PString &user=PString::Empty(), const PString &pass=PString::Empty(), const PString &host="localhost", int port=3306)
 Connect to a mySQL Server. More...
 
bool ConnectDB_mySQL (const PString &db, const PString &user=PString::Empty(), const PString &pass=PString::Empty(), const PString &host="localhost", int port=3306)
 Connect to a mySQL Server's specified DataBase. More...
 
bool Connect_postgreSQL (const PString &db, const PString &user, const PString &pass, const PString &host, int port=5432)
 Connect to a postgreSQL Server. More...
 
bool IsConnected () const
 Return true if connected. More...
 
virtual void OnConnected ()
 Call back on successful connection. More...
 
void Disconnect ()
 General Disconnect from DataSource. More...
 
PStringList GetDrivers (bool withAttributes=true) const
 Get a list of driver descriptions and attributes. More...
 
PStringList GetSources (bool system=false, bool withDescription=true) const
 Get a list of known data sources and their descriptions The returned strings when withDescription true are of the form name. More...
 
SQL
PStringArray TableList (const PString &options=PString::Empty())
 
Retrieve a List of Tables in the Datasource

use the option field to specify the type of data to access. More...

 
bool Execute (const PString &sql)
 Added Information to the DataSource. More...
 
__inline bool Query (const PString &sql)
 
- Public Member Functions inherited from PObject
unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
void SetTraceContextIdentifier (unsigned id)
 
void GetTraceContextIdentifier (PObject &obj)
 
void GetTraceContextIdentifier (PObject *obj)
 
void SetTraceContextIdentifier (const PObject &obj)
 
void SetTraceContextIdentifier (const PObject *obj)
 
virtual ~PObject ()
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. More...
 
__inline const PObjectPTraceObjectInstance () const
 
virtual Comparison Compare (const PObject &obj) const
 Compare the two objects and return their relative rank. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Protected Member Functions

 P_REMOVE_VIRTUAL_VOID (OnSQLError(const PString &, const PString &))
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

Link * m_link
 
int m_lastError
 
PString m_lastErrorText
 
unsigned m_precision
 
PTime::TimeFormat m_timeFormat
 Double Real Float Decimal digit rounding def= 4;. More...
 
PTime::TimeFormat m_dateFormat
 
PTime::TimeFormat m_dateTimeFormat
 
bool m_needChunking
 
PINDEX m_maxChunkSize
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

DataSource Access

enum  MSSQLProtocols {
  MSSQLNamedPipes, MSSQLWinSock, MSSQLIPX, MSSQLBanyan,
  MSSQLRPC
}
 MSSQL protocols.If your interested? More...
 
std::ostream & operator<< (std::ostream &strm, DriverType type)
 
 P_DECLARE_ENUM (DriverType, DSN, mySQL, postgreSQL, Oracle, IBM_DB2, MSSQL, MSAccess, Paradox, Foxpro, dBase, Excel, Ascii, ConnectionString)
 Driver types that are supported by this implementation. More...
 
bool Connect (const ConnectData &connectInfo)
 Connect to database using ConnectData This is the main function to call to contact a DataSource. More...
 
bool Connect (const PString &source)
 
General Connect Function

Custom connection strings should call this to connect. More...

 
static const char * GetDriverName (DriverType type)
 

Utilities

void SetPrecision (unsigned precision)
 
Set the Number of Decimal places to

round to By Default it is 4. More...

 
unsigned GetPrecision () const
 
PTime::TimeFormat GetTimeFormat () const
 
void SetTimeFormat (PTime::TimeFormat fmt)
 
PTime::TimeFormat GetDateFormat () const
 
void SetDateFormat (PTime::TimeFormat fmt)
 
PTime::TimeFormat GetDateTimeFormat () const
 
void SetDateTimeFormat (PTime::TimeFormat fmt)
 
PINDEX GetMaxChunkSize () const
 Maximum size of an individual chunk of data. More...
 
int GetLastError () const
 Get last error. More...
 
PString GetLastErrorText () const
 Get last error text. More...
 
virtual void OnSQLError (int native, const PString &code, const PString &message)
 OnSQL Error. More...
 
static PString GetFieldType (DriverType driver, PVarType::BasicType type, unsigned size=0)
 Get valid field type for PVarType enumeration. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from PObject
static const char * Class ()
 Get the name of the class as a C string. More...
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
- Friends inherited from PObject

Detailed Description

ODBC Support for PWLIB.

Class Description PODBC : Main DataBase connection class (Can derive class for error handling) PODBC::ConnectData : Class used to store information for Connecting to DataSource PODBC::RecordSet : Retrieved Data from Table or Select SQL Query PODBC::Row : Record wrapper class for the PODBC::RecordSet (PArray of Fields) PODBC::Field : Database field information (Field structure & bound data) PODBC::Statement : Wrapper for ODBC "statement" (Internal)

Example of Use


  PODBC link;
  PODBC::ConnectData connectInfo;
  connectInfo.Source = PODBC::MSAccess;
  connectInfo.DBPath = "test.mdb";
  connectInfo ....
  if (link.Connect(connectInfo)) {
Load a Database Table (could also be a SELECT Query)
    PODBC::RecordSet table(link, "FooTable");
Bind to Column 1
    PODBC::Field & field = table.Column(1):
Display Contents
    cout << " Value " << field.AsString(); << endl;
Move to Record 2 of fooTable
    table[2];
Display contents of Record 2 Column 1
    cout << " Value " << field.AsString(); << endl;
Set New Value for Record 2 Field 1 of FooTable
    field.SetValue("NewValue");
Send Update to Database.
    field.Commit();
To Add New Record.(with Default Values)
    table.NewRow();
Alter the Value of field 1
    field.SetValue("Something");
Post the New Field to the Database
    field.Commit();
Run General Query;
    link.Query("INSERT foo into [FooTable] ...");
  }
Disconnect from ODBC Source
  link.Disconnect();

PODBC Class The Main ODBC class. This Class should be used in the there is not a preconfigured DSN setup in the MDAC. This class will use the applicable ODBC drivers to connect to a compliant Datasource. It Supports a wide variety of Datasources but others can added by simply creating your custom connection string and then calling PODBC::Connect. For Defined sources the PODBC::DataSource function should be used.

Member Typedef Documentation

typedef unsigned PODBC::RowIndex

Type for row index, may become 64 bit one day.

Member Enumeration Documentation

anonymous enum
Enumerator
UndefinedRowIndex 

MSSQL protocols.If your interested?

Enumerator
MSSQLNamedPipes 
MSSQLWinSock 
MSSQLIPX 
MSSQLBanyan 
MSSQLRPC 

Constructor & Destructor Documentation

PODBC::PODBC ( )

Constructs ODBC connection.

PODBC::~PODBC ( )

Destroys ODBC connection.

Member Function Documentation

bool PODBC::Connect ( const ConnectData connectInfo)

Connect to database using ConnectData This is the main function to call to contact a DataSource.

Source specifies the Type of DataSource to contact and the Data parameter contain the relevent connection information. You can choose to call this function or use the specific Connection function.

bool PODBC::Connect ( const PString source)

General Connect Function

Custom connection strings should call this to connect.

bool PODBC::Connect ( const PString source,
const PString username,
const PString password 
)

Connect to the MDAC using a pre-existing MDAC Defined DataSource

This is different than calling PODBC::DataSource in that the Data Source is known defined externally within MDAC,

bool PODBC::Connect_DB2 ( const PFilePath dbPath)

Connect to IBM DB2 DataSource.

bool PODBC::Connect_DBASE ( const PDirectory dbPath)

Connect to a DBase DataStore.

bool PODBC::Connect_FOX ( const PFilePath dbPath,
const PString user = PString::Empty(),
const PString pass = PString::Empty(),
const PString type = "DBF",
bool  exclusive = false 
)

Connect to a Foxpro dataSource.

bool PODBC::Connect_MDB ( const PFilePath mdbPath,
const PString user = PString::Empty(),
const PString pass = PString::Empty(),
bool  exclusive = false 
)

Connect to a MS Access *.mdb DataSource.

bool PODBC::Connect_MSSQL ( const PString user = PString::Empty(),
const PString pass = PString::Empty(),
const PString host = "(local)",
bool  trusted = true,
MSSQLProtocols  Proto = MSSQLNamedPipes 
)

Connect to a MS SQL Server.

bool PODBC::Connect_mySQL ( const PString user = PString::Empty(),
const PString pass = PString::Empty(),
const PString host = "localhost",
int  port = 3306 
)

Connect to a mySQL Server.

bool PODBC::Connect_Oracle ( const PString server,
const PString user = PString::Empty(),
const PString pass = PString::Empty() 
)

Connect to an Oracle Datasource.

bool PODBC::Connect_PDOX ( const PDirectory dbPath,
const PDirectory defaultDir,
int  version = 5 
)

Connect to a paradox database datastore.

bool PODBC::Connect_postgreSQL ( const PString db,
const PString user,
const PString pass,
const PString host,
int  port = 5432 
)

Connect to a postgreSQL Server.

bool PODBC::Connect_TXT ( const PFilePath txtPath)

Connect to an ascii text or cvs file.

bool PODBC::Connect_XLS ( const PFilePath xlsPath,
const PString defDir = PString::Empty() 
)

Connect to MS Office excel spreadsheet.

bool PODBC::ConnectDB_mySQL ( const PString db,
const PString user = PString::Empty(),
const PString pass = PString::Empty(),
const PString host = "localhost",
int  port = 3306 
)

Connect to a mySQL Server's specified DataBase.

bool PODBC::DataSource ( DriverType  driver,
ConnectData  Data 
)
void PODBC::Disconnect ( )

General Disconnect from DataSource.

bool PODBC::Execute ( const PString sql)

Added Information to the DataSource.

Use this function if you just want to use a SQL statement to add data to a datasource without retreiving the data itself. ie "UPDATE" "APPEND" "INSERT" queries.

Referenced by Query().

PTime::TimeFormat PODBC::GetDateFormat ( ) const
inline

References m_dateFormat.

PTime::TimeFormat PODBC::GetDateTimeFormat ( ) const
inline

References m_dateTimeFormat.

static const char* PODBC::GetDriverName ( DriverType  type)
static
PStringList PODBC::GetDrivers ( bool  withAttributes = true) const

Get a list of driver descriptions and attributes.

The returned strings whenwithAttribute true are of the form name=val=val etc

static PString PODBC::GetFieldType ( DriverType  driver,
PVarType::BasicType  type,
unsigned  size = 0 
)
static

Get valid field type for PVarType enumeration.

This will get the database specific field name for the driver type.

int PODBC::GetLastError ( ) const
inline

Get last error.

References m_lastError.

PString PODBC::GetLastErrorText ( ) const
inline

Get last error text.

References m_lastErrorText.

PINDEX PODBC::GetMaxChunkSize ( ) const
inline

Maximum size of an individual chunk of data.

This is the maximum size for a field to be transferred in one go. Checks if database can do large transfers via the SQL_NEED_LONG_DATA_LEN info item. If needed then is set to 32k otherwise is P_MAX_INDEX

References m_maxChunkSize, and m_needChunking.

unsigned PODBC::GetPrecision ( ) const
inline

References m_precision.

PStringList PODBC::GetSources ( bool  system = false,
bool  withDescription = true 
) const

Get a list of known data sources and their descriptions The returned strings when withDescription true are of the form name.

PTime::TimeFormat PODBC::GetTimeFormat ( ) const
inline

References m_timeFormat.

bool PODBC::IsConnected ( ) const

Return true if connected.

virtual void PODBC::OnConnected ( )
virtual

Call back on successful connection.

virtual void PODBC::OnSQLError ( int  native,
const PString code,
const PString message 
)
virtual

OnSQL Error.

Parameters
nativeNative error code
code5 character SQLSTATE code
messageHuman readable error message
PODBC::P_DECLARE_ENUM ( DriverType  ,
DSN  ,
mySQL  ,
postgreSQL  ,
Oracle  ,
IBM_DB2  ,
MSSQL  ,
MSAccess  ,
Paradox  ,
Foxpro  ,
dBase  ,
Excel  ,
Ascii  ,
ConnectionString   
)

Driver types that are supported by this implementation.

PODBC::P_REMOVE_VIRTUAL_VOID ( OnSQLError(const PString &, const PString &)  )
protected
__inline bool PODBC::Query ( const PString sql)
inline

References Execute().

void PODBC::SetDateFormat ( PTime::TimeFormat  fmt)
inline

References m_dateFormat.

void PODBC::SetDateTimeFormat ( PTime::TimeFormat  fmt)
inline

References m_dateTimeFormat.

void PODBC::SetPrecision ( unsigned  precision)

Set the Number of Decimal places to

round to By Default it is 4.

However if the field decimal places is less then Precision Value the field rounding will be used. This must be set prior to calling LoadTable()

void PODBC::SetTimeFormat ( PTime::TimeFormat  fmt)
inline

References m_timeFormat.

PStringArray PODBC::TableList ( const PString options = PString::Empty())

Retrieve a List of Tables in the Datasource

use the option field to specify the type of data to access.

ie "CATALOGS", "SCHEMAS", "TABLE" or "VIEW" Note case is significant.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  strm,
DriverType  type 
)
friend

Member Data Documentation

PTime::TimeFormat PODBC::m_dateFormat
protected

Referenced by GetDateFormat(), and SetDateFormat().

PTime::TimeFormat PODBC::m_dateTimeFormat
protected
int PODBC::m_lastError
protected

Referenced by GetLastError().

PString PODBC::m_lastErrorText
protected

Referenced by GetLastErrorText().

Link* PODBC::m_link
protected
PINDEX PODBC::m_maxChunkSize
protected

Referenced by GetMaxChunkSize().

bool PODBC::m_needChunking
protected

Referenced by GetMaxChunkSize().

unsigned PODBC::m_precision
protected

Referenced by GetPrecision().

PTime::TimeFormat PODBC::m_timeFormat
protected

Double Real Float Decimal digit rounding def= 4;.

Referenced by GetTimeFormat(), and SetTimeFormat().


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