[go: up one dir, main page]

Menu

[r110]: / trunk / core / _rb.cpp  Maximize  Restore  History

Download this file

206 lines (169 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
///////////////////////////////////////////////////////////////////////////////
//
// File : $Id$
// Subject : IBPP, internal RB class implementation
//
///////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright 2000-2007 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)
//
// The contents of this file are subject to the IBPP License (the "License");
// you may not use this file except in compliance with the License. You may
// obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'
// file which must have been distributed along with this file.
//
// This software, distributed under the License, is distributed on an "AS IS"
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
///////////////////////////////////////////////////////////////////////////////
//
// COMMENTS
// * RB == Result Block/Buffer, see Interbase 6.0 C-API
// * Tabulations should be set every four characters when editing this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifdef _MSC_VER
#pragma warning(disable: 4786 4996)
#ifndef _DEBUG
#pragma warning(disable: 4702)
#endif
#endif
#include "_ibpp.h"
#ifdef HAS_HDRSTOP
#pragma hdrstop
#endif
using namespace ibpp_internals;
char* RB::FindToken(char token)
{
char* p = mBuffer;
while (*p != isc_info_end)
{
int len;
if (*p == token) return p;
len = (mDriver->m_vax_integer)(p+1, 2);
p += (len + 3);
}
return 0;
}
char* RB::FindToken(char token, char subtoken)
{
char* p = mBuffer;
while (*p != isc_info_end)
{
int len;
if (*p == token)
{
// Found token, now find subtoken
int inlen = (mDriver->m_vax_integer)(p+1, 2);
p += 3;
while (inlen > 0)
{
if (*p == subtoken) return p;
len = (mDriver->m_vax_integer)(p+1, 2);
p += (len + 3);
inlen -= (len + 3);
}
return 0;
}
len = (mDriver->m_vax_integer)(p+1, 2);
p += (len + 3);
}
return 0;
}
int RB::GetValue(char token)
{
int value;
int len;
char* p = FindToken(token);
if (p == 0)
throw LogicExceptionImpl("RB::GetValue", _("Token not found."));
len = (mDriver->m_vax_integer)(p+1, 2);
if (len == 0) value = 0;
else value = (mDriver->m_vax_integer)(p+3, (short)len);
return value;
}
int RB::GetCountValue(char token)
{
// Specifically used on tokens like isc_info_insert_count and the like
// which return detailed counts per relation. We sum up the values.
int value;
int len;
char* p = FindToken(token);
if (p == 0)
throw LogicExceptionImpl("RB::GetCountValue", _("Token not found."));
// len is the number of bytes in the following array
len = (mDriver->m_vax_integer)(p+1, 2);
p += 3;
value = 0;
while (len > 0)
{
// Each array item is 6 bytes : 2 bytes for the relation_id which
// we skip, and 4 bytes for the count value which we sum up accross
// all tables.
value += (mDriver->m_vax_integer)(p+2, 4);
p += 6;
len -= 6;
}
return value;
}
int RB::GetValue(char token, char subtoken)
{
int value;
int len;
char* p = FindToken(token, subtoken);
if (p == 0)
throw LogicExceptionImpl("RB::GetValue", _("Token/Subtoken not found."));
len = (mDriver->m_vax_integer)(p+1, 2);
if (len == 0) value = 0;
else value = (mDriver->m_vax_integer)(p+3, (short)len);
return value;
}
bool RB::GetBool(char token)
{
int value;
char* p = FindToken(token);
if (p == 0)
throw LogicExceptionImpl("RB::GetBool", _("Token not found."));
value = (mDriver->m_vax_integer)(p+1, 4);
return value == 0 ? false : true;
}
int RB::GetString(char token, std::string& data)
{
int len;
char* p = FindToken(token);
if (p == 0)
throw LogicExceptionImpl("RB::GetString", _("Token not found."));
len = (mDriver->m_vax_integer)(p+1, 2);
data = std::string(p+3, len);
return len;
}
void RB::Reset()
{
delete [] mBuffer;
mBuffer = new char [mSize];
memset(mBuffer, 255, mSize);
}
RB::RB(DriverImpl* drv)
{
mDriver = drv;
mSize = 1024;
mBuffer = new char [1024];
memset(mBuffer, 255, mSize);
}
RB::RB(DriverImpl* drv, int Size)
{
mDriver = drv;
mSize = Size;
mBuffer = new char [Size];
memset(mBuffer, 255, mSize);
}
RB::~RB()
{
try { delete [] mBuffer; }
catch (...) { }
}
//
// EOF
//