1 ///////////////////////////////////////////////////////////////////////////////
\r
3 // File : $Id: _ibpp.h,v 1.2 2007/05/17 08:37:05 faust Exp $
\r
4 // Subject : IBPP internal declarations
\r
6 ///////////////////////////////////////////////////////////////////////////////
\r
8 // (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)
\r
10 // The contents of this file are subject to the IBPP License (the "License");
\r
11 // you may not use this file except in compliance with the License. You may
\r
12 // obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'
\r
13 // file which must have been distributed along with this file.
\r
15 // This software, distributed under the License, is distributed on an "AS IS"
\r
16 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
\r
17 // License for the specific language governing rights and limitations
\r
18 // under the License.
\r
20 ///////////////////////////////////////////////////////////////////////////////
\r
24 // * 'Internal declarations' means everything used to implement ibpp. This
\r
25 // file and its contents is NOT needed by users of the library. All those
\r
26 // declarations are wrapped in a namespace : 'ibpp_internals'.
\r
27 // * Tabulations should be set every four characters when editing this file.
\r
29 ///////////////////////////////////////////////////////////////////////////////
\r
31 #ifndef __INTERNAL_IBPP_H__
\r
32 #define __INTERNAL_IBPP_H__
\r
36 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__DMC__)
\r
40 #if (defined(__GNUC__) && defined(IBPP_WINDOWS))
\r
41 // Setting flags for ibase.h -- using GCC/Cygwin/MinGW on Win32
\r
43 #define _MSC_VER 1299
\r
50 #include "ibase.h" // From Firebird 1.x or InterBase 6.x installation
\r
52 #if (defined(__GNUC__) && defined(IBPP_WINDOWS))
\r
53 // UNSETTING flags used above for ibase.h -- Huge conflicts with libstdc++ !
\r
59 #include <windows.h>
\r
69 #define ASSERTION(x) {if (!(x)) {throw LogicExceptionImpl("ASSERTION", \
\r
70 "'"#x"' is not verified at %s, line %d", \
\r
71 __FILE__, __LINE__);}}
\r
73 #define ASSERTION(x) /* x */
\r
76 // Fix to famous MSVC 6 variable scope bug
\r
77 #if defined(_MSC_VER) && (_MSC_VER < 1300) // MSVC 6 should be < 1300
\r
78 #define for if(true)for
\r
81 namespace ibpp_internals
\r
84 enum flush_debug_stream_type {fds};
\r
88 struct DebugStream : public std::stringstream
\r
90 // next two operators fix some g++ and vc++ related problems
\r
91 std::ostream& operator<< (const char* p)
\r
92 { static_cast<std::stringstream&>(*this)<< p; return *this; }
\r
94 std::ostream& operator<< (const std::string& p)
\r
95 { static_cast<std::stringstream&>(*this)<< p; return *this; }
\r
97 DebugStream& operator=(const DebugStream&) {return *this;}
\r
98 DebugStream(const DebugStream&) {}
\r
101 std::ostream& operator<< (std::ostream& a, flush_debug_stream_type);
\r
107 template<class T> DebugStream& operator<< (const T&) { return *this; }
\r
108 // for manipulators
\r
109 DebugStream& operator<< (std::ostream&(*)(std::ostream&)) { return *this; }
\r
114 class DatabaseImpl;
\r
115 class TransactionImpl;
\r
116 class StatementImpl;
\r
121 // Native data types
\r
122 typedef enum {ivArray, ivBlob, ivDate, ivTime, ivTimestamp, ivString,
\r
123 ivInt16, ivInt32, ivInt64, ivFloat, ivDouble,
\r
124 ivBool, ivDBKey, ivByte} IITYPE;
\r
127 // Those are the Interbase C API prototypes that we use
\r
128 // Taken 'asis' from IBASE.H, prefix 'isc_' replaced with 'proto_',
\r
129 // and 'typedef' preprended...
\r
132 typedef ISC_STATUS ISC_EXPORT proto_create_database (ISC_STATUS *,
\r
140 typedef ISC_STATUS ISC_EXPORT proto_attach_database (ISC_STATUS *,
\r
147 typedef ISC_STATUS ISC_EXPORT proto_detach_database (ISC_STATUS *,
\r
150 typedef ISC_STATUS ISC_EXPORT proto_drop_database (ISC_STATUS *,
\r
153 typedef ISC_STATUS ISC_EXPORT proto_database_info (ISC_STATUS *,
\r
160 typedef ISC_STATUS ISC_EXPORT proto_dsql_execute_immediate (ISC_STATUS *,
\r
168 typedef ISC_STATUS ISC_EXPORT proto_open_blob2 (ISC_STATUS *,
\r
176 typedef ISC_STATUS ISC_EXPORT proto_create_blob2 (ISC_STATUS *,
\r
184 typedef ISC_STATUS ISC_EXPORT proto_close_blob (ISC_STATUS *,
\r
185 isc_blob_handle *);
\r
187 typedef ISC_STATUS ISC_EXPORT proto_cancel_blob (ISC_STATUS *,
\r
188 isc_blob_handle *);
\r
190 typedef ISC_STATUS ISC_EXPORT proto_get_segment (ISC_STATUS *,
\r
196 typedef ISC_STATUS ISC_EXPORT proto_put_segment (ISC_STATUS *,
\r
201 typedef ISC_STATUS ISC_EXPORT proto_blob_info (ISC_STATUS *,
\r
208 typedef ISC_STATUS ISC_EXPORT proto_array_lookup_bounds (ISC_STATUS *,
\r
215 typedef ISC_STATUS ISC_EXPORT proto_array_get_slice (ISC_STATUS *,
\r
223 typedef ISC_STATUS ISC_EXPORT proto_array_put_slice (ISC_STATUS *,
\r
231 typedef ISC_LONG ISC_EXPORT proto_vax_integer (char *,
\r
234 typedef ISC_LONG ISC_EXPORT proto_sqlcode (ISC_STATUS *);
\r
236 typedef void ISC_EXPORT proto_sql_interprete (short,
\r
240 typedef ISC_STATUS ISC_EXPORT proto_interprete (char *,
\r
243 typedef ISC_STATUS ISC_EXPORT proto_que_events (ISC_STATUS *,
\r
251 typedef ISC_STATUS ISC_EXPORT proto_cancel_events (ISC_STATUS *,
\r
255 typedef ISC_STATUS ISC_EXPORT proto_start_multiple (ISC_STATUS *,
\r
260 typedef ISC_STATUS ISC_EXPORT proto_commit_transaction (ISC_STATUS *,
\r
263 typedef ISC_STATUS ISC_EXPORT proto_commit_retaining (ISC_STATUS *,
\r
266 typedef ISC_STATUS ISC_EXPORT proto_rollback_transaction (ISC_STATUS *,
\r
269 typedef ISC_STATUS ISC_EXPORT proto_rollback_retaining (ISC_STATUS *,
\r
273 typedef ISC_STATUS ISC_EXPORT proto_dsql_allocate_statement (ISC_STATUS *,
\r
275 isc_stmt_handle *);
\r
277 typedef ISC_STATUS ISC_EXPORT proto_dsql_describe (ISC_STATUS *,
\r
282 typedef ISC_STATUS ISC_EXPORT proto_dsql_describe_bind (ISC_STATUS *,
\r
287 typedef ISC_STATUS ISC_EXPORT proto_dsql_execute (ISC_STATUS *,
\r
293 typedef ISC_STATUS ISC_EXPORT proto_dsql_execute2 (ISC_STATUS *,
\r
300 typedef ISC_STATUS ISC_EXPORT proto_dsql_fetch (ISC_STATUS *,
\r
305 typedef ISC_STATUS ISC_EXPORT proto_dsql_free_statement (ISC_STATUS *,
\r
309 typedef ISC_STATUS ISC_EXPORT proto_dsql_prepare (ISC_STATUS *,
\r
317 typedef ISC_STATUS ISC_EXPORT proto_dsql_set_cursor_name (ISC_STATUS *,
\r
322 typedef ISC_STATUS ISC_EXPORT proto_dsql_sql_info (ISC_STATUS *,
\r
329 typedef void ISC_EXPORT proto_decode_date (ISC_QUAD *,
\r
332 typedef void ISC_EXPORT proto_encode_date (void *,
\r
335 typedef int ISC_EXPORT proto_add_user (ISC_STATUS *, USER_SEC_DATA *);
\r
336 typedef int ISC_EXPORT proto_delete_user (ISC_STATUS *, USER_SEC_DATA *);
\r
337 typedef int ISC_EXPORT proto_modify_user (ISC_STATUS *, USER_SEC_DATA *);
\r
340 // Those API are only available in versions 6.x of the GDS32.DLL
\r
343 typedef ISC_STATUS ISC_EXPORT proto_service_attach (ISC_STATUS *,
\r
350 typedef ISC_STATUS ISC_EXPORT proto_service_detach (ISC_STATUS *,
\r
353 typedef ISC_STATUS ISC_EXPORT proto_service_query (ISC_STATUS *,
\r
363 typedef ISC_STATUS ISC_EXPORT proto_service_start (ISC_STATUS *,
\r
369 typedef void ISC_EXPORT proto_decode_sql_date (ISC_DATE *,
\r
372 typedef void ISC_EXPORT proto_decode_sql_time (ISC_TIME *,
\r
375 typedef void ISC_EXPORT proto_decode_timestamp (ISC_TIMESTAMP *,
\r
378 typedef void ISC_EXPORT proto_encode_sql_date (void *,
\r
381 typedef void ISC_EXPORT proto_encode_sql_time (void *,
\r
384 typedef void ISC_EXPORT proto_encode_timestamp (void *,
\r
388 // Internal binding structure to the GDS32 DLL
\r
395 int mGDSVersion; // Version of the GDS32.DLL (50 for 5.0, 60 for 6.0)
\r
397 #ifdef IBPP_WINDOWS
\r
398 HMODULE mHandle; // The GDS32.DLL HMODULE
\r
399 std::string mSearchPaths; // Optional additional search paths
\r
404 // GDS32 Entry Points
\r
405 proto_create_database* m_create_database;
\r
406 proto_attach_database* m_attach_database;
\r
407 proto_detach_database* m_detach_database;
\r
408 proto_drop_database* m_drop_database;
\r
409 proto_database_info* m_database_info;
\r
410 proto_dsql_execute_immediate* m_dsql_execute_immediate;
\r
411 proto_open_blob2* m_open_blob2;
\r
412 proto_create_blob2* m_create_blob2;
\r
413 proto_close_blob* m_close_blob;
\r
414 proto_cancel_blob* m_cancel_blob;
\r
415 proto_get_segment* m_get_segment;
\r
416 proto_put_segment* m_put_segment;
\r
417 proto_blob_info* m_blob_info;
\r
418 proto_array_lookup_bounds* m_array_lookup_bounds;
\r
419 proto_array_get_slice* m_array_get_slice;
\r
420 proto_array_put_slice* m_array_put_slice;
\r
422 proto_vax_integer* m_vax_integer;
\r
423 proto_sqlcode* m_sqlcode;
\r
424 proto_sql_interprete* m_sql_interprete;
\r
425 proto_interprete* m_interprete;
\r
426 proto_que_events* m_que_events;
\r
427 proto_cancel_events* m_cancel_events;
\r
428 proto_start_multiple* m_start_multiple;
\r
429 proto_commit_transaction* m_commit_transaction;
\r
430 proto_commit_retaining* m_commit_retaining;
\r
431 proto_rollback_transaction* m_rollback_transaction;
\r
432 proto_rollback_retaining* m_rollback_retaining;
\r
433 proto_dsql_allocate_statement* m_dsql_allocate_statement;
\r
434 proto_dsql_describe* m_dsql_describe;
\r
435 proto_dsql_describe_bind* m_dsql_describe_bind;
\r
436 proto_dsql_prepare* m_dsql_prepare;
\r
437 proto_dsql_execute* m_dsql_execute;
\r
438 proto_dsql_execute2* m_dsql_execute2;
\r
439 proto_dsql_fetch* m_dsql_fetch;
\r
440 proto_dsql_free_statement* m_dsql_free_statement;
\r
441 proto_dsql_set_cursor_name* m_dsql_set_cursor_name;
\r
442 proto_dsql_sql_info* m_dsql_sql_info;
\r
443 //proto_decode_date* m_decode_date;
\r
444 //proto_encode_date* m_encode_date;
\r
445 //proto_add_user* m_add_user;
\r
446 //proto_delete_user* m_delete_user;
\r
447 //proto_modify_user* m_modify_user;
\r
449 proto_service_attach* m_service_attach;
\r
450 proto_service_detach* m_service_detach;
\r
451 proto_service_start* m_service_start;
\r
452 proto_service_query* m_service_query;
\r
453 //proto_decode_sql_date* m_decode_sql_date;
\r
454 //proto_decode_sql_time* m_decode_sql_time;
\r
455 //proto_decode_timestamp* m_decode_timestamp;
\r
456 //proto_encode_sql_date* m_encode_sql_date;
\r
457 //proto_encode_sql_time* m_encode_sql_time;
\r
458 //proto_encode_timestamp* m_encode_timestamp;
\r
460 // Constructor (No need for a specific destructor)
\r
465 #ifdef IBPP_WINDOWS
\r
474 // Service Parameter Block (used to define a service)
\r
479 static const int BUFFERINCR;
\r
481 char* mBuffer; // Dynamically allocated SPB structure
\r
482 int mSize; // Its used size in bytes
\r
483 int mAlloc; // Its allocated size in bytes
\r
485 void Grow(int needed); // Alloc or grow the mBuffer
\r
488 void Insert(char); // Insert a single byte code
\r
489 void InsertString(char, int, const char*); // Insert a string, len can be defined as 1 or 2 bytes
\r
490 void InsertByte(char type, char data);
\r
491 void InsertQuad(char type, int32_t data);
\r
492 void Reset(); // Clears the SPB
\r
493 char* Self() { return mBuffer; }
\r
494 short Size() { return (short)mSize; }
\r
496 SPB() : mBuffer(0), mSize(0), mAlloc(0) { }
\r
497 ~SPB() { Reset(); }
\r
501 // Database Parameter Block (used to define a database)
\r
506 static const int BUFFERINCR;
\r
508 char* mBuffer; // Dynamically allocated DPB structure
\r
509 int mSize; // Its used size in bytes
\r
510 int mAlloc; // Its allocated size in bytes
\r
512 void Grow(int needed); // Allocate or grow the mBuffer, so that
\r
513 // 'needed' bytes can be written (at least)
\r
516 void Insert(char, const char*); // Insert a new char* 'cluster'
\r
517 void Insert(char, int16_t); // Insert a new int16_t 'cluster'
\r
518 void Insert(char, bool); // Insert a new bool 'cluster'
\r
519 void Insert(char, char); // Insert a new byte 'cluster'
\r
520 void Reset(); // Clears the DPB
\r
521 char* Self() { return mBuffer; }
\r
522 short Size() { return (short)mSize; }
\r
524 DPB() : mBuffer(0), mSize(0), mAlloc(0) { }
\r
525 ~DPB() { Reset(); }
\r
529 // Transaction Parameter Block (used to define a transaction)
\r
534 static const int BUFFERINCR;
\r
536 char* mBuffer; // Dynamically allocated TPB structure
\r
537 int mSize; // Its used size in bytes
\r
538 int mAlloc; // Its allocated size
\r
540 void Grow(int needed); // Alloc or re-alloc the mBuffer
\r
543 void Insert(char); // Insert a flag item
\r
544 void Insert(const std::string& data); // Insert a string (typically table name)
\r
545 void Reset(); // Clears the TPB
\r
546 char* Self() { return mBuffer; }
\r
547 int Size() { return mSize; }
\r
549 TPB() : mBuffer(0), mSize(0), mAlloc(0) { }
\r
550 ~TPB() { Reset(); }
\r
554 // Used to receive (and process) a results buffer in various API calls
\r
562 char* FindToken(char token);
\r
563 char* FindToken(char token, char subtoken);
\r
567 int GetValue(char token);
\r
568 int GetCountValue(char token);
\r
569 int GetValue(char token, char subtoken);
\r
570 bool GetBool(char token);
\r
571 int GetString(char token, std::string& data);
\r
573 char* Self() { return mBuffer; }
\r
574 short Size() { return (short)mSize; }
\r
582 // Used to receive status info from API calls
\r
587 mutable ISC_STATUS mVector[20];
\r
588 mutable std::string mMessage;
\r
591 ISC_STATUS* Self() { return mVector; }
\r
592 bool Errors() { return (mVector[0] == 1 && mVector[1] > 0) ? true : false; }
\r
593 const char* ErrorMessage() const;
\r
594 int SqlCode() const;
\r
595 int EngineCode() const { return (mVector[0] == 1) ? (int)mVector[1] : 0; }
\r
599 IBS(IBS&); // Copy Constructor
\r
603 ///////////////////////////////////////////////////////////////////////////////
\r
605 // Implementation of the "hidden" classes associated with their public
\r
606 // counterparts. Their private data and methods can freely change without
\r
607 // breaking the compatibility of the DLL. If they receive new public methods,
\r
608 // and those methods are reflected in the public class, then the compatibility
\r
611 ///////////////////////////////////////////////////////////////////////////////
\r
614 // Hidden implementation of Exception classes.
\r
623 IBPP::LogicException ExceptionBase IBPP::SQLException
\r
625 | LogicExceptionImpl | SQLExceptionImpl
\r
629 IBPP::WrongTypeImpl
\r
632 class ExceptionBase
\r
634 // (((((((( OBJECT INTERNALS ))))))))
\r
637 std::string mContext; // Exception context ("IDatabase::Drop")
\r
638 std::string mWhat; // Full formatted message
\r
640 void buildErrorMessage(const char* message);
\r
641 void raise(const std::string& context, const char* message, va_list argptr);
\r
644 // The following constructors are small and could be inlined, but for object
\r
645 // code compacity of the library it is much better to have them non-inlined.
\r
646 // The amount of code generated by compilers for a throw is well-enough.
\r
648 ExceptionBase() throw();
\r
649 ExceptionBase(const ExceptionBase& copied) throw();
\r
650 ExceptionBase& operator=(const ExceptionBase& copied) throw();
\r
651 ExceptionBase(const std::string& context, const char* message = 0, ...) throw();
\r
653 virtual ~ExceptionBase() throw();
\r
655 // (((((((( OBJECT INTERFACE ))))))))
\r
657 virtual const char* Origin() const throw();
\r
658 virtual const char* ErrorMessage() const throw();
\r
659 virtual const char* what() const throw();
\r
662 class LogicExceptionImpl : public IBPP::LogicException, public ExceptionBase
\r
664 // (((((((( OBJECT INTERNALS ))))))))
\r
667 // The following constructors are small and could be inlined, but for object
\r
668 // code compacity of the library it is much better to have them non-inlined.
\r
669 // The amount of code generated by compilers for a throw is well-enough.
\r
671 LogicExceptionImpl() throw();
\r
672 LogicExceptionImpl(const LogicExceptionImpl& copied) throw();
\r
673 LogicExceptionImpl& operator=(const LogicExceptionImpl& copied) throw();
\r
674 LogicExceptionImpl(const std::string& context, const char* message = 0, ...) throw();
\r
676 virtual ~LogicExceptionImpl() throw ();
\r
678 // (((((((( OBJECT INTERFACE ))))))))
\r
680 // The object public interface is partly implemented by inheriting from
\r
681 // the ExceptionBase class.
\r
684 virtual const char* Origin() const throw();
\r
685 virtual const char* ErrorMessage() const throw();
\r
686 virtual const char* what() const throw();
\r
689 class SQLExceptionImpl : public IBPP::SQLException, public ExceptionBase
\r
691 // (((((((( OBJECT INTERNALS ))))))))
\r
698 // The following constructors are small and could be inlined, but for object
\r
699 // code compacity of the library it is much better to have them non-inlined.
\r
700 // The amount of code generated by compilers for a throw is well-enough.
\r
702 SQLExceptionImpl() throw();
\r
703 SQLExceptionImpl(const SQLExceptionImpl& copied) throw();
\r
704 SQLExceptionImpl& operator=(const SQLExceptionImpl& copied) throw();
\r
705 SQLExceptionImpl(const IBS& status, const std::string& context,
\r
706 const char* message = 0, ...) throw();
\r
708 virtual ~SQLExceptionImpl() throw ();
\r
710 // (((((((( OBJECT INTERFACE ))))))))
\r
712 // The object public interface is partly implemented by inheriting from
\r
713 // the ExceptionBase class.
\r
716 virtual const char* Origin() const throw();
\r
717 virtual const char* ErrorMessage() const throw();
\r
718 virtual const char* what() const throw();
\r
719 virtual int SqlCode() const throw();
\r
720 virtual int EngineCode() const throw();
\r
723 class WrongTypeImpl : public IBPP::WrongType, public ExceptionBase
\r
725 // (((((((( OBJECT INTERNALS ))))))))
\r
728 // The following constructors are small and could be inlined, but for object
\r
729 // code compacity of the library it is much better to have them non-inlined.
\r
730 // The amount of code generated by compilers for a throw is well-enough.
\r
732 WrongTypeImpl() throw();
\r
733 WrongTypeImpl(const WrongTypeImpl& copied) throw();
\r
734 WrongTypeImpl& operator=(const WrongTypeImpl& copied) throw();
\r
735 WrongTypeImpl(const std::string& context, int sqlType, IITYPE varType,
\r
736 const char* message = 0, ...) throw();
\r
738 virtual ~WrongTypeImpl() throw ();
\r
740 // (((((((( OBJECT INTERFACE ))))))))
\r
742 // The object public interface is partly implemented by inheriting from
\r
743 // the ExceptionBase class.
\r
746 virtual const char* Origin() const throw();
\r
747 virtual const char* ErrorMessage() const throw();
\r
748 virtual const char* what() const throw();
\r
751 class ServiceImpl : public IBPP::IService
\r
753 // (((((((( OBJECT INTERNALS ))))))))
\r
756 int mRefCount; // Reference counter
\r
757 isc_svc_handle mHandle; // InterBase API Service Handle
\r
758 std::string mServerName; // Nom du serveur
\r
759 std::string mUserName; // Nom de l'utilisateur
\r
760 std::string mUserPassword; // Mot de passe de l'utilisateur
\r
761 std::string mWaitMessage; // Progress message returned by WaitMsg()
\r
763 isc_svc_handle* GetHandlePtr() { return &mHandle; }
\r
764 void SetServerName(const char*);
\r
765 void SetUserName(const char*);
\r
766 void SetUserPassword(const char*);
\r
769 isc_svc_handle GetHandle() { return mHandle; }
\r
771 ServiceImpl(const std::string& ServerName, const std::string& UserName,
\r
772 const std::string& UserPassword);
\r
775 // (((((((( OBJECT INTERFACE ))))))))
\r
779 bool Connected() { return mHandle == 0 ? false : true; }
\r
782 void GetVersion(std::string& version);
\r
784 void AddUser(const IBPP::User&);
\r
785 void GetUser(IBPP::User&);
\r
786 void GetUsers(std::vector<IBPP::User>&);
\r
787 void ModifyUser(const IBPP::User&);
\r
788 void RemoveUser(const std::string& username);
\r
790 void SetPageBuffers(const std::string& dbfile, int buffers);
\r
791 void SetSweepInterval(const std::string& dbfile, int sweep);
\r
792 void SetSyncWrite(const std::string& dbfile, bool);
\r
793 void SetReadOnly(const std::string& dbfile, bool);
\r
794 void SetReserveSpace(const std::string& dbfile, bool);
\r
796 void Shutdown(const std::string& dbfile, IBPP::DSM mode, int sectimeout);
\r
797 void Restart(const std::string& dbfile);
\r
798 void Sweep(const std::string& dbfile);
\r
799 void Repair(const std::string& dbfile, IBPP::RPF flags);
\r
801 void StartBackup(const std::string& dbfile, const std::string& bkfile,
\r
802 IBPP::BRF flags = IBPP::BRF(0));
\r
803 void StartRestore(const std::string& bkfile, const std::string& dbfile,
\r
804 int pagesize, IBPP::BRF flags = IBPP::BRF(0));
\r
806 const char* WaitMsg();
\r
809 IBPP::IService* AddRef();
\r
813 class DatabaseImpl : public IBPP::IDatabase
\r
815 // (((((((( OBJECT INTERNALS ))))))))
\r
817 int mRefCount; // Reference counter
\r
818 isc_db_handle mHandle; // InterBase API Session Handle
\r
819 std::string mServerName; // Server name
\r
820 std::string mDatabaseName; // Database name (path/file)
\r
821 std::string mUserName; // User name
\r
822 std::string mUserPassword; // User password
\r
823 std::string mRoleName; // Role used for the duration of the connection
\r
824 std::string mCharSet; // Character Set used for the connection
\r
825 std::string mCreateParams; // Other parameters (creation only)
\r
827 int mDialect; // 1 if IB5, 1 or 3 if IB6/FB1
\r
828 std::vector<TransactionImpl*> mTransactions;// Table of Transaction*
\r
829 std::vector<StatementImpl*> mStatements;// Table of Statement*
\r
830 std::vector<BlobImpl*> mBlobs; // Table of Blob*
\r
831 std::vector<ArrayImpl*> mArrays; // Table of Array*
\r
832 std::vector<EventsImpl*> mEvents; // Table of Events*
\r
835 isc_db_handle* GetHandlePtr() { return &mHandle; }
\r
836 isc_db_handle GetHandle() { return mHandle; }
\r
838 void AttachTransactionImpl(TransactionImpl*);
\r
839 void DetachTransactionImpl(TransactionImpl*);
\r
840 void AttachStatementImpl(StatementImpl*);
\r
841 void DetachStatementImpl(StatementImpl*);
\r
842 void AttachBlobImpl(BlobImpl*);
\r
843 void DetachBlobImpl(BlobImpl*);
\r
844 void AttachArrayImpl(ArrayImpl*);
\r
845 void DetachArrayImpl(ArrayImpl*);
\r
846 void AttachEventsImpl(EventsImpl*);
\r
847 void DetachEventsImpl(EventsImpl*);
\r
849 DatabaseImpl(const std::string& ServerName, const std::string& DatabaseName,
\r
850 const std::string& UserName, const std::string& UserPassword,
\r
851 const std::string& RoleName, const std::string& CharSet,
\r
852 const std::string& CreateParams);
\r
855 // (((((((( OBJECT INTERFACE ))))))))
\r
858 const char* ServerName() const { return mServerName.c_str(); }
\r
859 const char* DatabaseName() const { return mDatabaseName.c_str(); }
\r
860 const char* Username() const { return mUserName.c_str(); }
\r
861 const char* UserPassword() const { return mUserPassword.c_str(); }
\r
862 const char* RoleName() const { return mRoleName.c_str(); }
\r
863 const char* CharSet() const { return mCharSet.c_str(); }
\r
864 const char* CreateParams() const { return mCreateParams.c_str(); }
\r
866 void Info(int* ODSMajor, int* ODSMinor,
\r
867 int* PageSize, int* Pages, int* Buffers, int* Sweep,
\r
868 bool* SyncWrites, bool* Reserve);
\r
869 void Statistics(int* Fetches, int* Marks, int* Reads, int* Writes);
\r
870 void Counts(int* Insert, int* Update, int* Delete,
\r
871 int* ReadIdx, int* ReadSeq);
\r
872 void Users(std::vector<std::string>& users);
\r
873 int Dialect() { return mDialect; }
\r
875 void Create(int dialect);
\r
877 bool Connected() { return mHandle == 0 ? false : true; }
\r
882 IBPP::IDatabase* AddRef();
\r
886 class TransactionImpl : public IBPP::ITransaction
\r
888 // (((((((( OBJECT INTERNALS ))))))))
\r
891 int mRefCount; // Reference counter
\r
892 isc_tr_handle mHandle; // Transaction InterBase
\r
894 std::vector<DatabaseImpl*> mDatabases; // Tableau de IDatabase*
\r
895 std::vector<StatementImpl*> mStatements; // Tableau de IStatement*
\r
896 std::vector<BlobImpl*> mBlobs; // Tableau de IBlob*
\r
897 std::vector<ArrayImpl*> mArrays; // Tableau de Array*
\r
898 std::vector<TPB*> mTPBs; // Tableau de TPB
\r
900 void Init(); // A usage exclusif des constructeurs
\r
903 isc_tr_handle* GetHandlePtr() { return &mHandle; }
\r
904 isc_tr_handle GetHandle() { return mHandle; }
\r
906 void AttachStatementImpl(StatementImpl*);
\r
907 void DetachStatementImpl(StatementImpl*);
\r
908 void AttachBlobImpl(BlobImpl*);
\r
909 void DetachBlobImpl(BlobImpl*);
\r
910 void AttachArrayImpl(ArrayImpl*);
\r
911 void DetachArrayImpl(ArrayImpl*);
\r
912 void AttachDatabaseImpl(DatabaseImpl* dbi, IBPP::TAM am = IBPP::amWrite,
\r
913 IBPP::TIL il = IBPP::ilConcurrency,
\r
914 IBPP::TLR lr = IBPP::lrWait, IBPP::TFF flags = IBPP::TFF(0));
\r
915 void DetachDatabaseImpl(DatabaseImpl* dbi);
\r
917 TransactionImpl(DatabaseImpl* db, IBPP::TAM am = IBPP::amWrite,
\r
918 IBPP::TIL il = IBPP::ilConcurrency,
\r
919 IBPP::TLR lr = IBPP::lrWait, IBPP::TFF flags = IBPP::TFF(0));
\r
920 ~TransactionImpl();
\r
922 // (((((((( OBJECT INTERFACE ))))))))
\r
925 void AttachDatabase(IBPP::Database db, IBPP::TAM am = IBPP::amWrite,
\r
926 IBPP::TIL il = IBPP::ilConcurrency,
\r
927 IBPP::TLR lr = IBPP::lrWait, IBPP::TFF flags = IBPP::TFF(0));
\r
928 void DetachDatabase(IBPP::Database db);
\r
929 void AddReservation(IBPP::Database db,
\r
930 const std::string& table, IBPP::TTR tr);
\r
933 bool Started() { return mHandle == 0 ? false : true; }
\r
936 void CommitRetain();
\r
937 void RollbackRetain();
\r
939 IBPP::ITransaction* AddRef();
\r
943 class RowImpl : public IBPP::IRow
\r
945 // (((((((( OBJECT INTERNALS ))))))))
\r
948 int mRefCount; // Reference counter
\r
950 XSQLDA* mDescrArea; // XSQLDA descriptor itself
\r
951 std::vector<double> mNumerics; // Temporary storage for Numerics
\r
952 std::vector<float> mFloats; // Temporary storage for Floats
\r
953 std::vector<int64_t> mInt64s; // Temporary storage for 64 bits
\r
954 std::vector<int32_t> mInt32s; // Temporary storage for 32 bits
\r
955 std::vector<int16_t> mInt16s; // Temporary storage for 16 bits
\r
956 std::vector<char> mBools; // Temporary storage for Bools
\r
957 std::vector<std::string> mStrings; // Temporary storage for Strings
\r
958 std::vector<bool> mUpdated; // Which columns where updated (Set()) ?
\r
960 int mDialect; // Related database dialect
\r
961 DatabaseImpl* mDatabase; // Related Database (important for Blobs, ...)
\r
962 TransactionImpl* mTransaction; // Related Transaction (same remark)
\r
964 void SetValue(int, IITYPE, const void* value, int = 0);
\r
965 void* GetValue(int, IITYPE, void* = 0);
\r
969 short AllocatedSize() { return mDescrArea->sqln; }
\r
970 void Resize(int n);
\r
971 void AllocVariables();
\r
972 bool MissingValues(); // Returns wether one of the mMissing[] is true
\r
973 XSQLDA* Self() { return mDescrArea; }
\r
975 RowImpl& operator=(const RowImpl& copied);
\r
976 RowImpl(const RowImpl& copied);
\r
977 RowImpl(int dialect, int size, DatabaseImpl* db, TransactionImpl* tr);
\r
980 // (((((((( OBJECT INTERFACE ))))))))
\r
984 void Set(int, bool);
\r
985 void Set(int, const char*); // c-strings
\r
986 void Set(int, const void*, int); // byte buffers
\r
987 void Set(int, const std::string&);
\r
988 void Set(int, int16_t);
\r
989 void Set(int, int32_t);
\r
990 void Set(int, int64_t);
\r
991 void Set(int, float);
\r
992 void Set(int, double);
\r
993 void Set(int, const IBPP::Timestamp&);
\r
994 void Set(int, const IBPP::Date&);
\r
995 void Set(int, const IBPP::Time&);
\r
996 void Set(int, const IBPP::DBKey&);
\r
997 void Set(int, const IBPP::Blob&);
\r
998 void Set(int, const IBPP::Array&);
\r
1001 bool Get(int, bool&);
\r
1002 bool Get(int, char*); // c-strings, len unchecked
\r
1003 bool Get(int, void*, int&); // byte buffers
\r
1004 bool Get(int, std::string&);
\r
1005 bool Get(int, int16_t&);
\r
1006 bool Get(int, int32_t&);
\r
1007 bool Get(int, int64_t&);
\r
1008 bool Get(int, float&);
\r
1009 bool Get(int, double&);
\r
1010 bool Get(int, IBPP::Timestamp&);
\r
1011 bool Get(int, IBPP::Date&);
\r
1012 bool Get(int, IBPP::Time&);
\r
1013 bool Get(int, IBPP::DBKey&);
\r
1014 bool Get(int, IBPP::Blob&);
\r
1015 bool Get(int, IBPP::Array&);
\r
1017 bool IsNull(const std::string&);
\r
1018 bool Get(const std::string&, bool&);
\r
1019 bool Get(const std::string&, char*); // c-strings, len unchecked
\r
1020 bool Get(const std::string&, void*, int&); // byte buffers
\r
1021 bool Get(const std::string&, std::string&);
\r
1022 bool Get(const std::string&, int16_t&);
\r
1023 bool Get(const std::string&, int32_t&);
\r
1024 bool Get(const std::string&, int64_t&);
\r
1025 bool Get(const std::string&, float&);
\r
1026 bool Get(const std::string&, double&);
\r
1027 bool Get(const std::string&, IBPP::Timestamp&);
\r
1028 bool Get(const std::string&, IBPP::Date&);
\r
1029 bool Get(const std::string&, IBPP::Time&);
\r
1030 bool Get(const std::string&, IBPP::DBKey&);
\r
1031 bool Get(const std::string&, IBPP::Blob&);
\r
1032 bool Get(const std::string&, IBPP::Array&);
\r
1034 int ColumnNum(const std::string&);
\r
1035 const char* ColumnName(int);
\r
1036 const char* ColumnAlias(int);
\r
1037 const char* ColumnTable(int);
\r
1038 IBPP::SDT ColumnType(int);
\r
1039 int ColumnSubtype(int);
\r
1040 int ColumnSize(int);
\r
1041 int ColumnScale(int);
\r
1044 bool ColumnUpdated(int);
\r
1047 IBPP::Database DatabasePtr() const;
\r
1048 IBPP::Transaction TransactionPtr() const;
\r
1050 IBPP::IRow* Clone();
\r
1051 IBPP::IRow* AddRef();
\r
1055 class StatementImpl : public IBPP::IStatement
\r
1057 // (((((((( OBJECT INTERNALS ))))))))
\r
1060 friend class TransactionImpl;
\r
1062 int mRefCount; // Reference counter
\r
1063 isc_stmt_handle mHandle; // Statement Handle
\r
1065 DatabaseImpl* mDatabase; // Attached database
\r
1066 TransactionImpl* mTransaction; // Attached transaction
\r
1068 //bool* mInMissing; // Quels paramètres n'ont pas été spécifiés
\r
1070 bool mResultSetAvailable; // Executed and result set is available
\r
1071 bool mCursorOpened; // dsql_set_cursor_name was called
\r
1072 IBPP::STT mType; // Type de requète
\r
1073 std::string mSql; // Last SQL statement prepared or executed
\r
1075 // Internal Methods
\r
1076 void CursorFree();
\r
1079 // Properties and Attributes Access Methods
\r
1080 isc_stmt_handle GetHandle() { return mHandle; }
\r
1082 void AttachDatabaseImpl(DatabaseImpl*);
\r
1083 void DetachDatabaseImpl();
\r
1084 void AttachTransactionImpl(TransactionImpl*);
\r
1085 void DetachTransactionImpl();
\r
1087 StatementImpl(DatabaseImpl*, TransactionImpl*, const std::string&);
\r
1090 // (((((((( OBJECT INTERFACE ))))))))
\r
1093 void Prepare(const std::string& sql);
\r
1094 void Execute(const std::string& sql);
\r
1095 inline void Execute() { Execute(std::string()); }
\r
1096 void ExecuteImmediate(const std::string&);
\r
1097 void CursorExecute(const std::string& cursor, const std::string& sql);
\r
1098 inline void CursorExecute(const std::string& cursor) { CursorExecute(cursor, std::string()); }
\r
1100 bool Fetch(IBPP::Row&);
\r
1101 int AffectedRows();
\r
1102 void Close(); // Free resources, attachments maintained
\r
1103 std::string& Sql() { return mSql; }
\r
1104 IBPP::STT Type() { return mType; }
\r
1106 void SetNull(int);
\r
1107 void Set(int, bool);
\r
1108 void Set(int, const char*); // c-strings
\r
1109 void Set(int, const void*, int); // byte buffers
\r
1110 void Set(int, const std::string&);
\r
1111 void Set(int, int16_t);
\r
1112 void Set(int, int32_t);
\r
1113 void Set(int, int64_t);
\r
1114 void Set(int, float);
\r
1115 void Set(int, double);
\r
1116 void Set(int, const IBPP::Timestamp&);
\r
1117 void Set(int, const IBPP::Date&);
\r
1118 void Set(int, const IBPP::Time&);
\r
1119 void Set(int, const IBPP::DBKey&);
\r
1120 void Set(int, const IBPP::Blob&);
\r
1121 void Set(int, const IBPP::Array&);
\r
1124 bool Get(int, bool*);
\r
1125 bool Get(int, bool&);
\r
1126 bool Get(int, char*); // c-strings, len unchecked
\r
1127 bool Get(int, void*, int&); // byte buffers
\r
1128 bool Get(int, std::string&);
\r
1129 bool Get(int, int16_t*);
\r
1130 bool Get(int, int16_t&);
\r
1131 bool Get(int, int32_t*);
\r
1132 bool Get(int, int32_t&);
\r
1133 bool Get(int, int64_t*);
\r
1134 bool Get(int, int64_t&);
\r
1135 bool Get(int, float*);
\r
1136 bool Get(int, float&);
\r
1137 bool Get(int, double*);
\r
1138 bool Get(int, double&);
\r
1139 bool Get(int, IBPP::Timestamp&);
\r
1140 bool Get(int, IBPP::Date&);
\r
1141 bool Get(int, IBPP::Time&);
\r
1142 bool Get(int, IBPP::DBKey&);
\r
1143 bool Get(int, IBPP::Blob&);
\r
1144 bool Get(int, IBPP::Array&);
\r
1146 bool IsNull(const std::string&);
\r
1147 bool Get(const std::string&, bool*);
\r
1148 bool Get(const std::string&, bool&);
\r
1149 bool Get(const std::string&, char*); // c-strings, len unchecked
\r
1150 bool Get(const std::string&, void*, int&); // byte buffers
\r
1151 bool Get(const std::string&, std::string&);
\r
1152 bool Get(const std::string&, int16_t*);
\r
1153 bool Get(const std::string&, int16_t&);
\r
1154 bool Get(const std::string&, int32_t*);
\r
1155 bool Get(const std::string&, int32_t&);
\r
1156 bool Get(const std::string&, int64_t*);
\r
1157 bool Get(const std::string&, int64_t&);
\r
1158 bool Get(const std::string&, float*);
\r
1159 bool Get(const std::string&, float&);
\r
1160 bool Get(const std::string&, double*);
\r
1161 bool Get(const std::string&, double&);
\r
1162 bool Get(const std::string&, IBPP::Timestamp&);
\r
1163 bool Get(const std::string&, IBPP::Date&);
\r
1164 bool Get(const std::string&, IBPP::Time&);
\r
1165 bool Get(const std::string&, IBPP::DBKey&);
\r
1166 bool Get(const std::string&, IBPP::Blob&);
\r
1167 bool Get(const std::string&, IBPP::Array&);
\r
1169 int ColumnNum(const std::string&);
\r
1170 int ColumnNumAlias(const std::string&);
\r
1171 const char* ColumnName(int);
\r
1172 const char* ColumnAlias(int);
\r
1173 const char* ColumnTable(int);
\r
1174 IBPP::SDT ColumnType(int);
\r
1175 int ColumnSubtype(int);
\r
1176 int ColumnSize(int);
\r
1177 int ColumnScale(int);
\r
1180 IBPP::SDT ParameterType(int);
\r
1181 int ParameterSubtype(int);
\r
1182 int ParameterSize(int);
\r
1183 int ParameterScale(int);
\r
1186 void Plan(std::string&);
\r
1188 IBPP::Database DatabasePtr() const;
\r
1189 IBPP::Transaction TransactionPtr() const;
\r
1191 IBPP::IStatement* AddRef();
\r
1195 class BlobImpl : public IBPP::IBlob
\r
1197 // (((((((( OBJECT INTERNALS ))))))))
\r
1200 friend class RowImpl;
\r
1205 isc_blob_handle mHandle;
\r
1207 DatabaseImpl* mDatabase; // Belongs to this database
\r
1208 TransactionImpl* mTransaction; // Belongs to this transaction
\r
1211 void SetId(ISC_QUAD*);
\r
1212 void GetId(ISC_QUAD*);
\r
1215 void AttachDatabaseImpl(DatabaseImpl*);
\r
1216 void DetachDatabaseImpl();
\r
1217 void AttachTransactionImpl(TransactionImpl*);
\r
1218 void DetachTransactionImpl();
\r
1220 BlobImpl(const BlobImpl&);
\r
1221 BlobImpl(DatabaseImpl*, TransactionImpl* = 0);
\r
1224 // (((((((( OBJECT INTERFACE ))))))))
\r
1231 int Read(void*, int size);
\r
1232 void Write(const void*, int size);
\r
1233 void Info(int* Size, int* Largest, int* Segments);
\r
1235 void Save(const std::string& data);
\r
1236 void Load(std::string& data);
\r
1238 IBPP::Database DatabasePtr() const;
\r
1239 IBPP::Transaction TransactionPtr() const;
\r
1241 IBPP::IBlob* AddRef();
\r
1245 class ArrayImpl : public IBPP::IArray
\r
1247 // (((((((( OBJECT INTERNALS ))))))))
\r
1250 friend class RowImpl;
\r
1252 int mRefCount; // Reference counter
\r
1256 ISC_ARRAY_DESC mDesc;
\r
1257 DatabaseImpl* mDatabase; // Database attachée
\r
1258 TransactionImpl* mTransaction; // Transaction attachée
\r
1259 void* mBuffer; // Buffer for native data
\r
1260 int mBufferSize; // Size of this buffer in bytes
\r
1261 int mElemCount; // Count of elements in this array
\r
1262 int mElemSize; // Size of an element in the buffer
\r
1265 void SetId(ISC_QUAD*);
\r
1266 void GetId(ISC_QUAD*);
\r
1268 void AllocArrayBuffer();
\r
1271 void AttachDatabaseImpl(DatabaseImpl*);
\r
1272 void DetachDatabaseImpl();
\r
1273 void AttachTransactionImpl(TransactionImpl*);
\r
1274 void DetachTransactionImpl();
\r
1276 ArrayImpl(const ArrayImpl&);
\r
1277 ArrayImpl(DatabaseImpl*, TransactionImpl* = 0);
\r
1280 // (((((((( OBJECT INTERFACE ))))))))
\r
1283 void Describe(const std::string& table, const std::string& column);
\r
1284 void ReadTo(IBPP::ADT, void*, int);
\r
1285 void WriteFrom(IBPP::ADT, const void*, int);
\r
1286 IBPP::SDT ElementType();
\r
1287 int ElementSize();
\r
1288 int ElementScale();
\r
1290 void Bounds(int dim, int* low, int* high);
\r
1291 void SetBounds(int dim, int low, int high);
\r
1293 IBPP::Database DatabasePtr() const;
\r
1294 IBPP::Transaction TransactionPtr() const;
\r
1296 IBPP::IArray* AddRef();
\r
1301 // EventBufferIterator: used in EventsImpl implementation.
\r
1304 template<class It>
\r
1305 struct EventBufferIterator
\r
1310 EventBufferIterator& operator++()
\r
1311 { mIt += 1 + static_cast<int>(*mIt) + 4; return *this; }
\r
1313 bool operator == (const EventBufferIterator& i) const { return i.mIt == mIt; }
\r
1314 bool operator != (const EventBufferIterator& i) const { return i.mIt != mIt; }
\r
1316 #ifdef __BCPLUSPLUS__
\r
1317 #pragma warn -8027
\r
1319 std::string get_name() const
\r
1321 return std::string(mIt + 1, mIt + 1 + static_cast<int32_t>(*mIt));
\r
1323 #ifdef __BCPLUSPLUS__
\r
1324 #pragma warn .8027
\r
1327 uint32_t get_count() const
\r
1329 return (*gds.Call()->m_vax_integer)
\r
1330 (const_cast<char*>(&*(mIt + 1 + static_cast<int>(*mIt))), 4);
\r
1333 // Those container like begin() and end() allow access to the underlying type
\r
1334 It begin() { return mIt; }
\r
1335 It end() { return mIt + 1 + static_cast<int>(*mIt) + 4; }
\r
1337 EventBufferIterator() {}
\r
1338 EventBufferIterator(It it) : mIt(it) {}
\r
1341 class EventsImpl : public IBPP::IEvents
\r
1343 static const size_t MAXEVENTNAMELEN;
\r
1344 static void EventHandler(const char*, short, const char*);
\r
1346 typedef std::vector<IBPP::EventInterface*> ObjRefs;
\r
1347 ObjRefs mObjectReferences;
\r
1349 typedef std::vector<char> Buffer;
\r
1350 Buffer mEventBuffer;
\r
1351 Buffer mResultsBuffer;
\r
1353 int mRefCount; // Reference counter
\r
1355 DatabaseImpl* mDatabase;
\r
1356 ISC_LONG mId; // Firebird internal Id of these events
\r
1357 bool mQueued; // Has isc_que_events() been called?
\r
1358 bool mTrapped; // EventHandled() was called since last que_events()
\r
1360 void FireActions();
\r
1364 EventsImpl& operator=(const EventsImpl&);
\r
1365 EventsImpl(const EventsImpl&);
\r
1368 void AttachDatabaseImpl(DatabaseImpl*);
\r
1369 void DetachDatabaseImpl();
\r
1371 EventsImpl(DatabaseImpl* dbi);
\r
1374 // (((((((( OBJECT INTERFACE ))))))))
\r
1377 void Add(const std::string&, IBPP::EventInterface*);
\r
1378 void Drop(const std::string&);
\r
1379 void List(std::vector<std::string>&);
\r
1380 void Clear(); // Drop all events
\r
1381 void Dispatch(); // Dispatch NON async events
\r
1383 IBPP::Database DatabasePtr() const;
\r
1385 IBPP::IEvents* AddRef();
\r
1389 void encodeDate(ISC_DATE& isc_dt, const IBPP::Date& dt);
\r
1390 void decodeDate(IBPP::Date& dt, const ISC_DATE& isc_dt);
\r
1392 void encodeTime(ISC_TIME& isc_tm, const IBPP::Time& tm);
\r
1393 void decodeTime(IBPP::Time& tm, const ISC_TIME& isc_tm);
\r
1395 void encodeTimestamp(ISC_TIMESTAMP& isc_ts, const IBPP::Timestamp& ts);
\r
1396 void decodeTimestamp(IBPP::Timestamp& ts, const ISC_TIMESTAMP& isc_ts);
\r
1398 struct consts // See _ibpp.cpp for initializations of these constants
\r
1400 static const double dscales[19];
\r
1401 static const int Dec31_1899;
\r
1402 static const int16_t min16;
\r
1403 static const int16_t max16;
\r
1404 static const int32_t min32;
\r
1405 static const int32_t max32;
\r
1408 } // namespace ibpp_internal
\r
1410 #endif // __INTERNAL_IBPP_H__
\r