PTLib
Version 2.18.8
|
ODBC Support for PWLIB. More...
#include <podbc.h>
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 |
![]() | |
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) |
![]() | |
__inline unsigned | GetTraceContextIdentifier () const |
Get PTRACE context identifier. More... | |
__inline void | SetTraceContextIdentifier (unsigned id) |
__inline void | SetTraceContextIdentifier (const PObject &obj) |
__inline void | SetTraceContextIdentifier (const PObject *obj) |
__inline void | CopyTraceContextIdentifier (PObject &obj) const |
__inline void | CopyTraceContextIdentifier (PObject *obj) const |
virtual | ~PObject () |
__inline const char * | GetClass () const |
__inline bool | IsClass (const char *name) const |
__inline const PObject * | PTraceObjectInstance () const |
virtual PObject * | Clone () 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 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 &)) | |
![]() | |
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 |
![]() | |
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 __inline void | CopyTraceContextIdentifier (PObject &to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject &to, const PObject *from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject &from) |
static __inline void | CopyTraceContextIdentifier (PObject *to, const PObject *from) |
static __inline const char * | Class () |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
template<typename T > | |
static Comparison | Compare2 (T v1, T v2) |
Compare two types, returning Comparison type. More... | |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
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.
typedef unsigned PODBC::RowIndex |
Type for row index, may become 64 bit one day.
typedef RecordSet PODBC::Table |
PODBC::PODBC | ( | ) |
Constructs ODBC connection.
PODBC::~PODBC | ( | ) |
Destroys ODBC connection.
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.
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().
|
inline |
References m_dateFormat.
|
inline |
References m_dateTimeFormat.
|
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 |
Get valid field type for PVarType enumeration.
This will get the database specific field name for the driver type.
|
inline |
Get last error.
References m_lastError.
|
inline |
Get last error text.
References m_lastErrorText.
|
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, m_needChunking, and P_MAX_INDEX.
|
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.
|
inline |
References m_timeFormat.
bool PODBC::IsConnected | ( | ) | const |
Return true if connected.
|
virtual |
Call back on successful connection.
|
virtual |
OnSQL Error.
native | Native error code |
code | 5 character SQLSTATE code |
message | Human 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.
|
protected |
|
inline |
References m_dateFormat.
|
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()
|
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.
|
friend |
|
protected |
Referenced by GetDateFormat(), and SetDateFormat().
|
protected |
Referenced by GetDateTimeFormat(), and SetDateTimeFormat().
|
protected |
Referenced by GetLastError().
|
protected |
Referenced by GetLastErrorText().
|
protected |
|
protected |
Referenced by GetMaxChunkSize().
|
protected |
Referenced by GetMaxChunkSize().
|
protected |
Referenced by GetPrecision().
|
protected |
Double Real Float Decimal digit rounding def= 4;.
Referenced by GetTimeFormat(), and SetTimeFormat().