]> git.stg.codes - stg.git/blob - stglibs/ibpp.lib/_ibpp.h
Merge branch 'stg-2.409-radius'
[stg.git] / stglibs / ibpp.lib / _ibpp.h
1 ///////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //      File    : $Id: _ibpp.h,v 1.2 2007/05/17 08:37:05 faust Exp $\r
4 //      Subject : IBPP internal declarations\r
5 //\r
6 ///////////////////////////////////////////////////////////////////////////////\r
7 //\r
8 //      (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)\r
9 //\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
14 //\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
19 //\r
20 ///////////////////////////////////////////////////////////////////////////////\r
21 //\r
22 //      COMMENTS\r
23 //\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
28 //\r
29 ///////////////////////////////////////////////////////////////////////////////\r
30 \r
31 #ifndef __INTERNAL_IBPP_H__\r
32 #define __INTERNAL_IBPP_H__\r
33 \r
34 #include "stg/ibpp.h"\r
35 \r
36 #if defined(__BCPLUSPLUS__) || defined(_MSC_VER) || defined(__DMC__)\r
37 #define HAS_HDRSTOP\r
38 #endif\r
39 \r
40 #if (defined(__GNUC__) && defined(IBPP_WINDOWS))\r
41 //      Setting flags for ibase.h -- using GCC/Cygwin/MinGW on Win32\r
42 #ifndef _MSC_VER\r
43 #define _MSC_VER 1299\r
44 #endif\r
45 #ifndef _WIN32\r
46 #define _WIN32   1\r
47 #endif\r
48 #endif\r
49 \r
50 #include "ibase.h"              // From Firebird 1.x or InterBase 6.x installation\r
51 \r
52 #if (defined(__GNUC__) && defined(IBPP_WINDOWS))\r
53 //      UNSETTING flags used above for ibase.h -- Huge conflicts with libstdc++ !\r
54 #undef _MSC_VER\r
55 #undef _WIN32\r
56 #endif\r
57 \r
58 #ifdef IBPP_WINDOWS\r
59 #include <windows.h>\r
60 #endif\r
61 \r
62 //#include <limits>\r
63 #include <string>\r
64 #include <vector>\r
65 #include <sstream>\r
66 #include <cstdarg>\r
67 \r
68 #ifdef _DEBUG\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
72 #else\r
73 #define ASSERTION(x)    /* x */\r
74 #endif\r
75 \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
79 #endif\r
80 \r
81 namespace ibpp_internals\r
82 {\r
83 \r
84 enum flush_debug_stream_type {fds};\r
85 \r
86 #ifdef _DEBUG\r
87 \r
88 struct DebugStream : public std::stringstream\r
89 {\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
93 \r
94         std::ostream& operator<< (const std::string& p)\r
95                 { static_cast<std::stringstream&>(*this)<< p; return *this; }\r
96 \r
97         DebugStream& operator=(const DebugStream&) {return *this;}\r
98         DebugStream(const DebugStream&) {}\r
99         DebugStream() {}\r
100 };\r
101 std::ostream& operator<< (std::ostream& a, flush_debug_stream_type);\r
102 \r
103 #else\r
104 \r
105 struct DebugStream\r
106 {\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
110 };\r
111 \r
112 #endif  // _DEBUG\r
113 \r
114 class DatabaseImpl;\r
115 class TransactionImpl;\r
116 class StatementImpl;\r
117 class BlobImpl;\r
118 class ArrayImpl;\r
119 class EventsImpl;\r
120 \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
125 \r
126 //\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
130 //\r
131 \r
132 typedef ISC_STATUS ISC_EXPORT proto_create_database (ISC_STATUS *,\r
133                                             short,\r
134                                             char *,\r
135                                             isc_db_handle *,\r
136                                             short,\r
137                                             char *,\r
138                                             short);\r
139 \r
140 typedef ISC_STATUS ISC_EXPORT proto_attach_database (ISC_STATUS *,\r
141                                             short,\r
142                                             char *,\r
143                                             isc_db_handle *,\r
144                                             short,\r
145                                             char *);\r
146 \r
147 typedef ISC_STATUS  ISC_EXPORT proto_detach_database (ISC_STATUS *,\r
148                                             isc_db_handle *);\r
149 \r
150 typedef ISC_STATUS  ISC_EXPORT proto_drop_database (ISC_STATUS *,\r
151                                           isc_db_handle *);\r
152 \r
153 typedef ISC_STATUS  ISC_EXPORT proto_database_info (ISC_STATUS *,\r
154                                           isc_db_handle *,\r
155                                           short,\r
156                                           char *,\r
157                                           short,\r
158                                           char *);\r
159 \r
160 typedef ISC_STATUS  ISC_EXPORT proto_dsql_execute_immediate (ISC_STATUS *,\r
161                                                    isc_db_handle *,\r
162                                                    isc_tr_handle *,\r
163                                                    unsigned short,\r
164                                                    char *,\r
165                                                    unsigned short,\r
166                                                    XSQLDA *);\r
167 \r
168 typedef ISC_STATUS  ISC_EXPORT proto_open_blob2 (ISC_STATUS *,\r
169                                        isc_db_handle *,\r
170                                        isc_tr_handle *,\r
171                                        isc_blob_handle *,\r
172                                        ISC_QUAD *,\r
173                                        short,\r
174                                        char *);\r
175 \r
176 typedef ISC_STATUS  ISC_EXPORT proto_create_blob2 (ISC_STATUS *,\r
177                                         isc_db_handle *,\r
178                                         isc_tr_handle *,\r
179                                         isc_blob_handle *,\r
180                                         ISC_QUAD *,\r
181                                         short,\r
182                                         char *);\r
183 \r
184 typedef ISC_STATUS  ISC_EXPORT proto_close_blob (ISC_STATUS *,\r
185                                        isc_blob_handle *);\r
186 \r
187 typedef ISC_STATUS  ISC_EXPORT proto_cancel_blob (ISC_STATUS *,\r
188                                         isc_blob_handle *);\r
189 \r
190 typedef ISC_STATUS  ISC_EXPORT proto_get_segment (ISC_STATUS *,\r
191                                         isc_blob_handle *,\r
192                                         unsigned short *,\r
193                                         unsigned short,\r
194                                         char *);\r
195 \r
196 typedef ISC_STATUS  ISC_EXPORT proto_put_segment (ISC_STATUS *,\r
197                                         isc_blob_handle *,\r
198                                         unsigned short,\r
199                                         char *);\r
200 \r
201 typedef ISC_STATUS  ISC_EXPORT proto_blob_info (ISC_STATUS *,\r
202                                       isc_blob_handle *,\r
203                                       short,\r
204                                       char *,\r
205                                       short,\r
206                                       char *);\r
207 \r
208 typedef ISC_STATUS  ISC_EXPORT proto_array_lookup_bounds (ISC_STATUS *,\r
209                                                 isc_db_handle *,\r
210                                                 isc_tr_handle *,\r
211                                                 char *,\r
212                                                 char *,\r
213                                                 ISC_ARRAY_DESC *);\r
214 \r
215 typedef ISC_STATUS  ISC_EXPORT proto_array_get_slice (ISC_STATUS *,\r
216                                             isc_db_handle *,\r
217                                             isc_tr_handle *,\r
218                                             ISC_QUAD *,\r
219                                             ISC_ARRAY_DESC *,\r
220                                             void *,\r
221                                             ISC_LONG *);\r
222 \r
223 typedef ISC_STATUS  ISC_EXPORT proto_array_put_slice (ISC_STATUS *,\r
224                                             isc_db_handle *,\r
225                                             isc_tr_handle *,\r
226                                             ISC_QUAD *,\r
227                                             ISC_ARRAY_DESC *,\r
228                                             void *,\r
229                                             ISC_LONG *);\r
230 \r
231 typedef ISC_LONG    ISC_EXPORT proto_vax_integer (char *,\r
232                                         short);\r
233 \r
234 typedef ISC_LONG    ISC_EXPORT proto_sqlcode (ISC_STATUS *);\r
235 \r
236 typedef void        ISC_EXPORT proto_sql_interprete (short,\r
237                                            char *,\r
238                                            short);\r
239 \r
240 typedef ISC_STATUS  ISC_EXPORT proto_interprete (char *,\r
241                                        ISC_STATUS * *);\r
242 \r
243 typedef ISC_STATUS  ISC_EXPORT proto_que_events (ISC_STATUS *,\r
244                                        isc_db_handle *,\r
245                                        ISC_LONG *,\r
246                                        short,\r
247                                        char *,\r
248                                        isc_callback,\r
249                                        void *);\r
250 \r
251 typedef ISC_STATUS  ISC_EXPORT proto_cancel_events (ISC_STATUS *,\r
252                                           isc_db_handle *,\r
253                                           ISC_LONG *);\r
254 \r
255 typedef ISC_STATUS  ISC_EXPORT proto_start_multiple (ISC_STATUS *,\r
256                                            isc_tr_handle *,\r
257                                            short,\r
258                                            void *);\r
259 \r
260 typedef ISC_STATUS  ISC_EXPORT proto_commit_transaction (ISC_STATUS *,\r
261                                                isc_tr_handle *);\r
262 \r
263 typedef ISC_STATUS  ISC_EXPORT proto_commit_retaining (ISC_STATUS *,\r
264                                              isc_tr_handle *);\r
265 \r
266 typedef ISC_STATUS  ISC_EXPORT proto_rollback_transaction (ISC_STATUS *,\r
267                                                  isc_tr_handle *);\r
268 \r
269 typedef ISC_STATUS  ISC_EXPORT proto_rollback_retaining (ISC_STATUS *,\r
270                                                  isc_tr_handle *);\r
271 \r
272 ///////////\r
273 typedef ISC_STATUS  ISC_EXPORT proto_dsql_allocate_statement (ISC_STATUS *,\r
274                                                     isc_db_handle *,\r
275                                                     isc_stmt_handle *);\r
276 \r
277 typedef ISC_STATUS  ISC_EXPORT proto_dsql_describe (ISC_STATUS *,\r
278                                           isc_stmt_handle *,\r
279                                           unsigned short,\r
280                                           XSQLDA *);\r
281 \r
282 typedef ISC_STATUS  ISC_EXPORT proto_dsql_describe_bind (ISC_STATUS *,\r
283                                                isc_stmt_handle *,\r
284                                                unsigned short,\r
285                                                XSQLDA *);\r
286 \r
287 typedef ISC_STATUS  ISC_EXPORT proto_dsql_execute (ISC_STATUS *,\r
288                                          isc_tr_handle *,\r
289                                          isc_stmt_handle *,\r
290                                          unsigned short,\r
291                                          XSQLDA *);\r
292 \r
293 typedef ISC_STATUS  ISC_EXPORT proto_dsql_execute2 (ISC_STATUS *,\r
294                                           isc_tr_handle *,\r
295                                           isc_stmt_handle *,\r
296                                           unsigned short,\r
297                                           XSQLDA *,\r
298                                           XSQLDA *);\r
299 \r
300 typedef ISC_STATUS  ISC_EXPORT proto_dsql_fetch (ISC_STATUS *,\r
301                                        isc_stmt_handle *,\r
302                                        unsigned short,\r
303                                        XSQLDA *);\r
304 \r
305 typedef ISC_STATUS  ISC_EXPORT proto_dsql_free_statement (ISC_STATUS *,\r
306                                                 isc_stmt_handle *,\r
307                                                 unsigned short);\r
308 \r
309 typedef ISC_STATUS  ISC_EXPORT proto_dsql_prepare (ISC_STATUS *,\r
310                                          isc_tr_handle *,\r
311                                          isc_stmt_handle *,\r
312                                          unsigned short,\r
313                                          char *,\r
314                                          unsigned short,\r
315                                          XSQLDA *);\r
316 \r
317 typedef ISC_STATUS  ISC_EXPORT proto_dsql_set_cursor_name (ISC_STATUS *,\r
318                                                  isc_stmt_handle *,\r
319                                                  char *,\r
320                                                  unsigned short);\r
321 \r
322 typedef ISC_STATUS  ISC_EXPORT proto_dsql_sql_info (ISC_STATUS *,\r
323                                           isc_stmt_handle *,\r
324                                           short,\r
325                                           char *,\r
326                                           short,\r
327                                           char *);\r
328 \r
329 typedef void        ISC_EXPORT proto_decode_date (ISC_QUAD *,\r
330                                         void *);\r
331 \r
332 typedef void        ISC_EXPORT proto_encode_date (void *,\r
333                                         ISC_QUAD *);\r
334 \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
338 \r
339 //\r
340 //      Those API are only available in versions 6.x of the GDS32.DLL\r
341 //\r
342 \r
343 typedef ISC_STATUS  ISC_EXPORT proto_service_attach (ISC_STATUS *,\r
344                                            unsigned short,\r
345                                            char *,\r
346                                            isc_svc_handle *,\r
347                                            unsigned short,\r
348                                            char *);\r
349 \r
350 typedef ISC_STATUS  ISC_EXPORT proto_service_detach (ISC_STATUS *,\r
351                                            isc_svc_handle *);\r
352 \r
353 typedef ISC_STATUS  ISC_EXPORT proto_service_query (ISC_STATUS *,\r
354                                           isc_svc_handle *,\r
355                                           isc_resv_handle *,\r
356                                           unsigned short,\r
357                                           char *,\r
358                                           unsigned short,\r
359                                           char *,\r
360                                           unsigned short,\r
361                                           char *);\r
362 \r
363 typedef ISC_STATUS ISC_EXPORT proto_service_start (ISC_STATUS *,\r
364                                          isc_svc_handle *,\r
365                                          isc_resv_handle *,\r
366                                          unsigned short,\r
367                                          char*);\r
368 \r
369 typedef void        ISC_EXPORT proto_decode_sql_date (ISC_DATE *,\r
370                                         void *);\r
371 \r
372 typedef void        ISC_EXPORT proto_decode_sql_time (ISC_TIME *,\r
373                                         void *);\r
374 \r
375 typedef void        ISC_EXPORT proto_decode_timestamp (ISC_TIMESTAMP *,\r
376                                         void *);\r
377 \r
378 typedef void        ISC_EXPORT proto_encode_sql_date (void *,\r
379                                         ISC_DATE *);\r
380 \r
381 typedef void        ISC_EXPORT proto_encode_sql_time (void *,\r
382                                         ISC_TIME *);\r
383 \r
384 typedef void        ISC_EXPORT proto_encode_timestamp (void *,\r
385                                         ISC_TIMESTAMP *);\r
386 \r
387 //\r
388 //      Internal binding structure to the GDS32 DLL\r
389 //\r
390 \r
391 struct GDS\r
392 {\r
393         // Attributes\r
394         bool mReady;\r
395         int mGDSVersion;                // Version of the GDS32.DLL (50 for 5.0, 60 for 6.0)\r
396 \r
397 #ifdef IBPP_WINDOWS\r
398         HMODULE mHandle;                        // The GDS32.DLL HMODULE\r
399         std::string mSearchPaths;       // Optional additional search paths\r
400 #endif\r
401 \r
402         GDS* Call();\r
403 \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
421 \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
448 \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
459 \r
460         // Constructor (No need for a specific destructor)\r
461         GDS()\r
462         {\r
463                 mReady = false;\r
464                 mGDSVersion = 0;\r
465 #ifdef IBPP_WINDOWS\r
466                 mHandle = 0;\r
467 #endif\r
468         }\r
469 };\r
470 \r
471 extern GDS gds;\r
472 \r
473 //\r
474 //      Service Parameter Block (used to define a service)\r
475 //\r
476 \r
477 class SPB\r
478 {\r
479         static const int BUFFERINCR;\r
480 \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
484 \r
485         void Grow(int needed);          // Alloc or grow the mBuffer\r
486 \r
487 public:\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
495 \r
496         SPB() : mBuffer(0), mSize(0), mAlloc(0) { }\r
497         ~SPB() { Reset(); }\r
498 };\r
499 \r
500 //\r
501 //      Database Parameter Block (used to define a database)\r
502 //\r
503 \r
504 class DPB\r
505 {\r
506         static const int BUFFERINCR;\r
507 \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
511 \r
512         void Grow(int needed);          // Allocate or grow the mBuffer, so that\r
513                                                                 // 'needed' bytes can be written (at least)\r
514 \r
515 public:\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
523 \r
524         DPB() : mBuffer(0), mSize(0), mAlloc(0) { }\r
525         ~DPB() { Reset(); }\r
526 };\r
527 \r
528 //\r
529 //      Transaction Parameter Block (used to define a transaction)\r
530 //\r
531 \r
532 class TPB\r
533 {\r
534         static const int BUFFERINCR;\r
535 \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
539 \r
540         void Grow(int needed);                  // Alloc or re-alloc the mBuffer\r
541 \r
542 public:\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
548 \r
549         TPB() : mBuffer(0), mSize(0), mAlloc(0) { }\r
550         ~TPB() { Reset(); }\r
551 };\r
552 \r
553 //\r
554 //      Used to receive (and process) a results buffer in various API calls\r
555 //\r
556 \r
557 class RB\r
558 {\r
559         char* mBuffer;\r
560         int mSize;\r
561 \r
562         char* FindToken(char token);\r
563         char* FindToken(char token, char subtoken);\r
564 \r
565 public:\r
566         void Reset();\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
572 \r
573         char* Self() { return mBuffer; }\r
574         short Size() { return (short)mSize; }\r
575 \r
576         RB();\r
577         RB(int Size);\r
578         ~RB();\r
579 };\r
580 \r
581 //\r
582 //      Used to receive status info from API calls\r
583 //\r
584 \r
585 class IBS\r
586 {\r
587         mutable ISC_STATUS mVector[20];\r
588         mutable std::string mMessage;\r
589 \r
590 public:\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
596         void Reset();\r
597 \r
598         IBS();\r
599         IBS(IBS&);      // Copy Constructor\r
600         ~IBS();\r
601 };\r
602 \r
603 ///////////////////////////////////////////////////////////////////////////////\r
604 //\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
609 //      is broken.\r
610 //\r
611 ///////////////////////////////////////////////////////////////////////////////\r
612 \r
613 //\r
614 // Hidden implementation of Exception classes.\r
615 //\r
616 \r
617 /*\r
618                          std::exception\r
619                                 |\r
620                          IBPP::Exception\r
621                        /                 \\r
622                       /                   \\r
623   IBPP::LogicException    ExceptionBase    IBPP::SQLException\r
624         |        \         /   |     \     /\r
625         |   LogicExceptionImpl |   SQLExceptionImpl\r
626         |                      |\r
627     IBPP::WrongType            |\r
628                \               |\r
629               IBPP::WrongTypeImpl\r
630 */\r
631 \r
632 class ExceptionBase\r
633 {\r
634         //      (((((((( OBJECT INTERNALS ))))))))\r
635 \r
636 protected:\r
637         std::string mContext;                   // Exception context ("IDatabase::Drop")\r
638         std::string mWhat;                              // Full formatted message\r
639 \r
640         void buildErrorMessage(const char* message);\r
641         void raise(const std::string& context, const char* message, va_list argptr);\r
642 \r
643 public:\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
647 \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
652 \r
653         virtual ~ExceptionBase() throw();\r
654 \r
655         //      (((((((( OBJECT INTERFACE ))))))))\r
656 \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
660 };\r
661 \r
662 class LogicExceptionImpl : public IBPP::LogicException, public ExceptionBase\r
663 {\r
664         //      (((((((( OBJECT INTERNALS ))))))))\r
665 \r
666 public:\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
670 \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
675 \r
676         virtual ~LogicExceptionImpl() throw ();\r
677 \r
678         //      (((((((( OBJECT INTERFACE ))))))))\r
679         //\r
680         //      The object public interface is partly implemented by inheriting from\r
681         //      the ExceptionBase class.\r
682 \r
683 public:\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
687 };\r
688 \r
689 class SQLExceptionImpl : public IBPP::SQLException, public ExceptionBase\r
690 {\r
691         //      (((((((( OBJECT INTERNALS ))))))))\r
692 \r
693 private:\r
694         int mSqlCode;\r
695         int mEngineCode;\r
696 \r
697 public:\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
701 \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
707 \r
708         virtual ~SQLExceptionImpl() throw ();\r
709 \r
710         //      (((((((( OBJECT INTERFACE ))))))))\r
711         //\r
712         //      The object public interface is partly implemented by inheriting from\r
713         //      the ExceptionBase class.\r
714 \r
715 public:\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
721 };\r
722 \r
723 class WrongTypeImpl : public IBPP::WrongType, public ExceptionBase\r
724 {\r
725         //      (((((((( OBJECT INTERNALS ))))))))\r
726 \r
727 public:\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
731 \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
737 \r
738         virtual ~WrongTypeImpl() throw ();\r
739 \r
740         //      (((((((( OBJECT INTERFACE ))))))))\r
741         //\r
742         //      The object public interface is partly implemented by inheriting from\r
743         //      the ExceptionBase class.\r
744 \r
745 public:\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
749 };\r
750 \r
751 class ServiceImpl : public IBPP::IService\r
752 {\r
753         //      (((((((( OBJECT INTERNALS ))))))))\r
754 \r
755 private:\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
762 \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
767 \r
768 public:\r
769         isc_svc_handle GetHandle() { return mHandle; }\r
770 \r
771         ServiceImpl(const std::string& ServerName, const std::string& UserName,\r
772                                         const std::string& UserPassword);\r
773     ~ServiceImpl();\r
774 \r
775         //      (((((((( OBJECT INTERFACE ))))))))\r
776 \r
777 public:\r
778     void Connect();\r
779         bool Connected() { return mHandle == 0 ? false : true; }\r
780         void Disconnect();\r
781 \r
782         void GetVersion(std::string& version);\r
783 \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
789 \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
795 \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
800 \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
805 \r
806         const char* WaitMsg();\r
807         void Wait();\r
808 \r
809         IBPP::IService* AddRef();\r
810         void Release();\r
811 };\r
812 \r
813 class DatabaseImpl : public IBPP::IDatabase\r
814 {\r
815         //      (((((((( OBJECT INTERNALS ))))))))\r
816 \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
826 \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
833 \r
834 public:\r
835         isc_db_handle* GetHandlePtr() { return &mHandle; }\r
836         isc_db_handle GetHandle() { return mHandle; }\r
837 \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
848 \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
853     ~DatabaseImpl();\r
854 \r
855         //      (((((((( OBJECT INTERFACE ))))))))\r
856 \r
857 public:\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
865 \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
874 \r
875     void Create(int dialect);\r
876         void Connect();\r
877         bool Connected() { return mHandle == 0 ? false : true; }\r
878         void Inactivate();\r
879         void Disconnect();\r
880     void Drop();\r
881 \r
882         IBPP::IDatabase* AddRef();\r
883         void Release();\r
884 };\r
885 \r
886 class TransactionImpl : public IBPP::ITransaction\r
887 {\r
888         //      (((((((( OBJECT INTERNALS ))))))))\r
889 \r
890 private:\r
891         int mRefCount;                                  // Reference counter\r
892     isc_tr_handle mHandle;                      // Transaction InterBase\r
893 \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
899 \r
900         void Init();                    // A usage exclusif des constructeurs\r
901 \r
902 public:\r
903         isc_tr_handle* GetHandlePtr() { return &mHandle; }\r
904         isc_tr_handle GetHandle() { return mHandle; }\r
905 \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
916 \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
921 \r
922         //      (((((((( OBJECT INTERFACE ))))))))\r
923 \r
924 public:\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
931 \r
932     void Start();\r
933         bool Started() { return mHandle == 0 ? false : true; }\r
934     void Commit();\r
935     void Rollback();\r
936     void CommitRetain();\r
937         void RollbackRetain();\r
938 \r
939         IBPP::ITransaction* AddRef();\r
940         void Release();\r
941 };\r
942 \r
943 class RowImpl : public IBPP::IRow\r
944 {\r
945         //      (((((((( OBJECT INTERNALS ))))))))\r
946 \r
947 private:\r
948         int mRefCount;                                  // Reference counter\r
949 \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
959 \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
963 \r
964         void SetValue(int, IITYPE, const void* value, int = 0);\r
965         void* GetValue(int, IITYPE, void* = 0);\r
966 \r
967 public:\r
968         void Free();\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
974 \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
978     ~RowImpl();\r
979 \r
980         //      (((((((( OBJECT INTERFACE ))))))))\r
981 \r
982 public:\r
983         void SetNull(int);\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
999 \r
1000         bool IsNull(int);\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
1016 \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
1033 \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
1042         int Columns();\r
1043 \r
1044         bool ColumnUpdated(int);\r
1045         bool Updated();\r
1046 \r
1047         IBPP::Database DatabasePtr() const;\r
1048         IBPP::Transaction TransactionPtr() const;\r
1049 \r
1050         IBPP::IRow* Clone();\r
1051         IBPP::IRow* AddRef();\r
1052         void Release();\r
1053 };\r
1054 \r
1055 class StatementImpl : public IBPP::IStatement\r
1056 {\r
1057         //      (((((((( OBJECT INTERNALS ))))))))\r
1058 \r
1059 private:\r
1060         friend class TransactionImpl;\r
1061 \r
1062         int mRefCount;                          // Reference counter\r
1063         isc_stmt_handle mHandle;        // Statement Handle\r
1064 \r
1065         DatabaseImpl* mDatabase;                // Attached database\r
1066         TransactionImpl* mTransaction;  // Attached transaction\r
1067         RowImpl* mInRow;\r
1068         //bool* mInMissing;                     // Quels paramètres n'ont pas Ã©té spécifiés\r
1069         RowImpl* mOutRow;\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
1074 \r
1075         // Internal Methods\r
1076         void CursorFree();\r
1077 \r
1078 public:\r
1079         // Properties and Attributes Access Methods\r
1080         isc_stmt_handle GetHandle() { return mHandle; }\r
1081 \r
1082         void AttachDatabaseImpl(DatabaseImpl*);\r
1083         void DetachDatabaseImpl();\r
1084         void AttachTransactionImpl(TransactionImpl*);\r
1085         void DetachTransactionImpl();\r
1086 \r
1087         StatementImpl(DatabaseImpl*, TransactionImpl*, const std::string&);\r
1088     ~StatementImpl();\r
1089 \r
1090         //      (((((((( OBJECT INTERFACE ))))))))\r
1091 \r
1092 public:\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
1099         bool Fetch();\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
1105 \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
1122 \r
1123         bool IsNull(int);\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
1145 \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
1168 \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
1178         int Columns();\r
1179 \r
1180         IBPP::SDT ParameterType(int);\r
1181         int ParameterSubtype(int);\r
1182         int ParameterSize(int);\r
1183         int ParameterScale(int);\r
1184         int Parameters();\r
1185 \r
1186         void Plan(std::string&);\r
1187 \r
1188         IBPP::Database DatabasePtr() const;\r
1189         IBPP::Transaction TransactionPtr() const;\r
1190 \r
1191         IBPP::IStatement* AddRef();\r
1192         void Release();\r
1193 };\r
1194 \r
1195 class BlobImpl : public IBPP::IBlob\r
1196 {\r
1197         //      (((((((( OBJECT INTERNALS ))))))))\r
1198 \r
1199 private:\r
1200         friend class RowImpl;\r
1201 \r
1202         int mRefCount;\r
1203         bool                                    mIdAssigned;\r
1204         ISC_QUAD                                mId;\r
1205         isc_blob_handle                 mHandle;\r
1206         bool                                    mWriteMode;\r
1207         DatabaseImpl*                   mDatabase;              // Belongs to this database\r
1208         TransactionImpl*                mTransaction;   // Belongs to this transaction\r
1209 \r
1210         void Init();\r
1211         void SetId(ISC_QUAD*);\r
1212         void GetId(ISC_QUAD*);\r
1213 \r
1214 public:\r
1215         void AttachDatabaseImpl(DatabaseImpl*);\r
1216         void DetachDatabaseImpl();\r
1217         void AttachTransactionImpl(TransactionImpl*);\r
1218         void DetachTransactionImpl();\r
1219 \r
1220         BlobImpl(const BlobImpl&);\r
1221         BlobImpl(DatabaseImpl*, TransactionImpl* = 0);\r
1222         ~BlobImpl();\r
1223 \r
1224         //      (((((((( OBJECT INTERFACE ))))))))\r
1225 \r
1226 public:\r
1227         void Create();\r
1228         void Open();\r
1229         void Close();\r
1230         void Cancel();\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
1234 \r
1235         void Save(const std::string& data);\r
1236         void Load(std::string& data);\r
1237 \r
1238         IBPP::Database DatabasePtr() const;\r
1239         IBPP::Transaction TransactionPtr() const;\r
1240 \r
1241         IBPP::IBlob* AddRef();\r
1242         void Release();\r
1243 };\r
1244 \r
1245 class ArrayImpl : public IBPP::IArray\r
1246 {\r
1247         //      (((((((( OBJECT INTERNALS ))))))))\r
1248 \r
1249 private:\r
1250         friend class RowImpl;\r
1251 \r
1252         int                                     mRefCount;              // Reference counter\r
1253         bool                            mIdAssigned;\r
1254         ISC_QUAD                        mId;\r
1255         bool                            mDescribed;\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
1263 \r
1264         void Init();\r
1265         void SetId(ISC_QUAD*);\r
1266         void GetId(ISC_QUAD*);\r
1267         void ResetId();\r
1268         void AllocArrayBuffer();\r
1269 \r
1270 public:\r
1271         void AttachDatabaseImpl(DatabaseImpl*);\r
1272         void DetachDatabaseImpl();\r
1273         void AttachTransactionImpl(TransactionImpl*);\r
1274         void DetachTransactionImpl();\r
1275 \r
1276         ArrayImpl(const ArrayImpl&);\r
1277         ArrayImpl(DatabaseImpl*, TransactionImpl* = 0);\r
1278         ~ArrayImpl();\r
1279 \r
1280         //      (((((((( OBJECT INTERFACE ))))))))\r
1281 \r
1282 public:\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
1289         int Dimensions();\r
1290         void Bounds(int dim, int* low, int* high);\r
1291         void SetBounds(int dim, int low, int high);\r
1292 \r
1293         IBPP::Database DatabasePtr() const;\r
1294         IBPP::Transaction TransactionPtr() const;\r
1295 \r
1296         IBPP::IArray* AddRef();\r
1297         void Release();\r
1298 };\r
1299 \r
1300 //\r
1301 //      EventBufferIterator: used in EventsImpl implementation.\r
1302 //\r
1303 \r
1304 template<class It>\r
1305 struct EventBufferIterator\r
1306 {\r
1307         It mIt;\r
1308 \r
1309 public:\r
1310         EventBufferIterator& operator++()\r
1311                 { mIt += 1 + static_cast<int>(*mIt) + 4; return *this; }\r
1312 \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
1315 \r
1316 #ifdef __BCPLUSPLUS__\r
1317 #pragma warn -8027\r
1318 #endif\r
1319         std::string get_name() const\r
1320         {\r
1321                 return std::string(mIt + 1, mIt + 1 + static_cast<int32_t>(*mIt));\r
1322         }\r
1323 #ifdef __BCPLUSPLUS__\r
1324 #pragma warn .8027\r
1325 #endif\r
1326 \r
1327         uint32_t get_count() const\r
1328         {\r
1329                 return (*gds.Call()->m_vax_integer)\r
1330                         (const_cast<char*>(&*(mIt + 1 + static_cast<int>(*mIt))), 4);\r
1331         }\r
1332 \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
1336 \r
1337         EventBufferIterator() {}\r
1338         EventBufferIterator(It it) : mIt(it) {}\r
1339 };\r
1340 \r
1341 class EventsImpl : public IBPP::IEvents\r
1342 {\r
1343         static const size_t MAXEVENTNAMELEN;\r
1344         static void EventHandler(const char*, short, const char*);\r
1345 \r
1346         typedef std::vector<IBPP::EventInterface*> ObjRefs;\r
1347         ObjRefs mObjectReferences;\r
1348 \r
1349         typedef std::vector<char> Buffer;\r
1350         Buffer mEventBuffer;\r
1351         Buffer mResultsBuffer;\r
1352 \r
1353         int mRefCount;          // Reference counter\r
1354 \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
1359 \r
1360         void FireActions();\r
1361         void Queue();\r
1362         void Cancel();\r
1363 \r
1364         EventsImpl& operator=(const EventsImpl&);\r
1365         EventsImpl(const EventsImpl&);\r
1366 \r
1367 public:\r
1368         void AttachDatabaseImpl(DatabaseImpl*);\r
1369         void DetachDatabaseImpl();\r
1370         \r
1371         EventsImpl(DatabaseImpl* dbi);\r
1372         ~EventsImpl();\r
1373                 \r
1374         //      (((((((( OBJECT INTERFACE ))))))))\r
1375 \r
1376 public:\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
1382 \r
1383         IBPP::Database DatabasePtr() const;\r
1384 \r
1385         IBPP::IEvents* AddRef();\r
1386         void Release();\r
1387 };\r
1388 \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
1391 \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
1394 \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
1397 \r
1398 struct consts   // See _ibpp.cpp for initializations of these constants\r
1399 {\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
1406 };\r
1407 \r
1408 }       // namespace ibpp_internal\r
1409 \r
1410 #endif // __INTERNAL_IBPP_H__\r
1411 \r
1412 //\r
1413 //      Eof\r
1414 //\r