1 ///////////////////////////////////////////////////////////////////////////////
\r
3 // File : $Id: _dpb.cpp,v 1.2 2009/03/19 20:00:27 faust Exp $
\r
4 // Subject : IBPP, internal DPB class implementation
\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
23 // * DPB == Database Parameter Block/Buffer, see Interbase 6.0 C-API
\r
24 // * Tabulations should be set every four characters when editing this file.
\r
26 ///////////////////////////////////////////////////////////////////////////////
\r
29 #pragma warning(disable: 4786 4996)
\r
31 #pragma warning(disable: 4702)
\r
43 using namespace ibpp_internals;
\r
45 const int DPB::BUFFERINCR = 128;
\r
47 void DPB::Grow(int needed)
\r
49 if (mBuffer == 0) ++needed; // Initial alloc will require one more byte
\r
50 if ((mSize + needed) > mAlloc)
\r
52 // We need to grow the buffer. We use increments of BUFFERINCR bytes.
\r
53 needed = (needed / BUFFERINCR + 1) * BUFFERINCR;
\r
54 char* newbuffer = new char[mAlloc + needed];
\r
57 // Initial allocation, initialize the version tag
\r
58 newbuffer[0] = isc_dpb_version1;
\r
63 // Move the old buffer content to the new one
\r
64 memcpy(newbuffer, mBuffer, mSize);
\r
67 mBuffer = newbuffer;
\r
72 void DPB::Insert(char type, const char* data)
\r
74 int len = (int)strlen(data);
\r
76 mBuffer[mSize++] = type;
\r
77 mBuffer[mSize++] = char(len);
\r
78 strncpy(&mBuffer[mSize], data, len);
\r
82 void DPB::Insert(char type, int16_t data)
\r
85 mBuffer[mSize++] = type;
\r
86 mBuffer[mSize++] = char(2);
\r
87 *(int16_t*)&mBuffer[mSize] = int16_t((*gds.Call()->m_vax_integer)((char*)&data, 2));
\r
91 void DPB::Insert(char type, bool data)
\r
94 mBuffer[mSize++] = type;
\r
95 mBuffer[mSize++] = char(1);
\r
96 mBuffer[mSize++] = char(data ? 1 : 0);
\r
99 void DPB::Insert(char type, char data)
\r
102 mBuffer[mSize++] = type;
\r
103 mBuffer[mSize++] = char(1);
\r
104 mBuffer[mSize++] = data;
\r