--- /dev/null
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+// File : $Id: ibpp.h,v 1.3 2007/10/28 11:17:44 nobunaga Exp $\r
+// Subject : IBPP public header file. This is _the_ only file you include in\r
+// your application files when developing with IBPP.\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+// (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)\r
+//\r
+// The contents of this file are subject to the IBPP License (the "License");\r
+// you may not use this file except in compliance with the License. You may\r
+// obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'\r
+// file which must have been distributed along with this file.\r
+//\r
+// This software, distributed under the License, is distributed on an "AS IS"\r
+// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the\r
+// License for the specific language governing rights and limitations\r
+// under the License.\r
+//\r
+// Contributor(s):\r
+//\r
+// Olivier Mascia, main coding\r
+// Matt Hortman, initial linux port\r
+// Mark Jordan, design contributions\r
+// Maxim Abrashkin, enhancement patches\r
+// Torsten Martinsen, enhancement patches\r
+// Michael Hieke, darwin (OS X) port, enhancement patches\r
+// Val Samko, enhancement patches and debugging\r
+// Mike Nordell, invaluable C++ advices\r
+// Claudio Valderrama, help with not-so-well documented IB/FB features\r
+// Many others, excellent suggestions, bug finding, and support\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+// COMMENTS\r
+// Tabulations should be set every four characters when editing this file.\r
+//\r
+// When compiling a project using IBPP, the following defines should be made\r
+// on the command-line (or in makefiles) according to the OS platform and\r
+// compiler used.\r
+//\r
+// Select the platform: IBPP_WINDOWS | IBPP_LINUX | IBPP_DARWIN\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
+#ifndef __IBPP_H__\r
+#define __IBPP_H__\r
+\r
+#if !defined(IBPP_WINDOWS) && !defined(IBPP_LINUX) && !defined(IBPP_DARWIN)\r
+#error Please define IBPP_WINDOWS/IBPP_LINUX/IBPP_DARWIN before compiling !\r
+#endif\r
+\r
+#if !defined(__BCPLUSPLUS__) && !defined(__GNUC__) && !defined(_MSC_VER) && !defined(__DMC__)
+#error Your compiler is not recognized.\r
+#endif\r
+\r
+#if defined(IBPP_LINUX) || defined(IBPP_DARWIN)\r
+#define IBPP_UNIX // IBPP_UNIX stands as a common denominator to *NIX flavours\r
+#endif\r
+\r
+// IBPP is written for 32 bits systems or higher.\r
+// The standard type 'int' is assumed to be at least 32 bits.\r
+// And the standard type 'short' is assumed to be exactly 16 bits.\r
+// Everywhere possible, where the exact size of an integer does not matter,\r
+// the standard type 'int' is used. And where an exact integer size is required\r
+// the standard exact precision types definitions of C 99 standard are used.\r
+\r
+#if defined(_MSC_VER) || defined(__DMC__) || defined(__BCPLUSPLUS__)\r
+// C99 §7.18.1.1 Exact-width integer types (only those used by IBPP)\r
+#if defined(_MSC_VER) && (_MSC_VER < 1300) // MSVC 6 should be < 1300\r
+ typedef short int16_t;\r
+ typedef int int32_t;\r
+ typedef unsigned int uint32_t;\r
+#else\r
+ typedef __int16 int16_t;\r
+ typedef __int32 int32_t;\r
+ typedef unsigned __int32 uint32_t;\r
+#endif\r
+ typedef __int64 int64_t;\r
+#else\r
+ #include <cstdint> // C99 (§7.18) integer types definitions\r
+#endif\r
+\r
+#if !defined(_)\r
+#define _(s) s\r
+#endif\r
+\r
+#include <exception>\r
+#include <string>\r
+#include <vector>\r
+\r
+namespace IBPP\r
+{\r
+ // Typically you use this constant in a call IBPP::CheckVersion as in:\r
+ // if (! IBPP::CheckVersion(IBPP::Version)) { throw .... ; }\r
+ const uint32_t Version = (2<<24) + (5<<16) + (3<<8) + 0; // Version == 2.5.3.0\r
+\r
+ // Dates range checking\r
+ const int MinDate = -693594; // 1 JAN 0001\r
+ const int MaxDate = 2958464; // 31 DEC 9999\r
+ \r
+ // Transaction Access Modes\r
+ enum TAM {amWrite, amRead};\r
+\r
+ // Transaction Isolation Levels\r
+ enum TIL {ilConcurrency, ilReadDirty, ilReadCommitted, ilConsistency};\r
+\r
+ // Transaction Lock Resolution\r
+ enum TLR {lrWait, lrNoWait};\r
+\r
+ // Transaction Table Reservation\r
+ enum TTR {trSharedWrite, trSharedRead, trProtectedWrite, trProtectedRead};\r
+\r
+ // Prepared Statement Types\r
+ enum STT {stUnknown, stUnsupported,\r
+ stSelect, stInsert, stUpdate, stDelete, stDDL, stExecProcedure,\r
+ stSelectUpdate, stSetGenerator, stSavePoint};\r
+\r
+ // SQL Data Types\r
+ enum SDT {sdArray, sdBlob, sdDate, sdTime, sdTimestamp, sdString,\r
+ sdSmallint, sdInteger, sdLargeint, sdFloat, sdDouble};\r
+\r
+ // Array Data Types\r
+ enum ADT {adDate, adTime, adTimestamp, adString,\r
+ adBool, adInt16, adInt32, adInt64, adFloat, adDouble};\r
+\r
+ // Database::Shutdown Modes\r
+ enum DSM {dsForce, dsDenyTrans, dsDenyAttach};\r
+\r
+ // Service::StartBackup && Service::StartRestore Flags\r
+ enum BRF {\r
+ brVerbose = 0x1,\r
+ // Backup flags\r
+ brIgnoreChecksums = 0x100, brIgnoreLimbo = 0x200,\r
+ brMetadataOnly = 0x400, brNoGarbageCollect = 0x800,\r
+ brNonTransportable = 0x1000, brConvertExtTables = 0x2000,\r
+ // Restore flags\r
+ brReplace = 0x10000, brDeactivateIdx = 0x20000,\r
+ brNoShadow = 0x40000, brNoValidity = 0x80000,\r
+ brPerTableCommit = 0x100000, brUseAllSpace = 0x200000\r
+ };\r
+\r
+ // Service::Repair Flags\r
+ enum RPF\r
+ {\r
+ // Mandatory and mutually exclusives\r
+ rpMendRecords = 0x1, rpValidatePages = 0x2, rpValidateFull = 0x4,\r
+ // Options\r
+ rpReadOnly = 0x100, rpIgnoreChecksums = 0x200, rpKillShadows = 0x400\r
+ };\r
+\r
+ // TransactionFactory Flags\r
+ enum TFF {tfIgnoreLimbo = 0x1, tfAutoCommit = 0x2, tfNoAutoUndo = 0x4};\r
+\r
+ /* IBPP never return any error codes. It throws exceptions.\r
+ * On database engine reported errors, an IBPP::SQLException is thrown.\r
+ * In all other cases, IBPP throws IBPP::LogicException.\r
+ * Also note that the runtime and the language might also throw exceptions\r
+ * while executing some IBPP methods. A failing new operator will throw\r
+ * std::bad_alloc, IBPP does nothing to alter the standard behaviour.\r
+ *\r
+ * std::exception\r
+ * |\r
+ * IBPP::Exception\r
+ * / \\r
+ * IBPP::LogicException IBPP::SQLException\r
+ * |\r
+ * IBPP::WrongType\r
+ */\r
+\r
+ class Exception : public std::exception\r
+ {\r
+ public:\r
+ virtual const char* Origin() const throw() = 0;\r
+ virtual const char* ErrorMessage() const throw() = 0; // Deprecated, use what()\r
+ virtual const char* what() const throw() = 0;\r
+ virtual ~Exception() throw();\r
+ };\r
+\r
+ class LogicException : public Exception\r
+ {\r
+ public:\r
+ virtual ~LogicException() throw();\r
+ };\r
+\r
+ class SQLException : public Exception\r
+ {\r
+ public:\r
+ virtual int SqlCode() const throw() = 0;\r
+ virtual int EngineCode() const throw() = 0;\r
+ \r
+ virtual ~SQLException() throw();\r
+ };\r
+\r
+ class WrongType : public LogicException\r
+ {\r
+ public:\r
+ virtual ~WrongType() throw();\r
+ };\r
+ \r
+ /* Classes Date, Time, Timestamp and DBKey are 'helper' classes. They help\r
+ * in retrieving or setting some special SQL types. Dates, times and dbkeys\r
+ * are often read and written as strings in SQL scripts. When programming\r
+ * with IBPP, we handle those data with these specific classes, which\r
+ * enhance their usefullness and free us of format problems (M/D/Y, D/M/Y,\r
+ * Y-M-D ?, and so on...). */\r
+\r
+ /* Class Date represent purely a Date (no time part specified). It is\r
+ * usefull in interactions with the SQL DATE type of Interbase. You can add\r
+ * or substract a number from a Date, that will modify it to represent the\r
+ * correct date, X days later or sooner. All the Y2K details taken into\r
+ * account.\r
+ * The full range goes from integer values IBPP::MinDate to IBPP::MaxDate\r
+ * which means from 01 Jan 0001 to 31 Dec 9999. ( Which is inherently\r
+ * incorrect as this assumes Gregorian calendar. ) */\r
+ \r
+ class Timestamp; // Cross-reference between Timestamp, Date and Time\r
+ \r
+ class Date\r
+ {\r
+ protected:\r
+ int mDate; // The date : 1 == 1 Jan 1900\r
+\r
+ public:\r
+ void Clear() { mDate = MinDate - 1; }\r
+ void Today();\r
+ void SetDate(int year, int month, int day);\r
+ void SetDate(int dt);\r
+ void GetDate(int& year, int& month, int& day) const;\r
+ int GetDate() const { return mDate; }\r
+ int Year() const;\r
+ int Month() const;\r
+ int Day() const;\r
+ void Add(int days);\r
+ void StartOfMonth();\r
+ void EndOfMonth();\r
+ \r
+ Date() { Clear(); }\r
+ Date(int dt) { SetDate(dt); }\r
+ Date(int year, int month, int day);\r
+ Date(const Date&); // Copy Constructor\r
+ Date& operator=(const Timestamp&); // Timestamp Assignment operator\r
+ Date& operator=(const Date&); // Date Assignment operator\r
+\r
+ bool operator==(const Date& rv) const { return mDate == rv.GetDate(); }\r
+ bool operator!=(const Date& rv) const { return mDate != rv.GetDate(); }\r
+ bool operator<(const Date& rv) const { return mDate < rv.GetDate(); }\r
+ bool operator>(const Date& rv) const { return mDate > rv.GetDate(); }\r
+\r
+ virtual ~Date() { }\r
+ };\r
+\r
+ /* Class Time represent purely a Time. It is usefull in interactions\r
+ * with the SQL TIME type of Interbase. */\r
+\r
+ class Time\r
+ {\r
+ protected:\r
+ int mTime; // The time, in ten-thousandths of seconds since midnight\r
+\r
+ public:\r
+ void Clear() { mTime = 0; }\r
+ void Now();\r
+ void SetTime(int hour, int minute, int second, int tenthousandths = 0);\r
+ void SetTime(int tm);\r
+ void GetTime(int& hour, int& minute, int& second) const;\r
+ void GetTime(int& hour, int& minute, int& second, int& tenthousandths) const;\r
+ int GetTime() const { return mTime; }\r
+ int Hours() const;\r
+ int Minutes() const;\r
+ int Seconds() const;\r
+ int SubSeconds() const; // Actually tenthousandths of seconds\r
+ Time() { Clear(); }\r
+ Time(int tm) { SetTime(tm); }\r
+ Time(int hour, int minute, int second, int tenthousandths = 0);\r
+ Time(const Time&); // Copy Constructor\r
+ Time& operator=(const Timestamp&); // Timestamp Assignment operator\r
+ Time& operator=(const Time&); // Time Assignment operator\r
+\r
+ bool operator==(const Time& rv) const { return mTime == rv.GetTime(); }\r
+ bool operator!=(const Time& rv) const { return mTime != rv.GetTime(); }\r
+ bool operator<(const Time& rv) const { return mTime < rv.GetTime(); }\r
+ bool operator>(const Time& rv) const { return mTime > rv.GetTime(); }\r
+\r
+ virtual ~Time() { }\r
+ };\r
+\r
+ /* Class Timestamp represent a date AND a time. It is usefull in\r
+ * interactions with the SQL TIMESTAMP type of Interbase. This class\r
+ * inherits from Date and Time and completely inline implements its small\r
+ * specific details. */\r
+\r
+ class Timestamp : public Date, public Time\r
+ {\r
+ public:\r
+ void Clear() { Date::Clear(); Time::Clear(); }\r
+ void Today() { Date::Today(); Time::Clear(); }\r
+ void Now() { Date::Today(); Time::Now(); }\r
+\r
+ Timestamp() { Clear(); }\r
+\r
+ Timestamp(int y, int m, int d)\r
+ { Date::SetDate(y, m, d); Time::Clear(); }\r
+\r
+ Timestamp(int y, int mo, int d, int h, int mi, int s, int t = 0)\r
+ { Date::SetDate(y, mo, d); Time::SetTime(h, mi, s, t); }\r
+\r
+ Timestamp(const Timestamp& rv)\r
+ : Date(rv.mDate), Time(rv.mTime) {} // Copy Constructor\r
+\r
+ Timestamp(const Date& rv)\r
+ { mDate = rv.GetDate(); mTime = 0; }\r
+\r
+ Timestamp(const Time& rv)\r
+ { mDate = 0; mTime = rv.GetTime(); }\r
+\r
+ Timestamp& operator=(const Timestamp& rv) // Timestamp Assignment operator\r
+ { mDate = rv.mDate; mTime = rv.mTime; return *this; }\r
+\r
+ Timestamp& operator=(const Date& rv) // Date Assignment operator\r
+ { mDate = rv.GetDate(); return *this; }\r
+\r
+ Timestamp& operator=(const Time& rv) // Time Assignment operator\r
+ { mTime = rv.GetTime(); return *this; }\r
+\r
+ bool operator==(const Timestamp& rv) const\r
+ { return (mDate == rv.GetDate()) && (mTime == rv.GetTime()); }\r
+\r
+ bool operator!=(const Timestamp& rv) const\r
+ { return (mDate != rv.GetDate()) || (mTime != rv.GetTime()); }\r
+\r
+ bool operator<(const Timestamp& rv) const\r
+ { return (mDate < rv.GetDate()) ||\r
+ (mDate == rv.GetDate() && mTime < rv.GetTime()); }\r
+\r
+ bool operator>(const Timestamp& rv) const\r
+ { return (mDate > rv.GetDate()) ||\r
+ (mDate == rv.GetDate() && mTime > rv.GetTime()); }\r
+\r
+ ~Timestamp() { }\r
+ };\r
+\r
+ /* Class DBKey can store a DBKEY, that special value which the hidden\r
+ * RDB$DBKEY can give you from a select statement. A DBKey is nothing\r
+ * specific to IBPP. It's a feature of the Firebird database engine. See its\r
+ * documentation for more information. */\r
+\r
+ class DBKey\r
+ {\r
+ private:\r
+ std::string mDBKey; // Stores the binary DBKey\r
+ mutable std::string mString;// String (temporary) representation of it\r
+\r
+ public:\r
+ void Clear();\r
+ int Size() const { return (int)mDBKey.size(); }\r
+ void SetKey(const void*, int size);\r
+ void GetKey(void*, int size) const;\r
+ const char* AsString() const;\r
+\r
+ DBKey& operator=(const DBKey&); // Assignment operator\r
+ DBKey(const DBKey&); // Copy Constructor\r
+ DBKey() { }\r
+ ~DBKey() { }\r
+ };\r
+\r
+ /* Class User wraps all the information about a user that the engine can manage. */\r
+\r
+ class User\r
+ {\r
+ public:\r
+ std::string username;\r
+ std::string password;\r
+ std::string firstname;\r
+ std::string middlename;\r
+ std::string lastname;\r
+ uint32_t userid; // Only relevant on unixes\r
+ uint32_t groupid; // Only relevant on unixes\r
+\r
+ private:\r
+ void copyfrom(const User& r);\r
+\r
+ public:\r
+ void clear();\r
+ User& operator=(const User& r) { copyfrom(r); return *this; }\r
+ User(const User& r) { copyfrom(r); }\r
+ User() : userid(0), groupid(0) { }\r
+ ~User() { }\r
+ };\r
+\r
+ // Interface Wrapper\r
+ template <class T>\r
+ class Ptr\r
+ {\r
+ private:\r
+ T* mObject;\r
+\r
+ public:\r
+ void clear()\r
+ {\r
+ if (mObject != 0) { mObject->Release(); mObject = 0; }\r
+ }\r
+\r
+ T* intf() const { return mObject; }\r
+ T* operator->() const { return mObject; }\r
+\r
+ bool operator==(const T* p) const { return mObject == p; }\r
+ bool operator==(const Ptr& r) const { return mObject == r.mObject; }\r
+ bool operator!=(const T* p) const { return mObject != p; }\r
+ bool operator!=(const Ptr& r) const { return mObject != r.mObject; }\r
+\r
+ Ptr& operator=(T* p)\r
+ {\r
+ // AddRef _before_ Release gives correct behaviour on self-assigns\r
+ T* tmp = (p == 0 ? 0 : p->AddRef()); // Take care of 0\r
+ if (mObject != 0) mObject->Release();\r
+ mObject = tmp; return *this;\r
+ }\r
+\r
+ Ptr& operator=(const Ptr& r)\r
+ {\r
+ // AddRef _before_ Release gives correct behaviour on self-assigns\r
+ T* tmp = (r.intf() == 0 ? 0 : r->AddRef());// Take care of 0\r
+ if (mObject != 0) mObject->Release();\r
+ mObject = tmp; return *this;\r
+ }\r
+\r
+ Ptr(T* p) : mObject(p == 0 ? 0 : p->AddRef()) { }\r
+ Ptr(const Ptr& r) : mObject(r.intf() == 0 ? 0 : r->AddRef()) { }\r
+\r
+ Ptr() : mObject(0) { }\r
+ ~Ptr() { clear(); }\r
+ };\r
+\r
+ // --- Interface Classes --- //\r
+\r
+ /* Interfaces IBlob, IArray, IService, IDatabase, ITransaction and\r
+ * IStatement are at the core of IBPP. Though it is possible to program your\r
+ * applications by using theses interfaces directly (as was the case with\r
+ * IBPP 1.x), you should refrain from using them and prefer the new IBPP\r
+ * Objects Blob, Array, ... (without the I in front). Those new objects are\r
+ * typedef'd right after each interface class definition as you can read\r
+ * below. If you program using the Blob (instead of the IBlob interface\r
+ * itself), you'll never have to care about AddRef/Release and you'll never\r
+ * have to care about deleting your objects. */\r
+\r
+ class IBlob; typedef Ptr<IBlob> Blob;\r
+ class IArray; typedef Ptr<IArray> Array;\r
+ class IService; typedef Ptr<IService> Service;\r
+ class IDatabase; typedef Ptr<IDatabase> Database;\r
+ class ITransaction; typedef Ptr<ITransaction> Transaction;\r
+ class IStatement; typedef Ptr<IStatement> Statement;\r
+ class IEvents; typedef Ptr<IEvents> Events;\r
+ class IRow; typedef Ptr<IRow> Row;\r
+\r
+ /* IBlob is the interface to the blob capabilities of IBPP. Blob is the\r
+ * object class you actually use in your programming. In Firebird, at the\r
+ * row level, a blob is merely a handle to a blob, stored elsewhere in the\r
+ * database. Blob allows you to retrieve such a handle and then read from or\r
+ * write to the blob, much in the same manner than you would do with a file. */\r
+\r
+ class IBlob\r
+ {\r
+ public:\r
+ virtual void Create() = 0;\r
+ virtual void Open() = 0;\r
+ virtual void Close() = 0;\r
+ virtual void Cancel() = 0;\r
+ virtual int Read(void*, int size) = 0;\r
+ virtual void Write(const void*, int size) = 0;\r
+ virtual void Info(int* Size, int* Largest, int* Segments) = 0;\r
+ \r
+ virtual void Save(const std::string& data) = 0;\r
+ virtual void Load(std::string& data) = 0;\r
+\r
+ virtual Database DatabasePtr() const = 0;\r
+ virtual Transaction TransactionPtr() const = 0;\r
+\r
+ virtual IBlob* AddRef() = 0;\r
+ virtual void Release() = 0;\r
+\r
+ virtual ~IBlob() { }\r
+ };\r
+\r
+ /* IArray is the interface to the array capabilities of IBPP. Array is the\r
+ * object class you actually use in your programming. With an Array object, you\r
+ * can create, read and write Interbase Arrays, as a whole or in slices. */\r
+\r
+ class IArray\r
+ {\r
+ public:\r
+ virtual void Describe(const std::string& table, const std::string& column) = 0;\r
+ virtual void ReadTo(ADT, void* buffer, int elemcount) = 0;\r
+ virtual void WriteFrom(ADT, const void* buffer, int elemcount) = 0;\r
+ virtual SDT ElementType() = 0;\r
+ virtual int ElementSize() = 0;\r
+ virtual int ElementScale() = 0;\r
+ virtual int Dimensions() = 0;\r
+ virtual void Bounds(int dim, int* low, int* high) = 0;\r
+ virtual void SetBounds(int dim, int low, int high) = 0;\r
+\r
+ virtual Database DatabasePtr() const = 0;\r
+ virtual Transaction TransactionPtr() const = 0;\r
+\r
+ virtual IArray* AddRef() = 0;\r
+ virtual void Release() = 0;\r
+\r
+ virtual ~IArray() { }\r
+ };\r
+\r
+ /* IService is the interface to the service capabilities of IBPP. Service is\r
+ * the object class you actually use in your programming. With a Service\r
+ * object, you can do some maintenance work of databases and servers\r
+ * (backup, restore, create/update users, ...) */\r
+\r
+ class IService\r
+ {\r
+ public:\r
+ virtual void Connect() = 0;\r
+ virtual bool Connected() = 0;\r
+ virtual void Disconnect() = 0;\r
+\r
+ virtual void GetVersion(std::string& version) = 0;\r
+\r
+ virtual void AddUser(const User&) = 0;\r
+ virtual void GetUser(User&) = 0;\r
+ virtual void GetUsers(std::vector<User>&) = 0;\r
+ virtual void ModifyUser(const User&) = 0;\r
+ virtual void RemoveUser(const std::string& username) = 0;\r
+\r
+ virtual void SetPageBuffers(const std::string& dbfile, int buffers) = 0;\r
+ virtual void SetSweepInterval(const std::string& dbfile, int sweep) = 0;\r
+ virtual void SetSyncWrite(const std::string& dbfile, bool) = 0;\r
+ virtual void SetReadOnly(const std::string& dbfile, bool) = 0;\r
+ virtual void SetReserveSpace(const std::string& dbfile, bool) = 0;\r
+\r
+ virtual void Shutdown(const std::string& dbfile, DSM mode, int sectimeout) = 0;\r
+ virtual void Restart(const std::string& dbfile) = 0;\r
+ virtual void Sweep(const std::string& dbfile) = 0;\r
+ virtual void Repair(const std::string& dbfile, RPF flags) = 0;\r
+\r
+ virtual void StartBackup(const std::string& dbfile,\r
+ const std::string& bkfile, BRF flags = BRF(0)) = 0;\r
+ virtual void StartRestore(const std::string& bkfile, const std::string& dbfile,\r
+ int pagesize = 0, BRF flags = BRF(0)) = 0;\r
+\r
+ virtual const char* WaitMsg() = 0; // With reporting (does not block)\r
+ virtual void Wait() = 0; // Without reporting (does block)\r
+\r
+ virtual IService* AddRef() = 0;\r
+ virtual void Release() = 0;\r
+\r
+ virtual ~IService() { }\r
+ };\r
+\r
+ /* IDatabase is the interface to the database connections in IBPP. Database\r
+ * is the object class you actually use in your programming. With a Database\r
+ * object, you can create/drop/connect databases. */\r
+\r
+ class EventInterface; // Cross-reference between EventInterface and IDatabase\r
+ \r
+ class IDatabase\r
+ {\r
+ public:\r
+ virtual const char* ServerName() const = 0;\r
+ virtual const char* DatabaseName() const = 0;\r
+ virtual const char* Username() const = 0;\r
+ virtual const char* UserPassword() const = 0;\r
+ virtual const char* RoleName() const = 0;\r
+ virtual const char* CharSet() const = 0;\r
+ virtual const char* CreateParams() const = 0;\r
+\r
+ virtual void Info(int* ODS, int* ODSMinor, int* PageSize,\r
+ int* Pages, int* Buffers, int* Sweep, bool* Sync,\r
+ bool* Reserve) = 0;\r
+ virtual void Statistics(int* Fetches, int* Marks,\r
+ int* Reads, int* Writes) = 0;\r
+ virtual void Counts(int* Insert, int* Update, int* Delete, \r
+ int* ReadIdx, int* ReadSeq) = 0;\r
+ virtual void Users(std::vector<std::string>& users) = 0;\r
+ virtual int Dialect() = 0;\r
+\r
+ virtual void Create(int dialect) = 0;\r
+ virtual void Connect() = 0;\r
+ virtual bool Connected() = 0;\r
+ virtual void Inactivate() = 0;\r
+ virtual void Disconnect() = 0;\r
+ virtual void Drop() = 0;\r
+\r
+ virtual IDatabase* AddRef() = 0;\r
+ virtual void Release() = 0;\r
+\r
+ virtual ~IDatabase() { }\r
+ };\r
+\r
+ /* ITransaction is the interface to the transaction connections in IBPP.\r
+ * Transaction is the object class you actually use in your programming. A\r
+ * Transaction object can be associated with more than one Database,\r
+ * allowing for distributed transactions spanning multiple databases,\r
+ * possibly located on different servers. IBPP is one among the few\r
+ * programming interfaces to Firebird that allows you to support distributed\r
+ * transactions. */\r
+\r
+ class ITransaction\r
+ {\r
+ public:\r
+ virtual void AttachDatabase(Database db, TAM am = amWrite,\r
+ TIL il = ilConcurrency, TLR lr = lrWait, TFF flags = TFF(0)) = 0;\r
+ virtual void DetachDatabase(Database db) = 0;\r
+ virtual void AddReservation(Database db,\r
+ const std::string& table, TTR tr) = 0;\r
+\r
+ virtual void Start() = 0;\r
+ virtual bool Started() = 0;\r
+ virtual void Commit() = 0;\r
+ virtual void Rollback() = 0;\r
+ virtual void CommitRetain() = 0;\r
+ virtual void RollbackRetain() = 0;\r
+\r
+ virtual ITransaction* AddRef() = 0;\r
+ virtual void Release() = 0;\r
+\r
+ virtual ~ITransaction() { }\r
+ };\r
+\r
+ /*\r
+ * Class Row can hold all the values of a row (from a SELECT for instance).\r
+ */\r
+\r
+ class IRow\r
+ {\r
+ public:\r
+ virtual void SetNull(int) = 0;\r
+ virtual void Set(int, bool) = 0;\r
+ virtual void Set(int, const void*, int) = 0; // byte buffers\r
+ virtual void Set(int, const char*) = 0; // c-string\r
+ virtual void Set(int, const std::string&) = 0;\r
+ virtual void Set(int, int16_t) = 0;\r
+ virtual void Set(int, int32_t) = 0;\r
+ virtual void Set(int, int64_t) = 0;\r
+ virtual void Set(int, float) = 0;\r
+ virtual void Set(int, double) = 0;\r
+ virtual void Set(int, const Timestamp&) = 0;\r
+ virtual void Set(int, const Date&) = 0;\r
+ virtual void Set(int, const Time&) = 0;\r
+ virtual void Set(int, const DBKey&) = 0;\r
+ virtual void Set(int, const Blob&) = 0;\r
+ virtual void Set(int, const Array&) = 0;\r
+\r
+ virtual bool IsNull(int) = 0;\r
+ virtual bool Get(int, bool&) = 0;\r
+ virtual bool Get(int, void*, int&) = 0; // byte buffers\r
+ virtual bool Get(int, std::string&) = 0;\r
+ virtual bool Get(int, int16_t&) = 0;\r
+ virtual bool Get(int, int32_t&) = 0;\r
+ virtual bool Get(int, int64_t&) = 0;\r
+ virtual bool Get(int, float&) = 0;\r
+ virtual bool Get(int, double&) = 0;\r
+ virtual bool Get(int, Timestamp&) = 0;\r
+ virtual bool Get(int, Date&) = 0;\r
+ virtual bool Get(int, Time&) = 0;\r
+ virtual bool Get(int, DBKey&) = 0;\r
+ virtual bool Get(int, Blob&) = 0;\r
+ virtual bool Get(int, Array&) = 0;\r
+\r
+ virtual bool IsNull(const std::string&) = 0;\r
+ virtual bool Get(const std::string&, bool&) = 0;\r
+ virtual bool Get(const std::string&, void*, int&) = 0; // byte buffers\r
+ virtual bool Get(const std::string&, std::string&) = 0;\r
+ virtual bool Get(const std::string&, int16_t&) = 0;\r
+ virtual bool Get(const std::string&, int32_t&) = 0;\r
+ virtual bool Get(const std::string&, int64_t&) = 0;\r
+ virtual bool Get(const std::string&, float&) = 0;\r
+ virtual bool Get(const std::string&, double&) = 0;\r
+ virtual bool Get(const std::string&, Timestamp&) = 0;\r
+ virtual bool Get(const std::string&, Date&) = 0;\r
+ virtual bool Get(const std::string&, Time&) = 0;\r
+ virtual bool Get(const std::string&, DBKey&) = 0;\r
+ virtual bool Get(const std::string&, Blob&) = 0;\r
+ virtual bool Get(const std::string&, Array&) = 0;\r
+\r
+ virtual int ColumnNum(const std::string&) = 0;\r
+ virtual const char* ColumnName(int) = 0;\r
+ virtual const char* ColumnAlias(int) = 0;\r
+ virtual const char* ColumnTable(int) = 0;\r
+ virtual SDT ColumnType(int) = 0;\r
+ virtual int ColumnSubtype(int) = 0;\r
+ virtual int ColumnSize(int) = 0;\r
+ virtual int ColumnScale(int) = 0;\r
+ virtual int Columns() = 0;\r
+ \r
+ virtual bool ColumnUpdated(int) = 0;\r
+ virtual bool Updated() = 0;\r
+\r
+ virtual Database DatabasePtr() const = 0;\r
+ virtual Transaction TransactionPtr() const = 0;\r
+\r
+ virtual IRow* Clone() = 0;\r
+ virtual IRow* AddRef() = 0;\r
+ virtual void Release() = 0;\r
+\r
+ virtual ~IRow() {}\r
+ };\r
+\r
+ /* IStatement is the interface to the statements execution in IBPP.\r
+ * Statement is the object class you actually use in your programming. A\r
+ * Statement object is the work horse of IBPP. All your data manipulation\r
+ * statements will be done through it. It is also used to access the result\r
+ * set of a query (when the statement is such), one row at a time and in\r
+ * strict forward direction. */\r
+\r
+ class IStatement\r
+ {\r
+ public:\r
+ virtual void Prepare(const std::string&) = 0;\r
+ virtual void Execute() = 0;\r
+ virtual void Execute(const std::string&) = 0;\r
+ virtual void ExecuteImmediate(const std::string&) = 0;\r
+ virtual void CursorExecute(const std::string& cursor) = 0;\r
+ virtual void CursorExecute(const std::string& cursor, const std::string&) = 0;\r
+ virtual bool Fetch() = 0;\r
+ virtual bool Fetch(Row&) = 0;\r
+ virtual int AffectedRows() = 0;\r
+ virtual void Close() = 0;\r
+ virtual std::string& Sql() = 0;\r
+ virtual STT Type() = 0;\r
+\r
+ virtual void SetNull(int) = 0;\r
+ virtual void Set(int, bool) = 0;\r
+ virtual void Set(int, const void*, int) = 0; // byte buffers\r
+ virtual void Set(int, const char*) = 0; // c-string\r
+ virtual void Set(int, const std::string&) = 0;\r
+ virtual void Set(int, int16_t value) = 0;\r
+ virtual void Set(int, int32_t value) = 0;\r
+ virtual void Set(int, int64_t value) = 0;\r
+ virtual void Set(int, float value) = 0;\r
+ virtual void Set(int, double value) = 0;\r
+ virtual void Set(int, const Timestamp& value) = 0;\r
+ virtual void Set(int, const Date& value) = 0;\r
+ virtual void Set(int, const Time& value) = 0;\r
+ virtual void Set(int, const DBKey& value) = 0;\r
+ virtual void Set(int, const Blob& value) = 0;\r
+ virtual void Set(int, const Array& value) = 0;\r
+\r
+ virtual bool IsNull(int) = 0;\r
+ virtual bool Get(int, bool&) = 0;\r
+ virtual bool Get(int, void*, int&) = 0; // byte buffers\r
+ virtual bool Get(int, std::string&) = 0;\r
+ virtual bool Get(int, int16_t&) = 0;\r
+ virtual bool Get(int, int32_t&) = 0;\r
+ virtual bool Get(int, int64_t&) = 0;\r
+ virtual bool Get(int, float&) = 0;\r
+ virtual bool Get(int, double&) = 0;\r
+ virtual bool Get(int, Timestamp& value) = 0;\r
+ virtual bool Get(int, Date& value) = 0;\r
+ virtual bool Get(int, Time& value) = 0;\r
+ virtual bool Get(int, DBKey& value) = 0;\r
+ virtual bool Get(int, Blob& value) = 0;\r
+ virtual bool Get(int, Array& value) = 0;\r
+\r
+ virtual bool IsNull(const std::string&) = 0;\r
+ virtual bool Get(const std::string&, bool&) = 0;\r
+ virtual bool Get(const std::string&, void*, int&) = 0; // byte buffers\r
+ virtual bool Get(const std::string&, std::string&) = 0;\r
+ virtual bool Get(const std::string&, int16_t&) = 0;\r
+ virtual bool Get(const std::string&, int32_t&) = 0;\r
+ virtual bool Get(const std::string&, int64_t&) = 0;\r
+ virtual bool Get(const std::string&, float&) = 0;\r
+ virtual bool Get(const std::string&, double&) = 0;\r
+ virtual bool Get(const std::string&, Timestamp& value) = 0;\r
+ virtual bool Get(const std::string&, Date& value) = 0;\r
+ virtual bool Get(const std::string&, Time& value) = 0;\r
+ virtual bool Get(const std::string&, DBKey& value) = 0;\r
+ virtual bool Get(const std::string&, Blob& value) = 0;\r
+ virtual bool Get(const std::string&, Array& value) = 0;\r
+\r
+ virtual int ColumnNum(const std::string&) = 0;\r
+ virtual const char* ColumnName(int) = 0;\r
+ virtual const char* ColumnAlias(int) = 0;\r
+ virtual const char* ColumnTable(int) = 0;\r
+ virtual SDT ColumnType(int) = 0;\r
+ virtual int ColumnSubtype(int) = 0;\r
+ virtual int ColumnSize(int) = 0;\r
+ virtual int ColumnScale(int) = 0;\r
+ virtual int Columns() = 0;\r
+\r
+ virtual SDT ParameterType(int) = 0;\r
+ virtual int ParameterSubtype(int) = 0;\r
+ virtual int ParameterSize(int) = 0;\r
+ virtual int ParameterScale(int) = 0;\r
+ virtual int Parameters() = 0;\r
+\r
+ virtual void Plan(std::string&) = 0;\r
+\r
+ virtual Database DatabasePtr() const = 0;\r
+ virtual Transaction TransactionPtr() const = 0;\r
+\r
+ virtual IStatement* AddRef() = 0;\r
+ virtual void Release() = 0;\r
+\r
+ virtual ~IStatement() { }\r
+\r
+ // DEPRECATED METHODS (WON'T BE AVAILABLE IN VERSIONS 3.x)\r
+ virtual bool Get(int, char*) = 0; // DEPRECATED\r
+ virtual bool Get(const std::string&, char*) = 0; // DEPRECATED\r
+ virtual bool Get(int, bool*) = 0; // DEPRECATED\r
+ virtual bool Get(const std::string&, bool*) = 0; // DEPRECATED\r
+ virtual bool Get(int, int16_t*) = 0; // DEPRECATED\r
+ virtual bool Get(const std::string&, int16_t*) = 0; // DEPRECATED\r
+ virtual bool Get(int, int32_t*) = 0; // DEPRECATED\r
+ virtual bool Get(const std::string&, int32_t*) = 0; // DEPRECATED\r
+ virtual bool Get(int, int64_t*) = 0; // DEPRECATED\r
+ virtual bool Get(const std::string&, int64_t*) = 0; // DEPRECATED\r
+ virtual bool Get(int, float*) = 0; // DEPRECATED\r
+ virtual bool Get(const std::string&, float*) = 0; // DEPRECATED\r
+ virtual bool Get(int, double*) = 0; // DEPRECATED\r
+ virtual bool Get(const std::string&, double*) = 0; // DEPRECATED\r
+ };\r
+ \r
+ class IEvents\r
+ {\r
+ public:\r
+ virtual void Add(const std::string&, EventInterface*) = 0;\r
+ virtual void Drop(const std::string&) = 0;\r
+ virtual void List(std::vector<std::string>&) = 0;\r
+ virtual void Clear() = 0; // Drop all events\r
+ virtual void Dispatch() = 0; // Dispatch events (calls handlers)\r
+\r
+ virtual Database DatabasePtr() const = 0;\r
+\r
+ virtual IEvents* AddRef() = 0;\r
+ virtual void Release() = 0;\r
+\r
+ virtual ~IEvents() { }\r
+ };\r
+ \r
+ /* Class EventInterface is merely a pure interface.\r
+ * It is _not_ implemented by IBPP. It is only a base class definition from\r
+ * which your own event interface classes have to derive from.\r
+ * Please read the reference guide at http://www.ibpp.org for more info. */\r
+\r
+ class EventInterface\r
+ {\r
+ public:\r
+ virtual void ibppEventHandler(Events, const std::string&, int) = 0;\r
+ virtual ~EventInterface() { }\r
+ };\r
+\r
+ // --- Factories ---\r
+ // These methods are the only way to get one of the above\r
+ // Interfaces. They are at the heart of how you program using IBPP. For\r
+ // instance, to get access to a database, you'll write code similar to this:\r
+ // {\r
+ // Database db = DatabaseFactory("server", "databasename",\r
+ // "user", "password");\r
+ // db->Connect();\r
+ // ...\r
+ // db->Disconnect();\r
+ // }\r
+\r
+ Service ServiceFactory(const std::string& ServerName,\r
+ const std::string& UserName, const std::string& UserPassword);\r
+\r
+ Database DatabaseFactory(const std::string& ServerName,\r
+ const std::string& DatabaseName, const std::string& UserName,\r
+ const std::string& UserPassword, const std::string& RoleName,\r
+ const std::string& CharSet, const std::string& CreateParams);\r
+\r
+ inline Database DatabaseFactory(const std::string& ServerName,\r
+ const std::string& DatabaseName, const std::string& UserName,\r
+ const std::string& UserPassword)\r
+ { return DatabaseFactory(ServerName, DatabaseName, UserName, UserPassword, "", "", ""); }\r
+\r
+ Transaction TransactionFactory(Database db, TAM am = amWrite,\r
+ TIL il = ilConcurrency, TLR lr = lrWait, TFF flags = TFF(0));\r
+\r
+ Statement StatementFactory(Database db, Transaction tr,\r
+ const std::string& sql);\r
+\r
+ inline Statement StatementFactory(Database db, Transaction tr)\r
+ { return StatementFactory(db, tr, ""); }\r
+\r
+ Blob BlobFactory(Database db, Transaction tr);\r
+ \r
+ Array ArrayFactory(Database db, Transaction tr);\r
+ \r
+ Events EventsFactory(Database db);\r
+\r
+ /* IBPP uses a self initialization system. Each time an object that may\r
+ * require the usage of the Interbase client C-API library is used, the\r
+ * library internal handling details are automatically initialized, if not\r
+ * already done. You can kick this initialization at the start of an\r
+ * application by calling IBPP::CheckVersion(). This is recommended, because\r
+ * IBPP::CheckVersion will assure you that YOUR code has been compiled\r
+ * against a compatible version of the library. */\r
+\r
+ bool CheckVersion(uint32_t);\r
+ int GDSVersion();\r
+ \r
+ /* On Win32 platform, ClientLibSearchPaths() allows to setup\r
+ * one or multiple additional paths (separated with a ';') where IBPP\r
+ * will look for the client library (before the default implicit search\r
+ * locations). This is usefull for applications distributed with a 'private'\r
+ * copy of Firebird, when the registry is useless to identify the location\r
+ * from where to attempt loading the fbclient.dll / gds32.dll.\r
+ * If called, this function must be called *early* by the application,\r
+ * before *any* other function or object methods of IBPP.\r
+ * Currently, this is a NO-OP on platforms other than Win32. */\r
+ \r
+ void ClientLibSearchPaths(const std::string&);\r
+\r
+ /* Finally, here are some date and time conversion routines used by IBPP and\r
+ * that may be helpful at the application level. They do not depend on\r
+ * anything related to Firebird/Interbase. Just a bonus. dtoi and itod\r
+ * return false on invalid parameters or out of range conversions. */\r
+\r
+ bool dtoi(int date, int* py, int* pm, int* pd);\r
+ bool itod(int* pdate, int year, int month, int day);\r
+ void ttoi(int itime, int* phour, int* pminute, int* psecond, int* ptt);\r
+ void itot(int* ptime, int hour, int minute, int second = 0, int tenthousandths = 0);\r
+\r
+}\r
+\r
+#endif\r
+\r
+//\r
+// EOF\r
+//\r