/usr/include/Poco/Data/ODBC/Preparation.h is in libpoco-dev 1.3.6p1-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | //
// Preparation.h
//
// $Id: //poco/1.3/Data/ODBC/include/Poco/Data/ODBC/Preparation.h#6 $
//
// Library: Data/ODBC
// Package: ODBC
// Module: Preparation
//
// Definition of the Preparation class.
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#ifndef DataConnectors_ODBC_Preparation_INCLUDED
#define DataConnectors_ODBC_Preparation_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Handle.h"
#include "Poco/Data/ODBC/ODBCColumn.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/AbstractPreparation.h"
#include "Poco/Data/BLOB.h"
#include "Poco/Any.h"
#include "Poco/SharedPtr.h"
#include <vector>
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
#endif
#include <sqlext.h>
namespace Poco {
namespace Data {
namespace ODBC {
class BLOB;
class ODBC_API Preparation : public AbstractPreparation
/// Class used for database preparation where we first have to register all data types
/// with respective memory output locations before extracting data.
/// Extraction works in two-phases: first prepare is called once, then extract n-times.
/// In ODBC, SQLBindCol/SQLFetch is the preferred method of data retrieval (SQLGetData is available,
/// however with numerous driver implementation dependent limitations). In order to fit this functionality
/// into Poco DataConnectors framework, every ODBC SQL statement instantiates its own Preparation object.
/// This is done once per statement execution (from StatementImpl::bindImpl()).
///
/// Preparation object is used to :
///
/// 1) Prepare SQL statement.
/// 2) Provide and contain the memory locations where retrieved values are placed during recordset iteration.
/// 3) Keep count of returned number of columns with their respective datatypes and sizes.
///
/// Notes:
///
/// - Value datatypes in this interface prepare() calls serve only for the purpose of type distinction.
/// - Preparation keeps its own std::vector<Any> buffer for fetched data to be later retrieved by Extractor.
/// - prepare() methods should not be called when extraction mode is DE_MANUAL
///
{
public:
enum DataExtraction
{
DE_MANUAL,
DE_BOUND
};
Preparation(const StatementHandle& rStmt,
const std::string& statement,
std::size_t maxFieldSize,
DataExtraction dataExtraction = DE_BOUND);
/// Creates the Preparation.
~Preparation();
/// Destroys the Preparation.
void prepare(std::size_t pos, Poco::Int8);
/// Prepares an Int8.
void prepare(std::size_t pos, Poco::UInt8);
/// Prepares an UInt8.
void prepare(std::size_t pos, Poco::Int16);
/// Prepares an Int16.
void prepare(std::size_t pos, Poco::UInt16);
/// Prepares an UInt16.
void prepare(std::size_t pos, Poco::Int32);
/// Prepares an Int32.
void prepare(std::size_t pos, Poco::UInt32);
/// Prepares an UInt32.
void prepare(std::size_t pos, Poco::Int64);
/// Prepares an Int64.
void prepare(std::size_t pos, Poco::UInt64);
/// Prepares an UInt64.
void prepare(std::size_t pos, bool);
/// Prepares a boolean.
void prepare(std::size_t pos, float);
/// Prepares a float.
void prepare(std::size_t pos, double);
/// Prepares a double.
void prepare(std::size_t pos, char);
/// Prepares a single character.
void prepare(std::size_t pos, const std::string&);
/// Prepares a string.
void prepare(std::size_t pos, const Poco::Data::BLOB&);
/// Prepares a BLOB.
void prepare(std::size_t pos, const Poco::Any&);
/// Prepares an Any.
std::size_t columns() const;
/// Returns the number of columns.
Poco::Any& operator [] (std::size_t pos);
/// Returns reference to column data.
void setMaxFieldSize(std::size_t size);
/// Sets maximum supported field size.
std::size_t getMaxFieldSize() const;
// Returns maximum supported field size.
std::size_t maxDataSize(std::size_t pos) const;
/// Returns max supported size for column at position pos.
/// Returned length for variable length fields is the one
/// supported by this implementation, not the underlying DB.
std::size_t actualDataSize(std::size_t pos) const;
/// Returns the returned length. This is usually
/// equal to the column size, except for variable length fields
/// (BLOB and variable length strings).
void setDataExtraction(DataExtraction ext);
/// Set data extraction mode.
DataExtraction getDataExtraction() const;
/// Returns data extraction mode.
private:
template <typename T>
void preparePOD(std::size_t pos, SQLSMALLINT valueType)
{
poco_assert (DE_BOUND == _dataExtraction);
poco_assert (pos >= 0 && pos < _pValues.size());
std::size_t dataSize = sizeof(T);
_pValues[pos] = new Poco::Any(T());
_pLengths[pos] = new SQLLEN;
*_pLengths[pos] = 0;
T* pVal = AnyCast<T>(_pValues[pos]);
poco_assert_dbg (pVal);
if (Utility::isError(SQLBindCol(_rStmt,
(SQLUSMALLINT) pos + 1,
valueType,
(SQLPOINTER) pVal,
(SQLINTEGER) dataSize,
_pLengths[pos])))
{
throw StatementException(_rStmt, "SQLBindCol()");
}
}
void prepareRaw(std::size_t pos, SQLSMALLINT valueType, std::size_t size);
const StatementHandle& _rStmt;
std::vector<Poco::Any*> _pValues;
std::vector<SQLLEN*> _pLengths;
std::size_t _maxFieldSize;
DataExtraction _dataExtraction;
std::vector<char*> _charPtrs;
};
//
// inlines
//
inline void Preparation::prepare(std::size_t pos, Poco::Int8)
{
preparePOD<Poco::Int8>(pos, SQL_C_STINYINT);
}
inline void Preparation::prepare(std::size_t pos, Poco::UInt8)
{
preparePOD<Poco::UInt8>(pos, SQL_C_UTINYINT);
}
inline void Preparation::prepare(std::size_t pos, Poco::Int16)
{
preparePOD<Poco::Int16>(pos, SQL_C_SSHORT);
}
inline void Preparation::prepare(std::size_t pos, Poco::UInt16)
{
preparePOD<Poco::UInt16>(pos, SQL_C_USHORT);
}
inline void Preparation::prepare(std::size_t pos, Poco::Int32)
{
preparePOD<Poco::Int32>(pos, SQL_C_SLONG);
}
inline void Preparation::prepare(std::size_t pos, Poco::UInt32)
{
preparePOD<Poco::UInt32>(pos, SQL_C_ULONG);
}
inline void Preparation::prepare(std::size_t pos, Poco::Int64)
{
preparePOD<Poco::Int64>(pos, SQL_C_SBIGINT);
}
inline void Preparation::prepare(std::size_t pos, Poco::UInt64)
{
preparePOD<Poco::UInt64>(pos, SQL_C_UBIGINT);
}
inline void Preparation::prepare(std::size_t pos, bool)
{
preparePOD<bool>(pos, SQL_C_BIT);
}
inline void Preparation::prepare(std::size_t pos, float)
{
preparePOD<float>(pos, SQL_C_FLOAT);
}
inline void Preparation::prepare(std::size_t pos, double)
{
preparePOD<double>(pos, SQL_C_DOUBLE);
}
inline void Preparation::prepare(std::size_t pos, char)
{
preparePOD<char>(pos, SQL_C_STINYINT);
}
inline void Preparation::prepare(std::size_t pos, const std::string&)
{
prepareRaw(pos, SQL_C_CHAR, maxDataSize(pos));
}
inline void Preparation::prepare(std::size_t pos, const Poco::Data::BLOB&)
{
prepareRaw(pos, SQL_C_BINARY, maxDataSize(pos));
}
inline std::size_t Preparation::columns() const
{
return _pValues.size();
}
inline std::size_t Preparation::actualDataSize(std::size_t pos) const
{
poco_assert (pos >= 0 && pos < _pValues.size());
poco_assert (_pLengths[pos]);
return *_pLengths[pos];
}
inline void Preparation::setMaxFieldSize(std::size_t size)
{
_maxFieldSize = size;
}
inline std::size_t Preparation::getMaxFieldSize() const
{
return _maxFieldSize;
}
inline void Preparation::setDataExtraction(Preparation::DataExtraction ext)
{
_dataExtraction = ext;
}
inline Preparation::DataExtraction Preparation::getDataExtraction() const
{
return _dataExtraction;
}
} } } // namespace Poco::Data::ODBC
#endif // DataConnectors_ODBC_Preparation_INCLUDED
|