TerraLib 4.1
E:/Projetos_Primeiro_Semestre_2012/TerraView/terralib/src/terralib/drivers/Firebird/ibpp/core/_ibpp.h
Go to the documentation of this file.
00001 
00002 //
00003 //         File    : $Id: _ibpp.h 9672 2011-06-27 20:26:31Z frederico.bede $
00004 //         Subject : IBPP internal declarations
00005 //
00007 //
00008 //         (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)
00009 //
00010 //         The contents of this file are subject to the IBPP License (the "License");
00011 //         you may not use this file except in compliance with the License.  You may
00012 //         obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'
00013 //         file which must have been distributed along with this file.
00014 //
00015 //         This software, distributed under the License, is distributed on an "AS IS"
00016 //         basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the
00017 //         License for the specific language governing rights and limitations
00018 //         under the License.
00019 //
00021 //
00022 //         COMMENTS
00023 //
00024 //         * 'Internal declarations' means everything used to implement ibpp. This
00025 //           file and its contents is NOT needed by users of the library. All those
00026 //           declarations are wrapped in a namespace : 'ibpp_internals'.
00027 //         * Tabulations should be set every four characters when editing this file.
00028 //
00030 
00031 #ifndef __INTERNAL_IBPP_H__
00032 #define __INTERNAL_IBPP_H__
00033 
00034 #include "ibpp.h"
00035 
00036 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__DMC__)
00037 #define HAS_HDRSTOP
00038 #endif
00039 
00040 #if (defined(__GNUC__) && defined(IBPP_WINDOWS))
00041 //         Setting flags for ibase.h -- using GCC/Cygwin/MinGW on Win32
00042 #ifndef _MSC_VER
00043 #define _MSC_VER 1299
00044 #endif
00045 #ifndef _WIN32
00046 #define _WIN32   1
00047 #endif
00048 #endif
00049 
00050 #include "ibase.h"               // From Firebird 1.x or InterBase 6.x installation
00051 
00052 #if (defined(__GNUC__) && defined(IBPP_WINDOWS))
00053 //         UNSETTING flags used above for ibase.h -- Huge conflicts with libstdc++ !
00054 #undef _MSC_VER
00055 #undef _WIN32
00056 #endif
00057 
00058 #ifdef IBPP_WINDOWS
00059 #include <windows.h>
00060 #endif
00061 
00062 #include <limits>
00063 #include <cstring>
00064 #include <vector>
00065 #include <sstream>
00066 #include <cstdarg>
00067 #include <memory>
00068 #include <cstdlib>
00069 
00070 #ifdef _DEBUG
00071 #define ASSERTION(x)  {if (!(x)) {throw LogicExceptionImpl("ASSERTION", \
00072                                                                              "'"#x"' is not verified at %s, line %d", \
00073                                                                                         __FILE__, __LINE__);}}
00074 #else
00075 #define ASSERTION(x)  /* x */
00076 #endif
00077 
00078 // Fix to famous MSVC 6 variable scope bug
00079 #if defined(_MSC_VER) && (_MSC_VER < 1300)  // MSVC 6 should be < 1300
00080 #define for if(true)for
00081 #endif
00082 
00083 namespace ibpp_internals
00084 {
00085 
00086 enum flush_debug_stream_type {fds};
00087 
00088 #ifdef _DEBUG
00089 
00090 struct DebugStream : public std::stringstream
00091 {
00092            // next two operators fix some g++ and vc++ related problems
00093            std::ostream& operator<< (const char* p)
00094                       { static_cast<std::stringstream&>(*this)<< p; return *this; }
00095 
00096            std::ostream& operator<< (const std::string& p)
00097                       { static_cast<std::stringstream&>(*this)<< p; return *this; }
00098 
00099            DebugStream& operator=(const DebugStream&) {return *this;}
00100            DebugStream(const DebugStream&) {}
00101            DebugStream() {}
00102 };
00103 std::ostream& operator<< (std::ostream& a, flush_debug_stream_type);
00104 
00105 #else
00106 
00107 struct DebugStream
00108 {
00109            template<class T> DebugStream& operator<< (const T&) { return *this; }
00110            // for manipulators
00111            DebugStream& operator<< (std::ostream&(*)(std::ostream&)) { return *this; }
00112 };
00113 
00114 #endif     // _DEBUG
00115 
00116 class DatabaseImpl;
00117 class TransactionImpl;
00118 class StatementImpl;
00119 class BlobImpl;
00120 class ArrayImpl;
00121 class EventsImpl;
00122 
00123 //         Native data types
00124 typedef enum {ivArray, ivBlob, ivDate, ivTime, ivTimestamp, ivString,
00125                                  ivInt16, ivInt32, ivInt64, ivFloat, ivDouble,
00126                                  ivBool, ivDBKey, ivByte} IITYPE;
00127 
00128 //
00129 //         Those are the Interbase C API prototypes that we use
00130 //         Taken 'asis' from IBASE.H, prefix 'isc_' replaced with 'proto_',
00131 //         and 'typedef' preprended...
00132 //
00133 
00134 typedef ISC_STATUS ISC_EXPORT proto_create_database (ISC_STATUS *,
00135                                                            short,
00136                                                            char *,
00137                                                            isc_db_handle *,
00138                                                            short,
00139                                                            char *,
00140                                                            short);
00141 
00142 typedef ISC_STATUS ISC_EXPORT proto_attach_database (ISC_STATUS *,
00143                                                            short,
00144                                                            char *,
00145                                                            isc_db_handle *,
00146                                                            short,
00147                                                            char *);
00148 
00149 typedef ISC_STATUS  ISC_EXPORT proto_detach_database (ISC_STATUS *,
00150                                                            isc_db_handle *);
00151 
00152 typedef ISC_STATUS  ISC_EXPORT proto_drop_database (ISC_STATUS *,
00153                                                          isc_db_handle *);
00154 
00155 typedef ISC_STATUS  ISC_EXPORT proto_database_info (ISC_STATUS *,
00156                                                          isc_db_handle *,
00157                                                          short,
00158                                                          char *,
00159                                                          short,
00160                                                          char *);
00161 
00162 typedef ISC_STATUS  ISC_EXPORT proto_dsql_execute_immediate (ISC_STATUS *,
00163                                                                      isc_db_handle *,
00164                                                                      isc_tr_handle *,
00165                                                                      unsigned short,
00166                                                                      char *,
00167                                                                      unsigned short,
00168                                                                      XSQLDA *);
00169 
00170 typedef ISC_STATUS  ISC_EXPORT proto_open_blob2 (ISC_STATUS *,
00171                                                    isc_db_handle *,
00172                                                    isc_tr_handle *,
00173                                                    isc_blob_handle *,
00174                                                    ISC_QUAD *,
00175                                                    short,
00176                                                    char *);
00177 
00178 typedef ISC_STATUS  ISC_EXPORT proto_create_blob2 (ISC_STATUS *,
00179                                                        isc_db_handle *,
00180                                                        isc_tr_handle *,
00181                                                        isc_blob_handle *,
00182                                                        ISC_QUAD *,
00183                                                        short,
00184                                                        char *);
00185 
00186 typedef ISC_STATUS  ISC_EXPORT proto_close_blob (ISC_STATUS *,
00187                                                    isc_blob_handle *);
00188 
00189 typedef ISC_STATUS  ISC_EXPORT proto_cancel_blob (ISC_STATUS *,
00190                                                     isc_blob_handle *);
00191 
00192 typedef ISC_STATUS  ISC_EXPORT proto_get_segment (ISC_STATUS *,
00193                                                     isc_blob_handle *,
00194                                                     unsigned short *,
00195                                                     unsigned short,
00196                                                     char *);
00197 
00198 typedef ISC_STATUS  ISC_EXPORT proto_put_segment (ISC_STATUS *,
00199                                                        isc_blob_handle *,
00200                                                        unsigned short,
00201                                                        char *);
00202 
00203 typedef ISC_STATUS  ISC_EXPORT proto_blob_info (ISC_STATUS *,
00204                                                   isc_blob_handle *,
00205                                                   short,
00206                                                   char *,
00207                                                   short,
00208                                                   char *);
00209 
00210 typedef ISC_STATUS  ISC_EXPORT proto_array_lookup_bounds (ISC_STATUS *,
00211                                                                   isc_db_handle *,
00212                                                                   isc_tr_handle *,
00213                                                                   char *,
00214                                                                   char *,
00215                                                                   ISC_ARRAY_DESC *);
00216 
00217 typedef ISC_STATUS  ISC_EXPORT proto_array_get_slice (ISC_STATUS *,
00218                                                            isc_db_handle *,
00219                                                            isc_tr_handle *,
00220                                                            ISC_QUAD *,
00221                                                            ISC_ARRAY_DESC *,
00222                                                            void *,
00223                                                            ISC_LONG *);
00224 
00225 typedef ISC_STATUS  ISC_EXPORT proto_array_put_slice (ISC_STATUS *,
00226                                                            isc_db_handle *,
00227                                                            isc_tr_handle *,
00228                                                            ISC_QUAD *,
00229                                                            ISC_ARRAY_DESC *,
00230                                                            void *,
00231                                                            ISC_LONG *);
00232 
00233 typedef ISC_LONG    ISC_EXPORT proto_vax_integer (char *,
00234                                                        short);
00235 
00236 typedef ISC_LONG    ISC_EXPORT proto_sqlcode (ISC_STATUS *);
00237 
00238 typedef void        ISC_EXPORT proto_sql_interprete (short,
00239                                                           char *,
00240                                                           short);
00241 
00242 typedef ISC_STATUS  ISC_EXPORT proto_interprete (char *,
00243                                                    ISC_STATUS * *);
00244 
00245 typedef ISC_STATUS  ISC_EXPORT proto_que_events (ISC_STATUS *,
00246                                                    isc_db_handle *,
00247                                                    ISC_LONG *,
00248                                                    short,
00249                                                    char *,
00250                                                    isc_callback,
00251                                                    void *);
00252 
00253 typedef ISC_STATUS  ISC_EXPORT proto_cancel_events (ISC_STATUS *,
00254                                                          isc_db_handle *,
00255                                                          ISC_LONG *);
00256 
00257 typedef ISC_STATUS  ISC_EXPORT proto_start_multiple (ISC_STATUS *,
00258                                                           isc_tr_handle *,
00259                                                           short,
00260                                                           void *);
00261 
00262 typedef ISC_STATUS  ISC_EXPORT proto_commit_transaction (ISC_STATUS *,
00263                                                               isc_tr_handle *);
00264 
00265 typedef ISC_STATUS  ISC_EXPORT proto_commit_retaining (ISC_STATUS *,
00266                                                             isc_tr_handle *);
00267 
00268 typedef ISC_STATUS  ISC_EXPORT proto_rollback_transaction (ISC_STATUS *,
00269                                                                    isc_tr_handle *);
00270 
00271 typedef ISC_STATUS  ISC_EXPORT proto_rollback_retaining (ISC_STATUS *,
00272                                                                    isc_tr_handle *);
00273 
00275 typedef ISC_STATUS  ISC_EXPORT proto_dsql_allocate_statement (ISC_STATUS *,
00276                                                                       isc_db_handle *,
00277                                                                       isc_stmt_handle *);
00278 
00279 typedef ISC_STATUS  ISC_EXPORT proto_dsql_describe (ISC_STATUS *,
00280                                                          isc_stmt_handle *,
00281                                                          unsigned short,
00282                                                          XSQLDA *);
00283 
00284 typedef ISC_STATUS  ISC_EXPORT proto_dsql_describe_bind (ISC_STATUS *,
00285                                                               isc_stmt_handle *,
00286                                                               unsigned short,
00287                                                               XSQLDA *);
00288 
00289 typedef ISC_STATUS  ISC_EXPORT proto_dsql_execute (ISC_STATUS *,
00290                                                         isc_tr_handle *,
00291                                                         isc_stmt_handle *,
00292                                                         unsigned short,
00293                                                         XSQLDA *);
00294 
00295 typedef ISC_STATUS  ISC_EXPORT proto_dsql_execute2 (ISC_STATUS *,
00296                                                          isc_tr_handle *,
00297                                                          isc_stmt_handle *,
00298                                                          unsigned short,
00299                                                          XSQLDA *,
00300                                                          XSQLDA *);
00301 
00302 typedef ISC_STATUS  ISC_EXPORT proto_dsql_fetch (ISC_STATUS *,
00303                                                    isc_stmt_handle *,
00304                                                    unsigned short,
00305                                                    XSQLDA *);
00306 
00307 typedef ISC_STATUS  ISC_EXPORT proto_dsql_free_statement (ISC_STATUS *,
00308                                                                   isc_stmt_handle *,
00309                                                                   unsigned short);
00310 
00311 typedef ISC_STATUS  ISC_EXPORT proto_dsql_prepare (ISC_STATUS *,
00312                                                         isc_tr_handle *,
00313                                                         isc_stmt_handle *,
00314                                                         unsigned short,
00315                                                         char *,
00316                                                         unsigned short,
00317                                                         XSQLDA *);
00318 
00319 typedef ISC_STATUS  ISC_EXPORT proto_dsql_set_cursor_name (ISC_STATUS *,
00320                                                                    isc_stmt_handle *,
00321                                                                    char *,
00322                                                                    unsigned short);
00323 
00324 typedef ISC_STATUS  ISC_EXPORT proto_dsql_sql_info (ISC_STATUS *,
00325                                                          isc_stmt_handle *,
00326                                                          short,
00327                                                          char *,
00328                                                          short,
00329                                                          char *);
00330 
00331 typedef void        ISC_EXPORT proto_decode_date (ISC_QUAD *,
00332                                                        void *);
00333 
00334 typedef void        ISC_EXPORT proto_encode_date (void *,
00335                                                        ISC_QUAD *);
00336 
00337 typedef int                                 ISC_EXPORT proto_add_user (ISC_STATUS *, USER_SEC_DATA *);
00338 typedef int                                 ISC_EXPORT proto_delete_user (ISC_STATUS *, USER_SEC_DATA *);
00339 typedef int                                 ISC_EXPORT proto_modify_user (ISC_STATUS *, USER_SEC_DATA *);
00340 
00341 //
00342 //         Those API are only available in versions 6.x of the GDS32.DLL
00343 //
00344 
00345 typedef ISC_STATUS  ISC_EXPORT proto_service_attach (ISC_STATUS *,
00346                                                           unsigned short,
00347                                                           char *,
00348                                                           isc_svc_handle *,
00349                                                           unsigned short,
00350                                                           char *);
00351 
00352 typedef ISC_STATUS  ISC_EXPORT proto_service_detach (ISC_STATUS *,
00353                                                           isc_svc_handle *);
00354 
00355 typedef ISC_STATUS  ISC_EXPORT proto_service_query (ISC_STATUS *,
00356                                                          isc_svc_handle *,
00357                                                       isc_resv_handle *,
00358                                                          unsigned short,
00359                                                          char *,
00360                                                          unsigned short,
00361                                                          char *,
00362                                                          unsigned short,
00363                                                          char *);
00364 
00365 typedef ISC_STATUS ISC_EXPORT proto_service_start (ISC_STATUS *,
00366                                                         isc_svc_handle *,
00367                                              isc_resv_handle *,
00368                                                         unsigned short,
00369                                                         char*);
00370 
00371 typedef void        ISC_EXPORT proto_decode_sql_date (ISC_DATE *,
00372                                                        void *);
00373 
00374 typedef void        ISC_EXPORT proto_decode_sql_time (ISC_TIME *,
00375                                                        void *);
00376 
00377 typedef void        ISC_EXPORT proto_decode_timestamp (ISC_TIMESTAMP *,
00378                                                        void *);
00379 
00380 typedef void        ISC_EXPORT proto_encode_sql_date (void *,
00381                                                        ISC_DATE *);
00382 
00383 typedef void        ISC_EXPORT proto_encode_sql_time (void *,
00384                                                        ISC_TIME *);
00385 
00386 typedef void        ISC_EXPORT proto_encode_timestamp (void *,
00387                                                        ISC_TIMESTAMP *);
00388 
00389 //
00390 //         Internal binding structure to the GDS32 DLL
00391 //
00392 
00393 struct GDS
00394 {
00395            // Attributes
00396            bool mReady;
00397            int mGDSVersion;                 // Version of the GDS32.DLL (50 for 5.0, 60 for 6.0)
00398 
00399 #ifdef IBPP_WINDOWS
00400            HMODULE mHandle;                            // The GDS32.DLL HMODULE
00401            std::string mSearchPaths;        // Optional additional search paths
00402 #endif
00403 
00404            GDS* Call();
00405 
00406            // GDS32 Entry Points
00407            proto_create_database*                                 m_create_database;
00408            proto_attach_database*                                 m_attach_database;
00409            proto_detach_database*                                 m_detach_database;
00410            proto_drop_database*                        m_drop_database;
00411            proto_database_info*                        m_database_info;
00412            proto_dsql_execute_immediate*    m_dsql_execute_immediate;
00413            proto_open_blob2*                                      m_open_blob2;
00414            proto_create_blob2*                                    m_create_blob2;
00415            proto_close_blob*                                      m_close_blob;
00416            proto_cancel_blob*                                     m_cancel_blob;
00417            proto_get_segment*                                     m_get_segment;
00418            proto_put_segment*                                     m_put_segment;
00419            proto_blob_info*                                       m_blob_info;
00420            proto_array_lookup_bounds*                  m_array_lookup_bounds;
00421            proto_array_get_slice*                                 m_array_get_slice;
00422            proto_array_put_slice*                                 m_array_put_slice;
00423 
00424            proto_vax_integer*                                     m_vax_integer;
00425            proto_sqlcode*                                                    m_sqlcode;
00426            proto_sql_interprete*                       m_sql_interprete;
00427            proto_interprete*                                      m_interprete;
00428            proto_que_events*                                      m_que_events;
00429            proto_cancel_events*                        m_cancel_events;
00430            proto_start_multiple*                       m_start_multiple;
00431            proto_commit_transaction*                   m_commit_transaction;
00432            proto_commit_retaining*                                m_commit_retaining;
00433            proto_rollback_transaction*                 m_rollback_transaction;
00434            proto_rollback_retaining*                   m_rollback_retaining;
00435            proto_dsql_allocate_statement*   m_dsql_allocate_statement;
00436            proto_dsql_describe*                        m_dsql_describe;
00437            proto_dsql_describe_bind*                   m_dsql_describe_bind;
00438            proto_dsql_prepare*                                    m_dsql_prepare;
00439            proto_dsql_execute*                                    m_dsql_execute;
00440            proto_dsql_execute2*                        m_dsql_execute2;
00441            proto_dsql_fetch*                                      m_dsql_fetch;
00442            proto_dsql_free_statement*                  m_dsql_free_statement;
00443            proto_dsql_set_cursor_name*                 m_dsql_set_cursor_name;
00444            proto_dsql_sql_info*                        m_dsql_sql_info;
00445            //proto_decode_date*                                   m_decode_date;
00446            //proto_encode_date*                                   m_encode_date;
00447            //proto_add_user*                                                 m_add_user;
00448            //proto_delete_user*                                   m_delete_user;
00449            //proto_modify_user*                                   m_modify_user;
00450 
00451            proto_service_attach*                       m_service_attach;
00452            proto_service_detach*                       m_service_detach;
00453            proto_service_start*                        m_service_start;
00454            proto_service_query*                        m_service_query;
00455            //proto_decode_sql_date*                               m_decode_sql_date;
00456            //proto_decode_sql_time*                               m_decode_sql_time;
00457            //proto_decode_timestamp*                              m_decode_timestamp;
00458            //proto_encode_sql_date*                               m_encode_sql_date;
00459            //proto_encode_sql_time*                               m_encode_sql_time;
00460            //proto_encode_timestamp*                              m_encode_timestamp;
00461 
00462            // Constructor (No need for a specific destructor)
00463            GDS()
00464            {
00465                       mReady = false;
00466                       mGDSVersion = 0;
00467 #ifdef IBPP_WINDOWS
00468                       mHandle = 0;
00469 #endif
00470            };
00471 };
00472 
00473 extern GDS gds;
00474 
00475 //
00476 //         Service Parameter Block (used to define a service)
00477 //
00478 
00479 class SPB
00480 {
00481            static const int BUFFERINCR;
00482 
00483            char* mBuffer;                                         // Dynamically allocated SPB structure
00484            int mSize;                                             // Its used size in bytes
00485            int mAlloc;                                                       // Its allocated size in bytes
00486 
00487            void Grow(int needed);                      // Alloc or grow the mBuffer
00488 
00489 public:
00490            void Insert(char);                          // Insert a single byte code
00491            void InsertString(char, int, const char*);  // Insert a string, len can be defined as 1 or 2 bytes
00492            void InsertByte(char type, char data);
00493            void InsertQuad(char type, int32_t data);
00494            void Reset();                               // Clears the SPB
00495            char* Self() { return mBuffer; }
00496            short Size() { return (short)mSize; }
00497 
00498            SPB() : mBuffer(0), mSize(0), mAlloc(0) { }
00499            ~SPB() { Reset(); }
00500 };
00501 
00502 //
00503 //         Database Parameter Block (used to define a database)
00504 //
00505 
00506 class DPB
00507 {
00508            static const int BUFFERINCR;
00509 
00510            char* mBuffer;                                         // Dynamically allocated DPB structure
00511            int mSize;                                             // Its used size in bytes
00512            int mAlloc;                                                       // Its allocated size in bytes
00513 
00514            void Grow(int needed);                      // Allocate or grow the mBuffer, so that
00515                                                                                         // 'needed' bytes can be written (at least)
00516 
00517 public:
00518            void Insert(char, const char*);  // Insert a new char* 'cluster'
00519            void Insert(char, int16_t);                 // Insert a new int16_t 'cluster'
00520            void Insert(char, bool);                    // Insert a new bool 'cluster'
00521            void Insert(char, char);                    // Insert a new byte 'cluster'
00522            void Reset();                                          // Clears the DPB
00523            char* Self() { return mBuffer; }
00524            short Size() { return (short)mSize; }
00525 
00526            DPB() : mBuffer(0), mSize(0), mAlloc(0) { }
00527            ~DPB() { Reset(); }
00528 };
00529 
00530 //
00531 //         Transaction Parameter Block (used to define a transaction)
00532 //
00533 
00534 class TPB
00535 {
00536            static const int BUFFERINCR;
00537 
00538            char* mBuffer;                                                    // Dynamically allocated TPB structure
00539            int mSize;                                                        // Its used size in bytes
00540            int mAlloc;                                                                  // Its allocated size
00541 
00542            void Grow(int needed);                                 // Alloc or re-alloc the mBuffer
00543 
00544 public:
00545            void Insert(char);                                     // Insert a flag item
00546            void Insert(const std::string& data); // Insert a string (typically table name)
00547            void Reset();                                          // Clears the TPB
00548            char* Self() { return mBuffer; }
00549            int Size() { return mSize; }
00550 
00551            TPB() : mBuffer(0), mSize(0), mAlloc(0) { }
00552            ~TPB() { Reset(); }
00553 };
00554 
00555 //
00556 //         Used to receive (and process) a results buffer in various API calls
00557 //
00558 
00559 class RB
00560 {
00561            char* mBuffer;
00562            int mSize;
00563 
00564            char* FindToken(char token);
00565            char* FindToken(char token, char subtoken);
00566 
00567 public:
00568            void Reset();
00569            int GetValue(char token);
00570            int GetCountValue(char token);
00571            int GetValue(char token, char subtoken);
00572            bool GetBool(char token);
00573            int GetString(char token, std::string& data);
00574 
00575            char* Self() { return mBuffer; }
00576            short Size() { return (short)mSize; }
00577 
00578            RB();
00579            RB(int Size);
00580            ~RB();
00581 };
00582 
00583 //
00584 //         Used to receive status info from API calls
00585 //
00586 
00587 class IBS
00588 {
00589            mutable ISC_STATUS mVector[20];
00590            mutable std::string mMessage;
00591 
00592 public:
00593            ISC_STATUS* Self() { return mVector; }
00594            bool Errors() { return (mVector[0] == 1 && mVector[1] > 0) ? true : false; }
00595            const char* ErrorMessage() const;
00596            int SqlCode() const;
00597            int EngineCode() const { return (mVector[0] == 1) ? (int)mVector[1] : 0; }
00598            void Reset();
00599 
00600            IBS();
00601            IBS(IBS&); // Copy Constructor
00602            ~IBS();
00603 };
00604 
00606 //
00607 //         Implementation of the "hidden" classes associated with their public
00608 //         counterparts. Their private data and methods can freely change without
00609 //         breaking the compatibility of the DLL. If they receive new public methods,
00610 //         and those methods are reflected in the public class, then the compatibility
00611 //         is broken.
00612 //
00614 
00615 //
00616 // Hidden implementation of Exception classes.
00617 //
00618 
00619 /*
00620                          std::exception
00621                                 |
00622                          IBPP::Exception
00623                        /                 \
00624                       /                   \
00625   IBPP::LogicException    ExceptionBase    IBPP::SQLException
00626         |        \         /   |     \     /
00627         |   LogicExceptionImpl |   SQLExceptionImpl
00628         |                      |
00629     IBPP::WrongType            |
00630                \               |
00631               IBPP::WrongTypeImpl
00632 */
00633 
00634 class ExceptionBase
00635 {
00636            //         (((((((( OBJECT INTERNALS ))))))))
00637 
00638 protected:
00639            std::string mContext;                                  // Exception context ("IDatabase::Drop")
00640            std::string mWhat;                                     // Full formatted message
00641 
00642            void buildErrorMessage(const char* message);
00643            void raise(const std::string& context, const char* message, va_list argptr);
00644 
00645 public:
00646            // The following constructors are small and could be inlined, but for object
00647            // code compacity of the library it is much better to have them non-inlined.
00648            // The amount of code generated by compilers for a throw is well-enough.
00649 
00650            ExceptionBase() throw();
00651            ExceptionBase(const ExceptionBase& copied) throw();
00652            ExceptionBase& operator=(const ExceptionBase& copied) throw();
00653            ExceptionBase(const std::string& context, const char* message = 0, ...) throw();
00654 
00655            virtual ~ExceptionBase() throw();
00656 
00657            //         (((((((( OBJECT INTERFACE ))))))))
00658 
00659     virtual const char* Origin() const throw();
00660     virtual const char* ErrorMessage() const throw();
00661            virtual const char* what() const throw();
00662 };
00663 
00664 class LogicExceptionImpl : public IBPP::LogicException, public ExceptionBase
00665 {
00666            //         (((((((( OBJECT INTERNALS ))))))))
00667 
00668 public:
00669            // The following constructors are small and could be inlined, but for object
00670            // code compacity of the library it is much better to have them non-inlined.
00671            // The amount of code generated by compilers for a throw is well-enough.
00672 
00673            LogicExceptionImpl() throw();
00674            LogicExceptionImpl(const LogicExceptionImpl& copied) throw();
00675            LogicExceptionImpl& operator=(const LogicExceptionImpl& copied) throw();
00676            LogicExceptionImpl(const std::string& context, const char* message = 0, ...) throw();
00677 
00678            virtual ~LogicExceptionImpl() throw ();
00679 
00680            //         (((((((( OBJECT INTERFACE ))))))))
00681            //
00682            //         The object public interface is partly implemented by inheriting from
00683            //         the ExceptionBase class.
00684 
00685 public:
00686     virtual const char* Origin() const throw();
00687     virtual const char* ErrorMessage() const throw();
00688            virtual const char* what() const throw();
00689 };
00690 
00691 class SQLExceptionImpl : public IBPP::SQLException, public ExceptionBase
00692 {
00693            //         (((((((( OBJECT INTERNALS ))))))))
00694 
00695 private:
00696            int mSqlCode;
00697            int mEngineCode;
00698 
00699 public:
00700            // The following constructors are small and could be inlined, but for object
00701            // code compacity of the library it is much better to have them non-inlined.
00702            // The amount of code generated by compilers for a throw is well-enough.
00703 
00704            SQLExceptionImpl() throw();
00705            SQLExceptionImpl(const SQLExceptionImpl& copied) throw();
00706            SQLExceptionImpl& operator=(const SQLExceptionImpl& copied) throw();
00707            SQLExceptionImpl(const IBS& status, const std::string& context,
00708                                                                   const char* message = 0, ...) throw();
00709 
00710            virtual ~SQLExceptionImpl() throw ();
00711 
00712            //         (((((((( OBJECT INTERFACE ))))))))
00713            //
00714            //         The object public interface is partly implemented by inheriting from
00715            //         the ExceptionBase class.
00716 
00717 public:
00718     virtual const char* Origin() const throw();
00719     virtual const char* ErrorMessage() const throw();
00720            virtual const char* what() const throw();
00721            virtual int SqlCode() const throw();
00722            virtual int EngineCode() const throw();
00723 };
00724 
00725 class WrongTypeImpl : public IBPP::WrongType, public ExceptionBase
00726 {
00727            //         (((((((( OBJECT INTERNALS ))))))))
00728 
00729 public:
00730            // The following constructors are small and could be inlined, but for object
00731            // code compacity of the library it is much better to have them non-inlined.
00732            // The amount of code generated by compilers for a throw is well-enough.
00733 
00734            WrongTypeImpl() throw();
00735            WrongTypeImpl(const WrongTypeImpl& copied) throw();
00736            WrongTypeImpl& operator=(const WrongTypeImpl& copied) throw();
00737            WrongTypeImpl(const std::string& context, int sqlType, IITYPE varType,
00738                                                        const char* message = 0, ...) throw();
00739 
00740            virtual ~WrongTypeImpl() throw ();
00741 
00742            //         (((((((( OBJECT INTERFACE ))))))))
00743            //
00744            //         The object public interface is partly implemented by inheriting from
00745            //         the ExceptionBase class.
00746 
00747 public:
00748     virtual const char* Origin() const throw();
00749     virtual const char* ErrorMessage() const throw();
00750            virtual const char* what() const throw();
00751 };
00752 
00753 class ServiceImpl : public IBPP::IService
00754 {
00755            //         (((((((( OBJECT INTERNALS ))))))))
00756 
00757 private:
00758            int mRefCount;                                         // Reference counter
00759     isc_svc_handle mHandle;                 // InterBase API Service Handle
00760            std::string mServerName;         // Nom du serveur
00761     std::string mUserName;                  // Nom de l'utilisateur
00762     std::string mUserPassword;   // Mot de passe de l'utilisateur
00763            std::string mWaitMessage;        // Progress message returned by WaitMsg()
00764 
00765            isc_svc_handle* GetHandlePtr() { return &mHandle; }
00766            void SetServerName(const char*);
00767            void SetUserName(const char*);
00768            void SetUserPassword(const char*);
00769 
00770 public:
00771            isc_svc_handle GetHandle() { return mHandle; }
00772 
00773            ServiceImpl(const std::string& ServerName, const std::string& UserName,
00774                                                        const std::string& UserPassword);
00775     ~ServiceImpl();
00776 
00777            //         (((((((( OBJECT INTERFACE ))))))))
00778 
00779 public:
00780     void Connect();
00781            bool Connected() { return mHandle == 0 ? false : true; }
00782            void Disconnect();
00783 
00784            void GetVersion(std::string& version);
00785 
00786            void AddUser(const IBPP::User&);
00787            void GetUser(IBPP::User&);
00788            void GetUsers(std::vector<IBPP::User>&);
00789            void ModifyUser(const IBPP::User&);
00790            void RemoveUser(const std::string& username);
00791 
00792            void SetPageBuffers(const std::string& dbfile, int buffers);
00793            void SetSweepInterval(const std::string& dbfile, int sweep);
00794            void SetSyncWrite(const std::string& dbfile, bool);
00795            void SetReadOnly(const std::string& dbfile, bool);
00796            void SetReserveSpace(const std::string& dbfile, bool);
00797 
00798            void Shutdown(const std::string& dbfile, IBPP::DSM mode, int sectimeout);
00799            void Restart(const std::string& dbfile);
00800            void Sweep(const std::string& dbfile);
00801            void Repair(const std::string& dbfile, IBPP::RPF flags);
00802 
00803            void StartBackup(const std::string& dbfile, const std::string& bkfile,
00804                       IBPP::BRF flags = IBPP::BRF(0));
00805            void StartRestore(const std::string& bkfile, const std::string& dbfile,
00806                       int pagesize, IBPP::BRF flags = IBPP::BRF(0));
00807 
00808            const char* WaitMsg();
00809            void Wait();
00810 
00811            IBPP::IService* AddRef();
00812            void Release();
00813 };
00814 
00815 class DatabaseImpl : public IBPP::IDatabase
00816 {
00817            //         (((((((( OBJECT INTERNALS ))))))))
00818 
00819            int mRefCount;                                         // Reference counter
00820     isc_db_handle mHandle;                  // InterBase API Session Handle
00821            std::string mServerName;         // Server name
00822     std::string mDatabaseName;   // Database name (path/file)
00823     std::string mUserName;                  // User name
00824     std::string mUserPassword;   // User password
00825     std::string mRoleName;                  // Role used for the duration of the connection
00826            std::string mCharSet;            // Character Set used for the connection
00827            std::string mCreateParams;       // Other parameters (creation only)
00828 
00829            int mDialect;                                                                           // 1 if IB5, 1 or 3 if IB6/FB1
00830            std::vector<TransactionImpl*> mTransactions;// Table of Transaction*
00831            std::vector<StatementImpl*> mStatements;// Table of Statement*
00832            std::vector<BlobImpl*> mBlobs;                         // Table of Blob*
00833            std::vector<ArrayImpl*> mArrays;            // Table of Array*
00834            std::vector<EventsImpl*> mEvents;                      // Table of Events*
00835 
00836 public:
00837            isc_db_handle* GetHandlePtr() { return &mHandle; }
00838            isc_db_handle GetHandle() { return mHandle; }
00839 
00840            void AttachTransactionImpl(TransactionImpl*);
00841            void DetachTransactionImpl(TransactionImpl*);
00842            void AttachStatementImpl(StatementImpl*);
00843            void DetachStatementImpl(StatementImpl*);
00844            void AttachBlobImpl(BlobImpl*);
00845            void DetachBlobImpl(BlobImpl*);
00846            void AttachArrayImpl(ArrayImpl*);
00847            void DetachArrayImpl(ArrayImpl*);
00848            void AttachEventsImpl(EventsImpl*);
00849            void DetachEventsImpl(EventsImpl*);
00850 
00851            DatabaseImpl(const std::string& ServerName, const std::string& DatabaseName,
00852                                             const std::string& UserName, const std::string& UserPassword,
00853                                             const std::string& RoleName, const std::string& CharSet,
00854                                             const std::string& CreateParams);
00855     ~DatabaseImpl();
00856 
00857            //         (((((((( OBJECT INTERFACE ))))))))
00858 
00859 public:
00860            const char* ServerName() const              { return mServerName.c_str(); }
00861            const char* DatabaseName() const { return mDatabaseName.c_str(); }
00862            const char* Username() const                { return mUserName.c_str(); }
00863            const char* UserPassword() const { return mUserPassword.c_str(); }
00864            const char* RoleName() const                { return mRoleName.c_str(); }
00865            const char* CharSet() const                            { return mCharSet.c_str(); }
00866            const char* CreateParams() const { return mCreateParams.c_str(); }
00867 
00868            void Info(int* ODSMajor, int* ODSMinor,
00869                       int* PageSize, int* Pages, int* Buffers, int* Sweep,
00870                       bool* SyncWrites, bool* Reserve);
00871            void Statistics(int* Fetches, int* Marks, int* Reads, int* Writes);
00872            void Counts(int* Insert, int* Update, int* Delete,
00873                       int* ReadIdx, int* ReadSeq);
00874            void Users(std::vector<std::string>& users);
00875            int Dialect() { return mDialect; }
00876 
00877     void Create(int dialect);
00878            void Connect();
00879            bool Connected() { return mHandle == 0 ? false : true; }
00880            void Inactivate();
00881            void Disconnect();
00882     void Drop();
00883 
00884            IBPP::IDatabase* AddRef();
00885            void Release();
00886 };
00887 
00888 class TransactionImpl : public IBPP::ITransaction
00889 {
00890            //         (((((((( OBJECT INTERNALS ))))))))
00891 
00892 private:
00893            int mRefCount;                                                    // Reference counter
00894     isc_tr_handle mHandle;                             // Transaction InterBase
00895 
00896            std::vector<DatabaseImpl*> mDatabases;      // Tableau de IDatabase*
00897            std::vector<StatementImpl*> mStatements;    // Tableau de IStatement*
00898            std::vector<BlobImpl*> mBlobs;                                    // Tableau de IBlob*
00899            std::vector<ArrayImpl*> mArrays;                       // Tableau de Array*
00900            std::vector<TPB*> mTPBs;                                                     // Tableau de TPB
00901 
00902            void Init();                                // A usage exclusif des constructeurs
00903 
00904 public:
00905            isc_tr_handle* GetHandlePtr() { return &mHandle; }
00906            isc_tr_handle GetHandle() { return mHandle; }
00907 
00908            void AttachStatementImpl(StatementImpl*);
00909            void DetachStatementImpl(StatementImpl*);
00910            void AttachBlobImpl(BlobImpl*);
00911            void DetachBlobImpl(BlobImpl*);
00912            void AttachArrayImpl(ArrayImpl*);
00913            void DetachArrayImpl(ArrayImpl*);
00914     void AttachDatabaseImpl(DatabaseImpl* dbi, IBPP::TAM am = IBPP::amWrite,
00915                                  IBPP::TIL il = IBPP::ilConcurrency,
00916                                  IBPP::TLR lr = IBPP::lrWait, IBPP::TFF flags = IBPP::TFF(0));
00917     void DetachDatabaseImpl(DatabaseImpl* dbi);
00918 
00919            TransactionImpl(DatabaseImpl* db, IBPP::TAM am = IBPP::amWrite,
00920                       IBPP::TIL il = IBPP::ilConcurrency,
00921                       IBPP::TLR lr = IBPP::lrWait, IBPP::TFF flags = IBPP::TFF(0));
00922     ~TransactionImpl();
00923 
00924            //         (((((((( OBJECT INTERFACE ))))))))
00925 
00926 public:
00927     void AttachDatabase(IBPP::Database db, IBPP::TAM am = IBPP::amWrite,
00928                                  IBPP::TIL il = IBPP::ilConcurrency,
00929                                  IBPP::TLR lr = IBPP::lrWait, IBPP::TFF flags = IBPP::TFF(0));
00930     void DetachDatabase(IBPP::Database db);
00931            void AddReservation(IBPP::Database db,
00932                                  const std::string& table, IBPP::TTR tr);
00933 
00934     void Start();
00935            bool Started() { return mHandle == 0 ? false : true; }
00936     void Commit();
00937     void Rollback();
00938     void CommitRetain();
00939            void RollbackRetain();
00940 
00941            IBPP::ITransaction* AddRef();
00942            void Release();
00943 };
00944 
00945 class RowImpl : public IBPP::IRow
00946 {
00947            //         (((((((( OBJECT INTERNALS ))))))))
00948 
00949 private:
00950            int mRefCount;                                                    // Reference counter
00951 
00952            XSQLDA* mDescrArea;                                    // XSQLDA descriptor itself
00953            std::vector<double> mNumerics;   // Temporary storage for Numerics
00954            std::vector<float> mFloats;                 // Temporary storage for Floats
00955            std::vector<int64_t> mInt64s;    // Temporary storage for 64 bits
00956            std::vector<int32_t> mInt32s;    // Temporary storage for 32 bits
00957            std::vector<int16_t> mInt16s;    // Temporary storage for 16 bits
00958            std::vector<char> mBools;                   // Temporary storage for Bools
00959            std::vector<std::string> mStrings;          // Temporary storage for Strings
00960            std::vector<bool> mUpdated;                 // Which columns where updated (Set()) ?
00961 
00962            int mDialect;                                                     // Related database dialect
00963            DatabaseImpl* mDatabase;                    // Related Database (important for Blobs, ...)
00964            TransactionImpl* mTransaction;   // Related Transaction (same remark)
00965 
00966            void SetValue(int, IITYPE, const void* value, int = 0);
00967            void* GetValue(int, IITYPE, void* = 0);
00968 
00969 public:
00970            void Free();
00971            short AllocatedSize() { return mDescrArea->sqln; }
00972            void Resize(int n);
00973            void AllocVariables();
00974            bool MissingValues();            // Returns wether one of the mMissing[] is true
00975            XSQLDA* Self() { return mDescrArea; }
00976 
00977            RowImpl& operator=(const RowImpl& copied);
00978            RowImpl(const RowImpl& copied);
00979            RowImpl(int dialect, int size, DatabaseImpl* db, TransactionImpl* tr);
00980     ~RowImpl();
00981 
00982            //         (((((((( OBJECT INTERFACE ))))))))
00983 
00984 public:
00985            void SetNull(int);
00986            void Set(int, bool);
00987            void Set(int, const char*);                                       // c-strings
00988            void Set(int, const void*, int);            // byte buffers
00989            void Set(int, const std::string&);
00990            void Set(int, int16_t);
00991            void Set(int, int32_t);
00992            void Set(int, int64_t);
00993            void Set(int, float);
00994            void Set(int, double);
00995            void Set(int, const IBPP::Timestamp&);
00996            void Set(int, const IBPP::Date&);
00997            void Set(int, const IBPP::Time&);
00998            void Set(int, const IBPP::DBKey&);
00999            void Set(int, const IBPP::Blob&);
01000            void Set(int, const IBPP::Array&);
01001 
01002            bool IsNull(int);
01003            bool Get(int, bool&);
01004            bool Get(int, char*);                       // c-strings, len unchecked
01005            bool Get(int, void*, int&);      // byte buffers
01006            bool Get(int, std::string&);
01007            bool Get(int, int16_t&);
01008            bool Get(int, int32_t&);
01009            bool Get(int, int64_t&);
01010            bool Get(int, float&);
01011            bool Get(int, double&);
01012            bool Get(int, IBPP::Timestamp&);
01013            bool Get(int, IBPP::Date&);
01014            bool Get(int, IBPP::Time&);
01015            bool Get(int, IBPP::DBKey&);
01016            bool Get(int, IBPP::Blob&);
01017            bool Get(int, IBPP::Array&);
01018 
01019            bool IsNull(const std::string&);
01020            bool Get(const std::string&, bool&);
01021            bool Get(const std::string&, char*);        // c-strings, len unchecked
01022            bool Get(const std::string&, void*, int&);  // byte buffers
01023            bool Get(const std::string&, std::string&);
01024            bool Get(const std::string&, int16_t&);
01025            bool Get(const std::string&, int32_t&);
01026            bool Get(const std::string&, int64_t&);
01027            bool Get(const std::string&, float&);
01028            bool Get(const std::string&, double&);
01029            bool Get(const std::string&, IBPP::Timestamp&);
01030            bool Get(const std::string&, IBPP::Date&);
01031            bool Get(const std::string&, IBPP::Time&);
01032            bool Get(const std::string&, IBPP::DBKey&);
01033            bool Get(const std::string&, IBPP::Blob&);
01034            bool Get(const std::string&, IBPP::Array&);
01035 
01036            int ColumnNum(const std::string&);
01037            const char* ColumnName(int);
01038            const char* ColumnAlias(int);
01039            const char* ColumnTable(int);
01040            IBPP::SDT ColumnType(int);
01041            int ColumnSubtype(int);
01042            int ColumnSize(int);
01043            int ColumnScale(int);
01044            int Columns();
01045 
01046            bool ColumnUpdated(int);
01047            bool Updated();
01048 
01049            IBPP::Database DatabasePtr() const;
01050            IBPP::Transaction TransactionPtr() const;
01051 
01052            IBPP::IRow* Clone();
01053            IBPP::IRow* AddRef();
01054            void Release();
01055 };
01056 
01057 class StatementImpl : public IBPP::IStatement
01058 {
01059            //         (((((((( OBJECT INTERNALS ))))))))
01060 
01061 private:
01062            friend class TransactionImpl;
01063 
01064            int mRefCount;                                         // Reference counter
01065            isc_stmt_handle mHandle;         // Statement Handle
01066 
01067            DatabaseImpl* mDatabase;                    // Attached database
01068            TransactionImpl* mTransaction;   // Attached transaction
01069            RowImpl* mInRow;
01070            //bool* mInMissing;                         // Quels param�tres n'ont pas �t� sp�cifi�s
01071            RowImpl* mOutRow;
01072            bool mResultSetAvailable;        // Executed and result set is available
01073            bool mCursorOpened;                         // dsql_set_cursor_name was called
01074            IBPP::STT mType;                            // Type de requ�te
01075            std::string mSql;                           // Last SQL statement prepared or executed
01076 
01077            // Internal Methods
01078            void CursorFree();
01079 
01080 public:
01081            // Properties and Attributes Access Methods
01082            isc_stmt_handle GetHandle() { return mHandle; }
01083 
01084            void AttachDatabaseImpl(DatabaseImpl*);
01085            void DetachDatabaseImpl();
01086            void AttachTransactionImpl(TransactionImpl*);
01087            void DetachTransactionImpl();
01088 
01089            StatementImpl(DatabaseImpl*, TransactionImpl*, const std::string&);
01090     ~StatementImpl();
01091 
01092            //         (((((((( OBJECT INTERFACE ))))))))
01093 
01094 public:
01095            void Prepare(const std::string& sql);
01096            void Execute(const std::string& sql);
01097            inline void Execute() { Execute(std::string()); }
01098            void ExecuteImmediate(const std::string&);
01099            void CursorExecute(const std::string& cursor, const std::string& sql);
01100            inline void CursorExecute(const std::string& cursor)   { CursorExecute(cursor, std::string()); }
01101            bool Fetch();
01102            bool Fetch(IBPP::Row&);
01103            int AffectedRows();
01104            void Close();         // Free resources, attachments maintained
01105            std::string& Sql() { return mSql; }
01106            IBPP::STT Type() { return mType; }
01107 
01108            void SetNull(int);
01109            void Set(int, bool);
01110            void Set(int, const char*);                                       // c-strings
01111            void Set(int, const void*, int);            // byte buffers
01112            void Set(int, const std::string&);
01113            void Set(int, int16_t);
01114            void Set(int, int32_t);
01115            void Set(int, int64_t);
01116            void Set(int, float);
01117            void Set(int, double);
01118            void Set(int, const IBPP::Timestamp&);
01119            void Set(int, const IBPP::Date&);
01120            void Set(int, const IBPP::Time&);
01121            void Set(int, const IBPP::DBKey&);
01122            void Set(int, const IBPP::Blob&);
01123            void Set(int, const IBPP::Array&);
01124 
01125            bool IsNull(int);
01126            bool Get(int, bool*);
01127            bool Get(int, bool&);
01128            bool Get(int, char*);                                  // c-strings, len unchecked
01129            bool Get(int, void*, int&);                            // byte buffers
01130            bool Get(int, std::string&);
01131            bool Get(int, int16_t*);
01132            bool Get(int, int16_t&);
01133            bool Get(int, int32_t*);
01134            bool Get(int, int32_t&);
01135            bool Get(int, int64_t*);
01136            bool Get(int, int64_t&);
01137            bool Get(int, float*);
01138            bool Get(int, float&);
01139            bool Get(int, double*);
01140            bool Get(int, double&);
01141            bool Get(int, IBPP::Timestamp&);
01142            bool Get(int, IBPP::Date&);
01143            bool Get(int, IBPP::Time&);
01144            bool Get(int, IBPP::DBKey&);
01145            bool Get(int, IBPP::Blob&);
01146            bool Get(int, IBPP::Array&);
01147 
01148            bool IsNull(const std::string&);
01149            bool Get(const std::string&, bool*);
01150            bool Get(const std::string&, bool&);
01151            bool Get(const std::string&, char*);                   // c-strings, len unchecked
01152            bool Get(const std::string&, void*, int&);  // byte buffers
01153            bool Get(const std::string&, std::string&);
01154            bool Get(const std::string&, int16_t*);
01155            bool Get(const std::string&, int16_t&);
01156            bool Get(const std::string&, int32_t*);
01157            bool Get(const std::string&, int32_t&);
01158            bool Get(const std::string&, int64_t*);
01159            bool Get(const std::string&, int64_t&);
01160            bool Get(const std::string&, float*);
01161            bool Get(const std::string&, float&);
01162            bool Get(const std::string&, double*);
01163            bool Get(const std::string&, double&);
01164            bool Get(const std::string&, IBPP::Timestamp&);
01165            bool Get(const std::string&, IBPP::Date&);
01166            bool Get(const std::string&, IBPP::Time&);
01167            bool Get(const std::string&, IBPP::DBKey&);
01168            bool Get(const std::string&, IBPP::Blob&);
01169            bool Get(const std::string&, IBPP::Array&);
01170 
01171            int ColumnNum(const std::string&);
01172     int ColumnNumAlias(const std::string&);
01173            const char* ColumnName(int);
01174            const char* ColumnAlias(int);
01175            const char* ColumnTable(int);
01176            IBPP::SDT ColumnType(int);
01177            int ColumnSubtype(int);
01178            int ColumnSize(int);
01179            int ColumnScale(int);
01180            int Columns();
01181 
01182            IBPP::SDT ParameterType(int);
01183            int ParameterSubtype(int);
01184            int ParameterSize(int);
01185            int ParameterScale(int);
01186            int Parameters();
01187 
01188            void Plan(std::string&);
01189 
01190            IBPP::Database DatabasePtr() const;
01191            IBPP::Transaction TransactionPtr() const;
01192 
01193            IBPP::IStatement* AddRef();
01194            void Release();
01195 };
01196 
01197 class BlobImpl : public IBPP::IBlob
01198 {
01199            //         (((((((( OBJECT INTERNALS ))))))))
01200 
01201 private:
01202            friend class RowImpl;
01203 
01204            int mRefCount;
01205            bool                                                   mIdAssigned;
01206            ISC_QUAD                                    mId;
01207            isc_blob_handle                             mHandle;
01208            bool                                                   mWriteMode;
01209            DatabaseImpl*                               mDatabase;            // Belongs to this database
01210            TransactionImpl*                 mTransaction;         // Belongs to this transaction
01211 
01212            void Init();
01213            void SetId(ISC_QUAD*);
01214            void GetId(ISC_QUAD*);
01215 
01216 public:
01217            void AttachDatabaseImpl(DatabaseImpl*);
01218            void DetachDatabaseImpl();
01219            void AttachTransactionImpl(TransactionImpl*);
01220            void DetachTransactionImpl();
01221 
01222            BlobImpl(const BlobImpl&);
01223            BlobImpl(DatabaseImpl*, TransactionImpl* = 0);
01224            ~BlobImpl();
01225 
01226            //         (((((((( OBJECT INTERFACE ))))))))
01227 
01228 public:
01229            void Create();
01230            void Open();
01231            void Close();
01232            void Cancel();
01233            int Read(void*, int size);
01234            void Write(const void*, int size);
01235            void Info(int* Size, int* Largest, int* Segments);
01236 
01237            void Save(const std::string& data);
01238            void Load(std::string& data);
01239 
01240            IBPP::Database DatabasePtr() const;
01241            IBPP::Transaction TransactionPtr() const;
01242 
01243            IBPP::IBlob* AddRef();
01244            void Release();
01245 };
01246 
01247 class ArrayImpl : public IBPP::IArray
01248 {
01249            //         (((((((( OBJECT INTERNALS ))))))))
01250 
01251 private:
01252            friend class RowImpl;
01253 
01254            int                                                    mRefCount;            // Reference counter
01255            bool                                        mIdAssigned;
01256            ISC_QUAD                         mId;
01257            bool                                        mDescribed;
01258            ISC_ARRAY_DESC                   mDesc;
01259            DatabaseImpl*                    mDatabase;            // Database attach�e
01260            TransactionImpl*      mTransaction;         // Transaction attach�e
01261            void*                                       mBuffer;              // Buffer for native data
01262            int                                                    mBufferSize;          // Size of this buffer in bytes
01263            int                                                    mElemCount;                      // Count of elements in this array
01264            int                                                    mElemSize;            // Size of an element in the buffer
01265 
01266            void Init();
01267            void SetId(ISC_QUAD*);
01268            void GetId(ISC_QUAD*);
01269            void ResetId();
01270            void AllocArrayBuffer();
01271 
01272 public:
01273            void AttachDatabaseImpl(DatabaseImpl*);
01274            void DetachDatabaseImpl();
01275            void AttachTransactionImpl(TransactionImpl*);
01276            void DetachTransactionImpl();
01277 
01278            ArrayImpl(const ArrayImpl&);
01279            ArrayImpl(DatabaseImpl*, TransactionImpl* = 0);
01280            ~ArrayImpl();
01281 
01282            //         (((((((( OBJECT INTERFACE ))))))))
01283 
01284 public:
01285            void Describe(const std::string& table, const std::string& column);
01286            void ReadTo(IBPP::ADT, void*, int);
01287            void WriteFrom(IBPP::ADT, const void*, int);
01288            IBPP::SDT ElementType();
01289            int ElementSize();
01290            int ElementScale();
01291            int Dimensions();
01292            void Bounds(int dim, int* low, int* high);
01293            void SetBounds(int dim, int low, int high);
01294 
01295            IBPP::Database DatabasePtr() const;
01296            IBPP::Transaction TransactionPtr() const;
01297 
01298            IBPP::IArray* AddRef();
01299            void Release();
01300 };
01301 
01302 //
01303 //         EventBufferIterator: used in EventsImpl implementation.
01304 //
01305 
01306 template<class It>
01307 struct EventBufferIterator
01308 {
01309            It mIt;
01310 
01311 public:
01312            EventBufferIterator& operator++()
01313                       { mIt += 1 + static_cast<int>(*mIt) + 4; return *this; }
01314 
01315            bool operator == (const EventBufferIterator& i) const { return i.mIt == mIt; }
01316            bool operator != (const EventBufferIterator& i) const { return i.mIt != mIt; }
01317 
01318 #ifdef __BCPLUSPLUS__
01319 #pragma warn -8027
01320 #endif
01321            std::string get_name() const
01322            {
01323                       return std::string(mIt + 1, mIt + 1 + static_cast<int32_t>(*mIt));
01324            }
01325 #ifdef __BCPLUSPLUS__
01326 #pragma warn .8027
01327 #endif
01328 
01329            uint32_t get_count() const
01330            {
01331                       return (*gds.Call()->m_vax_integer)
01332                                  (const_cast<char*>(&*(mIt + 1 + static_cast<int>(*mIt))), 4);
01333            }
01334 
01335            // Those container like begin() and end() allow access to the underlying type
01336            It begin() { return mIt; }
01337            It end()   { return mIt + 1 + static_cast<int>(*mIt) + 4; }
01338 
01339            EventBufferIterator() {}
01340            EventBufferIterator(It it) : mIt(it) {}
01341 };
01342 
01343 class EventsImpl : public IBPP::IEvents
01344 {
01345            static const size_t MAXEVENTNAMELEN;
01346            static void EventHandler(const char*, short, const char*);
01347 
01348            typedef std::vector<IBPP::EventInterface*> ObjRefs;
01349            ObjRefs mObjectReferences;
01350 
01351            typedef std::vector<char> Buffer;
01352            Buffer mEventBuffer;
01353            Buffer mResultsBuffer;
01354 
01355            int mRefCount;                   // Reference counter
01356 
01357            DatabaseImpl* mDatabase;
01358            ISC_LONG mId;                               // Firebird internal Id of these events
01359            bool mQueued;                               // Has isc_que_events() been called?
01360            bool mTrapped;                              // EventHandled() was called since last que_events()
01361 
01362            void FireActions();
01363            void Queue();
01364            void Cancel();
01365 
01366            EventsImpl& operator=(const EventsImpl&);
01367            EventsImpl(const EventsImpl&);
01368 
01369 public:
01370            void AttachDatabaseImpl(DatabaseImpl*);
01371            void DetachDatabaseImpl();
01372            
01373            EventsImpl(DatabaseImpl* dbi);
01374            ~EventsImpl();
01375                       
01376            //         (((((((( OBJECT INTERFACE ))))))))
01377 
01378 public:
01379            void Add(const std::string&, IBPP::EventInterface*);
01380            void Drop(const std::string&);
01381            void List(std::vector<std::string>&);
01382            void Clear();                                          // Drop all events
01383            void Dispatch();                            // Dispatch NON async events
01384 
01385            IBPP::Database DatabasePtr() const;
01386 
01387            IBPP::IEvents* AddRef();
01388            void Release();
01389 };
01390 
01391 void encodeDate(ISC_DATE& isc_dt, const IBPP::Date& dt);
01392 void decodeDate(IBPP::Date& dt, const ISC_DATE& isc_dt);
01393 
01394 void encodeTime(ISC_TIME& isc_tm, const IBPP::Time& tm);
01395 void decodeTime(IBPP::Time& tm, const ISC_TIME& isc_tm);
01396 
01397 void encodeTimestamp(ISC_TIMESTAMP& isc_ts, const IBPP::Timestamp& ts);
01398 void decodeTimestamp(IBPP::Timestamp& ts, const ISC_TIMESTAMP& isc_ts);
01399 
01400 struct consts         // See _ibpp.cpp for initializations of these constants
01401 {
01402            static const double dscales[19];
01403            static const int Dec31_1899;
01404            static const int16_t min16;
01405            static const int16_t max16;
01406            static const int32_t min32;
01407            static const int32_t max32;
01408 };
01409 
01410 }          // namespace ibpp_internal
01411 
01412 #endif // __INTERNAL_IBPP_H__
01413 
01414 //
01415 //         Eof
01416 //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines