Merge branch 'master' into parameters-rename-query

This commit is contained in:
Nikolay Degterinsky 2023-02-15 10:53:44 +01:00 committed by GitHub
commit 24bbf885db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
848 changed files with 100338 additions and 100196 deletions

View File

@ -2,7 +2,7 @@
name: Debug
'on':
[push, pull_request, release, workflow_dispatch, workflow_call]
[push, pull_request, pull_request_review, release, workflow_dispatch, workflow_call]
jobs:
DebugInfo:

View File

@ -0,0 +1,23 @@
name: PullRequestApprovedCI
env:
# Force the stdout and stderr streams to be unbuffered
PYTHONUNBUFFERED: 1
on: # yamllint disable-line rule:truthy
pull_request_review:
types:
- submitted
jobs:
MergeOnApproval:
runs-on: [self-hosted, style-checker]
steps:
- name: Check out repository code
uses: ClickHouse/checkout@v1
with:
clear-repository: true
- name: Merge approved PR
run: |
cd "$GITHUB_WORKSPACE/tests/ci"
python3 merge_pr.py --check-approved

View File

@ -476,7 +476,12 @@ enable_testing() # Enable for tests without binary
option(ENABLE_OPENSSL "This option performs a build with OpenSSL. NOTE! This option is insecure and should never be used. By default, ClickHouse uses and only supports BoringSSL" OFF)
option(ENABLE_OPENSSL_DYNAMIC "This option removes SSL from ClickHouse and will link to the OpenSSL version supplied by OS." OFF)
if (ARCH_S390X)
set(ENABLE_OPENSSL_DYNAMIC_DEFAULT ON)
else ()
set(ENABLE_OPENSSL_DYNAMIC_DEFAULT OFF)
endif ()
option(ENABLE_OPENSSL_DYNAMIC "This option removes SSL from ClickHouse and will link to the OpenSSL version supplied by OS." ${ENABLE_OPENSSL_DYNAMIC_DEFAULT})
# when installing to /usr - place configs to /etc but for /usr/local place to /usr/local/etc
if (CMAKE_INSTALL_PREFIX STREQUAL "/usr")

View File

@ -84,7 +84,10 @@ if (OS MATCHES "Linux"
set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-aarch64.cmake" CACHE INTERNAL "")
elseif (ARCH MATCHES "^(ppc64le.*|PPC64LE.*)")
set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-ppc64le.cmake" CACHE INTERNAL "")
elseif (ARCH MATCHES "^(s390x.*|S390X.*)")
set (CMAKE_TOOLCHAIN_FILE "cmake/linux/toolchain-s390x.cmake" CACHE INTERNAL "")
else ()
message (FATAL_ERROR "Unsupported architecture: ${ARCH}")
endif ()
endif()

View File

@ -28,8 +28,8 @@
#define NO_INLINE __attribute__((__noinline__))
#define MAY_ALIAS __attribute__((__may_alias__))
#if !defined(__x86_64__) && !defined(__aarch64__) && !defined(__PPC__) && !(defined(__riscv) && (__riscv_xlen == 64))
# error "The only supported platforms are x86_64 and AArch64, PowerPC (work in progress) and RISC-V 64 (experimental)"
#if !defined(__x86_64__) && !defined(__aarch64__) && !defined(__PPC__) && !defined(__s390x__) && !(defined(__riscv) && (__riscv_xlen == 64))
# error "The only supported platforms are x86_64 and AArch64, PowerPC (work in progress), s390x (work in progress) and RISC-V 64 (experimental)"
#endif
/// Check for presence of address sanitizer

View File

@ -360,7 +360,7 @@ struct integer<Bits, Signed>::_impl
constexpr const unsigned to_copy = min_bits / base_bits;
for (unsigned i = 0; i < to_copy; ++i)
self.items[little(i)] = rhs.items[little(i)];
self.items[little(i)] = rhs.items[integer<Bits2, Signed2>::_impl::little(i)];
if constexpr (Bits > Bits2)
{

View File

@ -18,22 +18,24 @@
#define Crypto_Cipher_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <istream>
#include <ostream>
#include <vector>
#include "Poco/AutoPtr.h"
#include "Poco/Crypto/Crypto.h"
#include "Poco/RefCountedObject.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class CryptoTransform;
class CryptoTransform;
class Crypto_API Cipher: public Poco::RefCountedObject
class Crypto_API Cipher : public Poco::RefCountedObject
/// Represents the abstract base class from which all implementations of
/// symmetric/asymmetric encryption algorithms must inherit. Use the CipherFactory
/// class to obtain an instance of this class:
@ -82,8 +84,8 @@ class Crypto_API Cipher: public Poco::RefCountedObject
/// // Always close output streams to flush all internal buffers
/// encryptor.close();
/// sink.close();
{
public:
{
public:
typedef Poco::AutoPtr<Cipher> Ptr;
typedef std::vector<unsigned char> ByteVec;
@ -101,38 +103,39 @@ public:
virtual ~Cipher();
/// Destroys the Cipher.
virtual const std::string& name() const = 0;
virtual const std::string & name() const = 0;
/// Returns the name of the Cipher.
virtual CryptoTransform* createEncryptor() = 0;
virtual CryptoTransform * createEncryptor() = 0;
/// Creates an encryptor object to be used with a CryptoStream.
virtual CryptoTransform* createDecryptor() = 0;
virtual CryptoTransform * createDecryptor() = 0;
/// Creates a decryptor object to be used with a CryptoStream.
virtual std::string encryptString(const std::string& str, Encoding encoding = ENC_NONE);
virtual std::string encryptString(const std::string & str, Encoding encoding = ENC_NONE);
/// Directly encrypt a string and encode it using the given encoding.
virtual std::string decryptString(const std::string& str, Encoding encoding = ENC_NONE);
virtual std::string decryptString(const std::string & str, Encoding encoding = ENC_NONE);
/// Directly decrypt a string that is encoded with the given encoding.
virtual void encrypt(std::istream& source, std::ostream& sink, Encoding encoding = ENC_NONE);
virtual void encrypt(std::istream & source, std::ostream & sink, Encoding encoding = ENC_NONE);
/// Directly encrypts an input stream and encodes it using the given encoding.
virtual void decrypt(std::istream& source, std::ostream& sink, Encoding encoding = ENC_NONE);
virtual void decrypt(std::istream & source, std::ostream & sink, Encoding encoding = ENC_NONE);
/// Directly decrypt an input stream that is encoded with the given encoding.
protected:
protected:
Cipher();
/// Creates a new Cipher object.
private:
Cipher(const Cipher&);
Cipher& operator = (const Cipher&);
};
private:
Cipher(const Cipher &);
Cipher & operator=(const Cipher &);
};
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_Cipher_INCLUDED

View File

@ -21,27 +21,29 @@
#include "Poco/Crypto/Crypto.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class Cipher;
class CipherKey;
class RSAKey;
class Cipher;
class CipherKey;
class RSAKey;
class Crypto_API CipherFactory
class Crypto_API CipherFactory
/// A factory for Cipher objects. See the Cipher class for examples on how to
/// use the CipherFactory.
{
public:
{
public:
CipherFactory();
/// Creates a new CipherFactory object.
virtual ~CipherFactory();
/// Destroys the CipherFactory.
Cipher* createCipher(const CipherKey& key);
Cipher * createCipher(const CipherKey & key);
/// Creates a Cipher object for the given Cipher name. Valid cipher
/// names depend on the OpenSSL version the library is linked with;
/// see the output of
@ -56,20 +58,21 @@ public:
/// * DES: "des", "des3"
/// * Blowfish: "bf"
Cipher* createCipher(const RSAKey& key, RSAPaddingMode paddingMode = RSA_PADDING_PKCS1);
Cipher * createCipher(const RSAKey & key, RSAPaddingMode paddingMode = RSA_PADDING_PKCS1);
/// Creates a RSACipher using the given RSA key and padding mode
/// for public key encryption/private key decryption.
static CipherFactory& defaultFactory();
static CipherFactory & defaultFactory();
/// Returns the default CipherFactory.
private:
CipherFactory(const CipherFactory&);
CipherFactory& operator = (const CipherFactory&);
};
private:
CipherFactory(const CipherFactory &);
CipherFactory & operator=(const CipherFactory &);
};
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_CipherFactory_INCLUDED

View File

@ -18,52 +18,55 @@
#define Crypto_CipherImpl_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include <openssl/evp.h>
#include "Poco/Crypto/Cipher.h"
#include "Poco/Crypto/CipherKey.h"
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include <openssl/evp.h>
namespace Poco {
namespace Crypto {
class CipherImpl: public Cipher
/// An implementation of the Cipher class for OpenSSL's crypto library.
namespace Poco
{
public:
CipherImpl(const CipherKey& key);
namespace Crypto
{
class CipherImpl : public Cipher
/// An implementation of the Cipher class for OpenSSL's crypto library.
{
public:
CipherImpl(const CipherKey & key);
/// Creates a new CipherImpl object for the given CipherKey.
virtual ~CipherImpl();
/// Destroys the CipherImpl.
const std::string& name() const;
const std::string & name() const;
/// Returns the name of the cipher.
CryptoTransform* createEncryptor();
CryptoTransform * createEncryptor();
/// Creates an encryptor object.
CryptoTransform* createDecryptor();
CryptoTransform * createDecryptor();
/// Creates a decryptor object.
private:
private:
CipherKey _key;
OpenSSLInitializer _openSSLInitializer;
};
};
//
// Inlines
//
inline const std::string& CipherImpl::name() const
{
//
// Inlines
//
inline const std::string & CipherImpl::name() const
{
return _key.name();
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_CipherImpl_INCLUDED

View File

@ -18,15 +18,17 @@
#define Crypto_CipherKey_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/CipherKeyImpl.h"
#include "Poco/Crypto/Crypto.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class Crypto_API CipherKey
class Crypto_API CipherKey
/// CipherKey stores the key information for decryption/encryption of data.
/// To create a random key, using the following code:
///
@ -55,8 +57,8 @@ class Crypto_API CipherKey
/// std::string digest ("sha1");
/// CipherKey key("aes-256", password, salt, 100, digest);
///
{
public:
{
public:
typedef CipherKeyImpl::Mode Mode;
typedef CipherKeyImpl::ByteVec ByteVec;
@ -68,17 +70,16 @@ public:
/// an iteration count of at least 1000.
};
CipherKey(const std::string& name,
const std::string& passphrase,
const std::string& salt = "",
CipherKey(
const std::string & name,
const std::string & passphrase,
const std::string & salt = "",
int iterationCount = DEFAULT_ITERATION_COUNT,
const std::string& digest = "md5");
const std::string & digest = "md5");
/// Creates a new CipherKeyImpl object using the given
/// cipher name, passphrase, salt value, iteration count and digest.
CipherKey(const std::string& name,
const ByteVec& key,
const ByteVec& iv);
CipherKey(const std::string & name, const ByteVec & key, const ByteVec & iv);
/// Creates a new CipherKeyImpl object using the given cipher
/// name, key and initialization vector (IV).
///
@ -86,14 +87,14 @@ public:
/// IV size (see ivSize()), except for GCM mode, which allows
/// a custom IV size.
CipherKey(const std::string& name);
CipherKey(const std::string & name);
/// Creates a new CipherKeyImpl object. Autoinitializes key and
/// initialization vector.
~CipherKey();
/// Destroys the CipherKeyImpl.
const std::string& name() const;
const std::string & name() const;
/// Returns the name of the Cipher.
int keySize() const;
@ -108,16 +109,16 @@ public:
Mode mode() const;
/// Returns the Cipher's mode of operation.
const ByteVec& getKey() const;
const ByteVec & getKey() const;
/// Returns the key for the Cipher.
void setKey(const ByteVec& key);
void setKey(const ByteVec & key);
/// Sets the key for the Cipher.
const ByteVec& getIV() const;
const ByteVec & getIV() const;
/// Returns the initialization vector (IV) for the Cipher.
void setIV(const ByteVec& iv);
void setIV(const ByteVec & iv);
/// Sets the initialization vector (IV) for the Cipher.
///
/// The size of the vector must match the cipher's expected
@ -127,75 +128,76 @@ public:
CipherKeyImpl::Ptr impl();
/// Returns the impl object
private:
private:
CipherKeyImpl::Ptr _pImpl;
};
};
//
// inlines
//
inline const std::string& CipherKey::name() const
{
//
// inlines
//
inline const std::string & CipherKey::name() const
{
return _pImpl->name();
}
}
inline int CipherKey::keySize() const
{
inline int CipherKey::keySize() const
{
return _pImpl->keySize();
}
}
inline int CipherKey::blockSize() const
{
inline int CipherKey::blockSize() const
{
return _pImpl->blockSize();
}
}
inline int CipherKey::ivSize() const
{
inline int CipherKey::ivSize() const
{
return _pImpl->ivSize();
}
}
inline CipherKey::Mode CipherKey::mode() const
{
inline CipherKey::Mode CipherKey::mode() const
{
return _pImpl->mode();
}
}
inline const CipherKey::ByteVec& CipherKey::getKey() const
{
inline const CipherKey::ByteVec & CipherKey::getKey() const
{
return _pImpl->getKey();
}
}
inline void CipherKey::setKey(const CipherKey::ByteVec& key)
{
inline void CipherKey::setKey(const CipherKey::ByteVec & key)
{
_pImpl->setKey(key);
}
}
inline const CipherKey::ByteVec& CipherKey::getIV() const
{
inline const CipherKey::ByteVec & CipherKey::getIV() const
{
return _pImpl->getIV();
}
}
inline void CipherKey::setIV(const CipherKey::ByteVec& iv)
{
inline void CipherKey::setIV(const CipherKey::ByteVec & iv)
{
_pImpl->setIV(iv);
}
}
inline CipherKeyImpl::Ptr CipherKey::impl()
{
inline CipherKeyImpl::Ptr CipherKey::impl()
{
return _pImpl;
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_CipherKey_INCLUDED

View File

@ -18,25 +18,27 @@
#define Crypto_CipherKeyImpl_INCLUDED
#include <vector>
#include "Poco/AutoPtr.h"
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <vector>
struct evp_cipher_st;
typedef struct evp_cipher_st EVP_CIPHER;
namespace Poco {
namespace Crypto {
class CipherKeyImpl: public RefCountedObject
/// An implementation of the CipherKey class for OpenSSL's crypto library.
namespace Poco
{
public:
namespace Crypto
{
class CipherKeyImpl : public RefCountedObject
/// An implementation of the CipherKey class for OpenSSL's crypto library.
{
public:
typedef std::vector<unsigned char> ByteVec;
typedef Poco::AutoPtr<CipherKeyImpl> Ptr;
@ -54,29 +56,28 @@ public:
MODE_CCM /// Counter with CBC-MAC
};
CipherKeyImpl(const std::string& name,
const std::string& passphrase,
const std::string& salt,
CipherKeyImpl(
const std::string & name,
const std::string & passphrase,
const std::string & salt,
int iterationCount,
const std::string& digest);
const std::string & digest);
/// Creates a new CipherKeyImpl object, using
/// the given cipher name, passphrase, salt value
/// and iteration count.
CipherKeyImpl(const std::string& name,
const ByteVec& key,
const ByteVec& iv);
CipherKeyImpl(const std::string & name, const ByteVec & key, const ByteVec & iv);
/// Creates a new CipherKeyImpl object, using the
/// given cipher name, key and initialization vector.
CipherKeyImpl(const std::string& name);
CipherKeyImpl(const std::string & name);
/// Creates a new CipherKeyImpl object. Autoinitializes key
/// and initialization vector.
virtual ~CipherKeyImpl();
/// Destroys the CipherKeyImpl.
const std::string& name() const;
const std::string & name() const;
/// Returns the name of the Cipher.
int keySize() const;
@ -91,78 +92,77 @@ public:
Mode mode() const;
/// Returns the Cipher's mode of operation.
const ByteVec& getKey() const;
const ByteVec & getKey() const;
/// Returns the key for the Cipher.
void setKey(const ByteVec& key);
void setKey(const ByteVec & key);
/// Sets the key for the Cipher.
const ByteVec& getIV() const;
const ByteVec & getIV() const;
/// Returns the initialization vector (IV) for the Cipher.
void setIV(const ByteVec& iv);
void setIV(const ByteVec & iv);
/// Sets the initialization vector (IV) for the Cipher.
const EVP_CIPHER* cipher();
const EVP_CIPHER * cipher();
/// Returns the cipher object
private:
void generateKey(const std::string& passphrase,
const std::string& salt,
int iterationCount);
private:
void generateKey(const std::string & passphrase, const std::string & salt, int iterationCount);
/// Generates key and IV from a password and optional salt string.
void generateKey();
/// Generates key and IV from random data.
void getRandomBytes(ByteVec& vec, std::size_t count);
void getRandomBytes(ByteVec & vec, std::size_t count);
/// Stores random bytes in vec.
private:
const EVP_CIPHER* _pCipher;
const EVP_MD* _pDigest;
private:
const EVP_CIPHER * _pCipher;
const EVP_MD * _pDigest;
std::string _name;
ByteVec _key;
ByteVec _iv;
OpenSSLInitializer _openSSLInitializer;
};
};
//
// Inlines
//
inline const std::string& CipherKeyImpl::name() const
{
//
// Inlines
//
inline const std::string & CipherKeyImpl::name() const
{
return _name;
}
}
inline const CipherKeyImpl::ByteVec& CipherKeyImpl::getKey() const
{
inline const CipherKeyImpl::ByteVec & CipherKeyImpl::getKey() const
{
return _key;
}
}
inline void CipherKeyImpl::setKey(const ByteVec& key)
{
inline void CipherKeyImpl::setKey(const ByteVec & key)
{
poco_assert(key.size() == static_cast<ByteVec::size_type>(keySize()));
_key = key;
}
}
inline const CipherKeyImpl::ByteVec& CipherKeyImpl::getIV() const
{
inline const CipherKeyImpl::ByteVec & CipherKeyImpl::getIV() const
{
return _iv;
}
}
inline const EVP_CIPHER* CipherKeyImpl::cipher()
{
inline const EVP_CIPHER * CipherKeyImpl::cipher()
{
return _pCipher;
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_CipherKeyImpl_INCLUDED

View File

@ -24,23 +24,21 @@
#define POCO_EXTERNAL_OPENSSL_SLPRO 2
#include "Poco/Foundation.h"
#include <openssl/opensslv.h>
#include "Poco/Foundation.h"
#ifndef OPENSSL_VERSION_PREREQ
#if defined(OPENSSL_VERSION_MAJOR) && defined(OPENSSL_VERSION_MINOR)
#define OPENSSL_VERSION_PREREQ(maj, min) \
((OPENSSL_VERSION_MAJOR << 16) + OPENSSL_VERSION_MINOR >= ((maj) << 16) + (min))
#else
#define OPENSSL_VERSION_PREREQ(maj, min) \
(OPENSSL_VERSION_NUMBER >= (((maj) << 28) | ((min) << 20)))
#endif
# if defined(OPENSSL_VERSION_MAJOR) && defined(OPENSSL_VERSION_MINOR)
# define OPENSSL_VERSION_PREREQ(maj, min) ((OPENSSL_VERSION_MAJOR << 16) + OPENSSL_VERSION_MINOR >= ((maj) << 16) + (min))
# else
# define OPENSSL_VERSION_PREREQ(maj, min) (OPENSSL_VERSION_NUMBER >= (((maj) << 28) | ((min) << 20)))
# endif
#endif
enum RSAPaddingMode
/// The padding mode used for RSA public key encryption.
/// The padding mode used for RSA public key encryption.
{
RSA_PADDING_PKCS1,
/// PKCS #1 v1.5 padding. This currently is the most widely used mode.
@ -69,22 +67,22 @@ enum RSAPaddingMode
// defined with this macro as being exported.
//
#if defined(_WIN32)
#if defined(POCO_DLL)
#if defined(Crypto_EXPORTS)
#define Crypto_API __declspec(dllexport)
#else
#define Crypto_API __declspec(dllimport)
#endif
#endif
# if defined(POCO_DLL)
# if defined(Crypto_EXPORTS)
# define Crypto_API __declspec(dllexport)
# else
# define Crypto_API __declspec(dllimport)
# endif
# endif
#endif
#if !defined(Crypto_API)
#if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4)
#define Crypto_API __attribute__ ((visibility ("default")))
#else
#define Crypto_API
#endif
# if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined(__GNUC__) && (__GNUC__ >= 4)
# define Crypto_API __attribute__((visibility("default")))
# else
# define Crypto_API
# endif
#endif
@ -92,83 +90,84 @@ enum RSAPaddingMode
// Automatically link Crypto and OpenSSL libraries.
//
#if defined(_MSC_VER)
#if !defined(POCO_NO_AUTOMATIC_LIBS)
#if defined(POCO_INTERNAL_OPENSSL_MSVC_VER)
#if defined(POCO_EXTERNAL_OPENSSL)
#pragma message("External OpenSSL defined but internal headers used - possible mismatch!")
#endif // POCO_EXTERNAL_OPENSSL
#if !defined(_DEBUG)
#define POCO_DEBUG_SUFFIX ""
#if !defined (_DLL)
#define POCO_STATIC_SUFFIX "mt"
#else // _DLL
#define POCO_STATIC_SUFFIX ""
#endif
#else // _DEBUG
#define POCO_DEBUG_SUFFIX "d"
#if !defined (_DLL)
#define POCO_STATIC_SUFFIX "mt"
#else // _DLL
#define POCO_STATIC_SUFFIX ""
#endif
#endif
#pragma comment(lib, "libcrypto" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
#pragma comment(lib, "libssl" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
#if !defined(_WIN64) && !defined (_DLL) && \
(POCO_INTERNAL_OPENSSL_MSVC_VER == 120) && \
(POCO_MSVC_VERSION < POCO_INTERNAL_OPENSSL_MSVC_VER)
#pragma comment(lib, "libPreVS2013CRT" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
#endif
#if !defined (_DLL) && (POCO_MSVS_VERSION >= 2015)
#pragma comment(lib, "legacy_stdio_definitions.lib")
#pragma comment(lib, "legacy_stdio_wide_specifiers.lib")
#endif
#elif defined(POCO_EXTERNAL_OPENSSL)
#if POCO_EXTERNAL_OPENSSL == POCO_EXTERNAL_OPENSSL_SLPRO
#if defined(POCO_DLL)
#if OPENSSL_VERSION_PREREQ(1,1)
#pragma comment(lib, "libcrypto.lib")
#pragma comment(lib, "libssl.lib")
#else
#pragma comment(lib, "libeay32.lib")
#pragma comment(lib, "ssleay32.lib")
#endif
#else
#if OPENSSL_VERSION_PREREQ(1,1)
#if defined(_WIN64)
#pragma comment(lib, "libcrypto64" POCO_LIB_SUFFIX)
#pragma comment(lib, "libssl64" POCO_LIB_SUFFIX)
#else
#pragma comment(lib, "libcrypto32" POCO_LIB_SUFFIX)
#pragma comment(lib, "libssl32" POCO_LIB_SUFFIX)
#endif
#else
#pragma comment(lib, "libeay32" POCO_LIB_SUFFIX)
#pragma comment(lib, "ssleay32" POCO_LIB_SUFFIX)
#endif
#endif
#elif POCO_EXTERNAL_OPENSSL == POCO_EXTERNAL_OPENSSL_DEFAULT
#if OPENSSL_VERSION_PREREQ(1,1)
#pragma comment(lib, "libcrypto.lib")
#pragma comment(lib, "libssl.lib")
#else
#pragma comment(lib, "libeay32.lib")
#pragma comment(lib, "ssleay32.lib")
#endif
#endif
#endif // POCO_INTERNAL_OPENSSL_MSVC_VER
#if !defined(Crypto_EXPORTS)
#pragma comment(lib, "PocoCrypto" POCO_LIB_SUFFIX)
#endif
#endif // POCO_NO_AUTOMATIC_LIBS
# if !defined(POCO_NO_AUTOMATIC_LIBS)
# if defined(POCO_INTERNAL_OPENSSL_MSVC_VER)
# if defined(POCO_EXTERNAL_OPENSSL)
# pragma message("External OpenSSL defined but internal headers used - possible mismatch!")
# endif // POCO_EXTERNAL_OPENSSL
# if !defined(_DEBUG)
# define POCO_DEBUG_SUFFIX ""
# if !defined(_DLL)
# define POCO_STATIC_SUFFIX "mt"
# else // _DLL
# define POCO_STATIC_SUFFIX ""
# endif
# else // _DEBUG
# define POCO_DEBUG_SUFFIX "d"
# if !defined(_DLL)
# define POCO_STATIC_SUFFIX "mt"
# else // _DLL
# define POCO_STATIC_SUFFIX ""
# endif
# endif
# pragma comment(lib, "libcrypto" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
# pragma comment(lib, "libssl" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
# if !defined(_WIN64) && !defined(_DLL) && (POCO_INTERNAL_OPENSSL_MSVC_VER == 120) \
&& (POCO_MSVC_VERSION < POCO_INTERNAL_OPENSSL_MSVC_VER)
# pragma comment(lib, "libPreVS2013CRT" POCO_STATIC_SUFFIX POCO_DEBUG_SUFFIX ".lib")
# endif
# if !defined(_DLL) && (POCO_MSVS_VERSION >= 2015)
# pragma comment(lib, "legacy_stdio_definitions.lib")
# pragma comment(lib, "legacy_stdio_wide_specifiers.lib")
# endif
# elif defined(POCO_EXTERNAL_OPENSSL)
# if POCO_EXTERNAL_OPENSSL == POCO_EXTERNAL_OPENSSL_SLPRO
# if defined(POCO_DLL)
# if OPENSSL_VERSION_PREREQ(1, 1)
# pragma comment(lib, "libcrypto.lib")
# pragma comment(lib, "libssl.lib")
# else
# pragma comment(lib, "libeay32.lib")
# pragma comment(lib, "ssleay32.lib")
# endif
# else
# if OPENSSL_VERSION_PREREQ(1, 1)
# if defined(_WIN64)
# pragma comment(lib, "libcrypto64" POCO_LIB_SUFFIX)
# pragma comment(lib, "libssl64" POCO_LIB_SUFFIX)
# else
# pragma comment(lib, "libcrypto32" POCO_LIB_SUFFIX)
# pragma comment(lib, "libssl32" POCO_LIB_SUFFIX)
# endif
# else
# pragma comment(lib, "libeay32" POCO_LIB_SUFFIX)
# pragma comment(lib, "ssleay32" POCO_LIB_SUFFIX)
# endif
# endif
# elif POCO_EXTERNAL_OPENSSL == POCO_EXTERNAL_OPENSSL_DEFAULT
# if OPENSSL_VERSION_PREREQ(1, 1)
# pragma comment(lib, "libcrypto.lib")
# pragma comment(lib, "libssl.lib")
# else
# pragma comment(lib, "libeay32.lib")
# pragma comment(lib, "ssleay32.lib")
# endif
# endif
# endif // POCO_INTERNAL_OPENSSL_MSVC_VER
# if !defined(Crypto_EXPORTS)
# pragma comment(lib, "PocoCrypto" POCO_LIB_SUFFIX)
# endif
# endif // POCO_NO_AUTOMATIC_LIBS
#endif
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
void Crypto_API initializeCrypto();
void Crypto_API initializeCrypto();
/// Initialize the Crypto library, as well as the underlying OpenSSL
/// libraries, by calling OpenSSLInitializer::initialize().
///
@ -184,12 +183,13 @@ void Crypto_API initializeCrypto();
/// must be performed.
void Crypto_API uninitializeCrypto();
void Crypto_API uninitializeCrypto();
/// Uninitializes the Crypto library by calling
/// OpenSSLInitializer::uninitialize().
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_Crypto_INCLUDED

View File

@ -23,34 +23,37 @@
#include "Poco/Exception.h"
namespace Poco {
namespace Crypto {
POCO_DECLARE_EXCEPTION(Crypto_API, CryptoException, Poco::Exception)
class Crypto_API OpenSSLException : public CryptoException
namespace Poco
{
public:
namespace Crypto
{
POCO_DECLARE_EXCEPTION(Crypto_API, CryptoException, Poco::Exception)
class Crypto_API OpenSSLException : public CryptoException
{
public:
OpenSSLException(int code = 0);
OpenSSLException(const std::string& msg, int code = 0);
OpenSSLException(const std::string& msg, const std::string& arg, int code = 0);
OpenSSLException(const std::string& msg, const Poco::Exception& exc, int code = 0);
OpenSSLException(const OpenSSLException& exc);
OpenSSLException(const std::string & msg, int code = 0);
OpenSSLException(const std::string & msg, const std::string & arg, int code = 0);
OpenSSLException(const std::string & msg, const Poco::Exception & exc, int code = 0);
OpenSSLException(const OpenSSLException & exc);
~OpenSSLException() throw();
OpenSSLException& operator = (const OpenSSLException& exc);
const char* name() const throw();
const char* className() const throw();
Poco::Exception* clone() const;
OpenSSLException & operator=(const OpenSSLException & exc);
const char * name() const throw();
const char * className() const throw();
Poco::Exception * clone() const;
void rethrow() const;
private:
private:
void setExtMessage();
};
};
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_CryptoException_INCLUDED

View File

@ -19,89 +19,91 @@
#define Crypto_CryptoStream_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/BufferedStreamBuf.h"
#include "Poco/Buffer.h"
#include <iostream>
#include "Poco/Buffer.h"
#include "Poco/BufferedStreamBuf.h"
#include "Poco/Crypto/Crypto.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class CryptoTransform;
class Cipher;
class CryptoTransform;
class Cipher;
class Crypto_API CryptoStreamBuf: public Poco::BufferedStreamBuf
class Crypto_API CryptoStreamBuf : public Poco::BufferedStreamBuf
/// This stream buffer performs cryptographic transformation on the data
/// going through it.
{
public:
CryptoStreamBuf(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
CryptoStreamBuf(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
{
public:
CryptoStreamBuf(std::istream & istr, CryptoTransform * pTransform, std::streamsize bufferSize = 8192);
CryptoStreamBuf(std::ostream & ostr, CryptoTransform * pTransform, std::streamsize bufferSize = 8192);
virtual ~CryptoStreamBuf();
void close();
/// Flushes all buffers and finishes the encryption.
protected:
int readFromDevice(char* buffer, std::streamsize length);
int writeToDevice(const char* buffer, std::streamsize length);
protected:
int readFromDevice(char * buffer, std::streamsize length);
int writeToDevice(const char * buffer, std::streamsize length);
private:
CryptoTransform* _pTransform;
std::istream* _pIstr;
std::ostream* _pOstr;
private:
CryptoTransform * _pTransform;
std::istream * _pIstr;
std::ostream * _pOstr;
bool _eof;
Poco::Buffer<unsigned char> _buffer;
CryptoStreamBuf(const CryptoStreamBuf&);
CryptoStreamBuf& operator = (const CryptoStreamBuf&);
};
CryptoStreamBuf(const CryptoStreamBuf &);
CryptoStreamBuf & operator=(const CryptoStreamBuf &);
};
class Crypto_API CryptoIOS: public virtual std::ios
class Crypto_API CryptoIOS : public virtual std::ios
/// The base class for CryptoInputStream and CryptoOutputStream.
///
/// This class is needed to ensure correct initialization order of the
/// stream buffer and base classes.
{
public:
CryptoIOS(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
CryptoIOS(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
{
public:
CryptoIOS(std::istream & istr, CryptoTransform * pTransform, std::streamsize bufferSize = 8192);
CryptoIOS(std::ostream & ostr, CryptoTransform * pTransform, std::streamsize bufferSize = 8192);
~CryptoIOS();
CryptoStreamBuf* rdbuf();
CryptoStreamBuf * rdbuf();
protected:
protected:
CryptoStreamBuf _buf;
};
};
class Crypto_API CryptoInputStream: public CryptoIOS, public std::istream
class Crypto_API CryptoInputStream : public CryptoIOS, public std::istream
/// This stream transforms all data passing through it using the given
/// CryptoTransform.
///
/// Use a CryptoTransform object provided by Cipher::createEncrytor() or
/// Cipher::createDecryptor() to create an encrypting or decrypting stream,
/// respectively.
{
public:
CryptoInputStream(std::istream& istr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
{
public:
CryptoInputStream(std::istream & istr, CryptoTransform * pTransform, std::streamsize bufferSize = 8192);
/// Create a new CryptoInputStream object. The CryptoInputStream takes the
/// ownership of the given CryptoTransform object.
CryptoInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192);
CryptoInputStream(std::istream & istr, Cipher & cipher, std::streamsize bufferSize = 8192);
/// Create a new encrypting CryptoInputStream object using the given cipher.
~CryptoInputStream();
/// Destroys the CryptoInputStream.
};
};
class Crypto_API CryptoOutputStream: public CryptoIOS, public std::ostream
class Crypto_API CryptoOutputStream : public CryptoIOS, public std::ostream
/// This stream transforms all data passing through it using the given
/// CryptoTransform.
///
@ -111,13 +113,13 @@ class Crypto_API CryptoOutputStream: public CryptoIOS, public std::ostream
///
/// After all data has been passed through the stream, close() must be called
/// to ensure completion of cryptographic transformation.
{
public:
CryptoOutputStream(std::ostream& ostr, CryptoTransform* pTransform, std::streamsize bufferSize = 8192);
{
public:
CryptoOutputStream(std::ostream & ostr, CryptoTransform * pTransform, std::streamsize bufferSize = 8192);
/// Create a new CryptoOutputStream object. The CryptoOutputStream takes the
/// ownership of the given CryptoTransform object.
CryptoOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192);
CryptoOutputStream(std::ostream & ostr, Cipher & cipher, std::streamsize bufferSize = 8192);
/// Create a new decrypting CryptoOutputStream object using the given cipher.
~CryptoOutputStream();
@ -125,28 +127,28 @@ public:
void close();
/// Flushes all buffers and finishes the encryption.
};
};
class Crypto_API DecryptingInputStream: public CryptoIOS, public std::istream
class Crypto_API DecryptingInputStream : public CryptoIOS, public std::istream
/// This stream decrypts all data passing through it using the given
/// Cipher.
{
public:
DecryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192);
{
public:
DecryptingInputStream(std::istream & istr, Cipher & cipher, std::streamsize bufferSize = 8192);
/// Create a new DecryptingInputStream object using the given cipher.
~DecryptingInputStream();
/// Destroys the DecryptingInputStream.
};
};
class Crypto_API DecryptingOutputStream: public CryptoIOS, public std::ostream
class Crypto_API DecryptingOutputStream : public CryptoIOS, public std::ostream
/// This stream decrypts all data passing through it using the given
/// Cipher.
{
public:
DecryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192);
{
public:
DecryptingOutputStream(std::ostream & ostr, Cipher & cipher, std::streamsize bufferSize = 8192);
/// Create a new DecryptingOutputStream object using the given cipher.
~DecryptingOutputStream();
@ -154,28 +156,28 @@ public:
void close();
/// Flushes all buffers and finishes the decryption.
};
};
class Crypto_API EncryptingInputStream: public CryptoIOS, public std::istream
class Crypto_API EncryptingInputStream : public CryptoIOS, public std::istream
/// This stream encrypts all data passing through it using the given
/// Cipher.
{
public:
EncryptingInputStream(std::istream& istr, Cipher& cipher, std::streamsize bufferSize = 8192);
{
public:
EncryptingInputStream(std::istream & istr, Cipher & cipher, std::streamsize bufferSize = 8192);
/// Create a new EncryptingInputStream object using the given cipher.
~EncryptingInputStream();
/// Destroys the EncryptingInputStream.
};
};
class Crypto_API EncryptingOutputStream: public CryptoIOS, public std::ostream
class Crypto_API EncryptingOutputStream : public CryptoIOS, public std::ostream
/// This stream encrypts all data passing through it using the given
/// Cipher.
{
public:
EncryptingOutputStream(std::ostream& ostr, Cipher& cipher, std::streamsize bufferSize = 8192);
{
public:
EncryptingOutputStream(std::ostream & ostr, Cipher & cipher, std::streamsize bufferSize = 8192);
/// Create a new EncryptingOutputStream object using the given cipher.
~EncryptingOutputStream();
@ -183,10 +185,11 @@ public:
void close();
/// Flushes all buffers and finishes the encryption.
};
};
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_CryptoStream_INCLUDED

View File

@ -18,23 +18,25 @@
#define Crypto_CryptoTransform_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include <ios>
#include "Poco/Crypto/Crypto.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class Crypto_API CryptoTransform
class Crypto_API CryptoTransform
/// This interface represents the basic operations for cryptographic
/// transformations to be used with a CryptoInputStream or a
/// CryptoOutputStream.
///
/// Implementations of this class are returned by the Cipher class to
/// perform encryption or decryption of data.
{
public:
{
public:
CryptoTransform();
/// Creates a new CryptoTransform object.
@ -55,33 +57,32 @@ public:
///
/// Must be called after finalize().
virtual void setTag(const std::string& tag) = 0;
virtual void setTag(const std::string & tag) = 0;
/// Sets the GCM tag for authenticated decryption using GCM mode.
///
/// Must be set before finalize() is called, otherwise
/// decryption will fail.
virtual std::streamsize transform(
const unsigned char* input,
std::streamsize inputLength,
unsigned char* output,
std::streamsize outputLength) = 0;
virtual std::streamsize
transform(const unsigned char * input, std::streamsize inputLength, unsigned char * output, std::streamsize outputLength)
= 0;
/// Transforms a chunk of data. The inputLength is arbitrary and does not
/// need to be a multiple of the block size. The output buffer has a maximum
/// capacity of the given outputLength that must be at least
/// inputLength + blockSize() - 1
/// Returns the number of bytes written to the output buffer.
virtual std::streamsize finalize(unsigned char* output, std::streamsize length) = 0;
virtual std::streamsize finalize(unsigned char * output, std::streamsize length) = 0;
/// Finalizes the transformation. The output buffer must contain enough
/// space for at least two blocks, ie.
/// length >= 2*blockSize()
/// must be true. Returns the number of bytes written to the output
/// buffer.
};
};
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_CryptoTransform_INCLUDED

View File

@ -18,22 +18,24 @@
#define Crypto_DigestEngine_INCLUDED
#include <openssl/evp.h>
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/DigestEngine.h"
#include <openssl/evp.h>
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class Crypto_API DigestEngine: public Poco::DigestEngine
class Crypto_API DigestEngine : public Poco::DigestEngine
/// This class implements a Poco::DigestEngine for all
/// digest algorithms supported by OpenSSL.
{
public:
DigestEngine(const std::string& name);
{
public:
DigestEngine(const std::string & name);
/// Creates a DigestEngine using the digest with the given name
/// (e.g., "MD5", "SHA1", "SHA256", "SHA512", etc.).
/// See the OpenSSL documentation for a list of supported digest algorithms.
@ -43,7 +45,7 @@ public:
~DigestEngine();
/// Destroys the DigestEngine.
const std::string& algorithm() const;
const std::string & algorithm() const;
/// Returns the name of the digest algorithm.
int nid() const;
@ -52,29 +54,30 @@ public:
// DigestEngine
std::size_t digestLength() const;
void reset();
const Poco::DigestEngine::Digest& digest();
const Poco::DigestEngine::Digest & digest();
protected:
void updateImpl(const void* data, std::size_t length);
protected:
void updateImpl(const void * data, std::size_t length);
private:
private:
std::string _name;
EVP_MD_CTX* _pContext;
EVP_MD_CTX * _pContext;
Poco::DigestEngine::Digest _digest;
OpenSSLInitializer _openSSLInitializer;
};
};
//
// inlines
//
inline const std::string& DigestEngine::algorithm() const
{
//
// inlines
//
inline const std::string & DigestEngine::algorithm() const
{
return _name;
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_DigestEngine_INCLUDED

View File

@ -19,19 +19,21 @@
#define Crypto_ECDSADigestEngine_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/ECKey.h"
#include "Poco/DigestEngine.h"
#include "Poco/Crypto/DigestEngine.h"
#include <istream>
#include <ostream>
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/DigestEngine.h"
#include "Poco/Crypto/ECKey.h"
#include "Poco/DigestEngine.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class Crypto_API ECDSADigestEngine: public Poco::DigestEngine
class Crypto_API ECDSADigestEngine : public Poco::DigestEngine
/// This class implements a Poco::DigestEngine that can be
/// used to compute a secure digital signature.
///
@ -44,10 +46,9 @@ class Crypto_API ECDSADigestEngine: public Poco::DigestEngine
/// member function. It will decrypt the signature
/// using the ECDSA public key and compare the resulting
/// hash with the actual hash of the data.
{
public:
ECDSADigestEngine(const ECKey& key, const std::string &name);
{
public:
ECDSADigestEngine(const ECKey & key, const std::string & name);
/// Creates the ECDSADigestEngine with the given ECDSA key,
/// using the hash algorithm with the given name
/// (e.g., "SHA1", "SHA256", "SHA512", etc.).
@ -65,37 +66,38 @@ public:
/// Resets the engine so that a new
/// digest can be computed.
const DigestEngine::Digest& digest();
const DigestEngine::Digest & digest();
/// Finishes the computation of the digest
/// (the first time it's called) and
/// returns the message digest.
///
/// Can be called multiple times.
const DigestEngine::Digest& signature();
const DigestEngine::Digest & signature();
/// Signs the digest using the ECDSADSA algorithm
/// and the private key (the first time it's
/// called) and returns the result.
///
/// Can be called multiple times.
bool verify(const DigestEngine::Digest& signature);
bool verify(const DigestEngine::Digest & signature);
/// Verifies the data against the signature.
///
/// Returns true if the signature can be verified, false otherwise.
protected:
void updateImpl(const void* data, std::size_t length);
protected:
void updateImpl(const void * data, std::size_t length);
private:
private:
ECKey _key;
Poco::Crypto::DigestEngine _engine;
Poco::DigestEngine::Digest _digest;
Poco::DigestEngine::Digest _signature;
};
};
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_ECDSADigestEngine_INCLUDED

View File

@ -20,18 +20,20 @@
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/KeyPair.h"
#include "Poco/Crypto/ECKeyImpl.h"
#include "Poco/Crypto/KeyPair.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class X509Certificate;
class PKCS12Container;
class X509Certificate;
class PKCS12Container;
class Crypto_API ECKey : public KeyPair
class Crypto_API ECKey : public KeyPair
/// This class stores an EC key pair, consisting
/// of private and public key. Storage of the private
/// key is optional.
@ -39,22 +41,22 @@ class Crypto_API ECKey : public KeyPair
/// If a private key is available, the ECKey can be
/// used for decrypting data (encrypted with the public key)
/// or computing secure digital signatures.
{
public:
ECKey(const EVPPKey& key);
{
public:
ECKey(const EVPPKey & key);
/// Constructs ECKeyImpl by extracting the EC key.
ECKey(const X509Certificate& cert);
ECKey(const X509Certificate & cert);
/// Extracts the EC public key from the given certificate.
ECKey(const PKCS12Container& cert);
ECKey(const PKCS12Container & cert);
/// Extracts the EC private key from the given certificate.
ECKey(const std::string& eccGroup);
ECKey(const std::string & eccGroup);
/// Creates the ECKey. Creates a new public/private key pair using the given parameters.
/// Can be used to sign data and verify signatures.
ECKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase = "");
ECKey(const std::string & publicKeyFile, const std::string & privateKeyFile, const std::string & privateKeyPassphrase = "");
/// Creates the ECKey, by reading public and private key from the given files and
/// using the given passphrase for the private key.
///
@ -63,7 +65,7 @@ public:
/// If a private key is specified, you don't need to specify a public key file.
/// OpenSSL will auto-create the public key from the private key.
ECKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "");
ECKey(std::istream * pPublicKeyStream, std::istream * pPrivateKeyStream = 0, const std::string & privateKeyPassphrase = "");
/// Creates the ECKey, by reading public and private key from the given streams and
/// using the given passphrase for the private key.
///
@ -87,49 +89,50 @@ public:
///
/// If no curves are found, returns empty string;
static int getCurveNID(std::string& name);
static int getCurveNID(std::string & name);
/// Returns the NID of the specified curve.
///
/// If name is empty, returns the first curve NID
/// and updates the name accordingly.
static bool hasCurve(const std::string& name);
static bool hasCurve(const std::string & name);
/// Returns true if the named curve is found,
/// false otherwise.
private:
private:
ECKeyImpl::Ptr _pImpl;
};
};
//
// inlines
//
inline ECKeyImpl::Ptr ECKey::impl() const
{
//
// inlines
//
inline ECKeyImpl::Ptr ECKey::impl() const
{
return _pImpl;
}
}
inline std::string ECKey::getCurveName(int nid)
{
inline std::string ECKey::getCurveName(int nid)
{
return ECKeyImpl::getCurveName(nid);
}
}
inline int ECKey::getCurveNID(std::string& name)
{
inline int ECKey::getCurveNID(std::string & name)
{
return ECKeyImpl::getCurveNID(name);
}
}
inline bool ECKey::hasCurve(const std::string& name)
{
inline bool ECKey::hasCurve(const std::string & name)
{
return ECKeyImpl::hasCurve(name);
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_ECKey_INCLUDED

View File

@ -19,53 +19,55 @@
#define Crypto_ECKeyImplImpl_INCLUDED
#include <istream>
#include <ostream>
#include <vector>
#include <openssl/ec.h>
#include <openssl/objects.h>
#include "Poco/AutoPtr.h"
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/EVPPKey.h"
#include "Poco/Crypto/KeyPairImpl.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <istream>
#include <ostream>
#include <vector>
#include <openssl/objects.h>
#include <openssl/ec.h>
namespace Poco {
namespace Crypto {
class X509Certificate;
class PKCS12Container;
class ECKeyImpl: public KeyPairImpl
/// Elliptic Curve key clas implementation.
namespace Poco
{
public:
namespace Crypto
{
class X509Certificate;
class PKCS12Container;
class ECKeyImpl : public KeyPairImpl
/// Elliptic Curve key clas implementation.
{
public:
typedef Poco::AutoPtr<ECKeyImpl> Ptr;
typedef std::vector<unsigned char> ByteVec;
ECKeyImpl(const EVPPKey& key);
ECKeyImpl(const EVPPKey & key);
/// Constructs ECKeyImpl by extracting the EC key.
ECKeyImpl(const X509Certificate& cert);
ECKeyImpl(const X509Certificate & cert);
/// Constructs ECKeyImpl by extracting the EC public key from the given certificate.
ECKeyImpl(const PKCS12Container& cert);
ECKeyImpl(const PKCS12Container & cert);
/// Constructs ECKeyImpl by extracting the EC private key from the given certificate.
ECKeyImpl(int eccGroup);
/// Creates the ECKey of the specified group. Creates a new public/private keypair using the given parameters.
/// Can be used to sign data and verify signatures.
ECKeyImpl(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase);
ECKeyImpl(const std::string & publicKeyFile, const std::string & privateKeyFile, const std::string & privateKeyPassphrase);
/// Creates the ECKey, by reading public and private key from the given files and
/// using the given passphrase for the private key. Can only by used for signing if
/// a private key is available.
ECKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase);
ECKeyImpl(std::istream * pPublicKeyStream, std::istream * pPrivateKeyStream, const std::string & privateKeyPassphrase);
/// Creates the ECKey. Can only by used for signing if pPrivKey
/// is not null. If a private key file is specified, you don't need to
/// specify a public key file. OpenSSL will auto-create it from the private key.
@ -73,10 +75,10 @@ public:
~ECKeyImpl();
/// Destroys the ECKeyImpl.
EC_KEY* getECKey();
EC_KEY * getECKey();
/// Returns the OpenSSL EC key.
const EC_KEY* getECKey() const;
const EC_KEY * getECKey() const;
/// Returns the OpenSSL EC key.
int size() const;
@ -88,17 +90,15 @@ public:
std::string groupName() const;
/// Returns the EC key group name.
void save(const std::string& publicKeyFile,
const std::string& privateKeyFile = "",
const std::string& privateKeyPassphrase = "") const;
void save(const std::string & publicKeyFile, const std::string & privateKeyFile = "", const std::string & privateKeyPassphrase = "")
const;
/// Exports the public and private keys to the given files.
///
/// If an empty filename is specified, the corresponding key
/// is not exported.
void save(std::ostream* pPublicKeyStream,
std::ostream* pPrivateKeyStream = 0,
const std::string& privateKeyPassphrase = "") const;
void
save(std::ostream * pPublicKeyStream, std::ostream * pPrivateKeyStream = 0, const std::string & privateKeyPassphrase = "") const;
/// Exports the public and private key to the given streams.
///
/// If a null pointer is passed for a stream, the corresponding
@ -113,62 +113,61 @@ public:
///
/// If no curves are found, returns empty string;
static int getCurveNID(std::string& name);
static int getCurveNID(std::string & name);
/// Returns the NID of the specified curve.
///
/// If name is empty, returns the first curve NID
/// and updates the name accordingly.
static bool hasCurve(const std::string& name);
static bool hasCurve(const std::string & name);
/// Returns true if the named curve is found,
/// false otherwise.
private:
void checkEC(const std::string& method, const std::string& func) const;
private:
void checkEC(const std::string & method, const std::string & func) const;
void freeEC();
EC_KEY* _pEC;
};
EC_KEY * _pEC;
};
//
// inlines
//
inline EC_KEY* ECKeyImpl::getECKey()
{
//
// inlines
//
inline EC_KEY * ECKeyImpl::getECKey()
{
return _pEC;
}
}
inline const EC_KEY* ECKeyImpl::getECKey() const
{
inline const EC_KEY * ECKeyImpl::getECKey() const
{
return _pEC;
}
}
inline std::string ECKeyImpl::groupName() const
{
inline std::string ECKeyImpl::groupName() const
{
return OBJ_nid2sn(groupId());
}
}
inline void ECKeyImpl::save(const std::string& publicKeyFile,
const std::string& privateKeyFile,
const std::string& privateKeyPassphrase) const
{
inline void
ECKeyImpl::save(const std::string & publicKeyFile, const std::string & privateKeyFile, const std::string & privateKeyPassphrase) const
{
EVPPKey(_pEC).save(publicKeyFile, privateKeyFile, privateKeyPassphrase);
}
}
inline void ECKeyImpl::save(std::ostream* pPublicKeyStream,
std::ostream* pPrivateKeyStream,
const std::string& privateKeyPassphrase) const
{
inline void
ECKeyImpl::save(std::ostream * pPublicKeyStream, std::ostream * pPrivateKeyStream, const std::string & privateKeyPassphrase) const
{
EVPPKey(_pEC).save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase);
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_ECKeyImplImpl_INCLUDED

View File

@ -19,77 +19,80 @@
#define Crypto_EVPPKeyImpl_INCLUDED
#include <sstream>
#include <typeinfo>
#include <openssl/ec.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/CryptoException.h"
#include "Poco/StreamCopier.h"
#include <openssl/ec.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <openssl/pem.h>
#include <sstream>
#include <typeinfo>
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class ECKey;
class RSAKey;
class ECKey;
class RSAKey;
class Crypto_API EVPPKey
class Crypto_API EVPPKey
/// Utility class for conversion of native keys to EVP.
/// Currently, only RSA and EC keys are supported.
{
public:
explicit EVPPKey(const std::string& ecCurveName);
{
public:
explicit EVPPKey(const std::string & ecCurveName);
/// Constructs EVPPKey from ECC curve name.
///
/// Only EC keys can be wrapped by an EVPPKey
/// created using this constructor.
explicit EVPPKey(const char* ecCurveName);
explicit EVPPKey(const char * ecCurveName);
/// Constructs EVPPKey from ECC curve name.
///
/// Only EC keys can be wrapped by an EVPPKey
/// created using this constructor.
explicit EVPPKey(EVP_PKEY* pEVPPKey);
explicit EVPPKey(EVP_PKEY * pEVPPKey);
/// Constructs EVPPKey from EVP_PKEY pointer.
/// The content behind the supplied pointer is internally duplicated.
template<typename K>
explicit EVPPKey(K* pKey): _pEVPPKey(EVP_PKEY_new())
template <typename K>
explicit EVPPKey(K * pKey) : _pEVPPKey(EVP_PKEY_new())
/// Constructs EVPPKey from a "native" OpenSSL (RSA or EC_KEY),
/// or a Poco wrapper (RSAKey, ECKey) key pointer.
{
if (!_pEVPPKey) throw OpenSSLException();
if (!_pEVPPKey)
throw OpenSSLException();
setKey(pKey);
}
EVPPKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase = "");
EVPPKey(const std::string & publicKeyFile, const std::string & privateKeyFile, const std::string & privateKeyPassphrase = "");
/// Creates the EVPPKey, by reading public and private key from the given files and
/// using the given passphrase for the private key. Can only by used for signing if
/// a private key is available.
EVPPKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase = "");
EVPPKey(std::istream * pPublicKeyStream, std::istream * pPrivateKeyStream, const std::string & privateKeyPassphrase = "");
/// Creates the EVPPKey. Can only by used for signing if pPrivKey
/// is not null. If a private key file is specified, you don't need to
/// specify a public key file. OpenSSL will auto-create it from the private key.
EVPPKey(const EVPPKey& other);
EVPPKey(const EVPPKey & other);
/// Copy constructor.
EVPPKey& operator=(const EVPPKey& other);
EVPPKey & operator=(const EVPPKey & other);
/// Assignment operator.
#ifdef POCO_ENABLE_CPP11
EVPPKey(EVPPKey&& other);
EVPPKey(EVPPKey && other);
/// Move constructor.
EVPPKey& operator=(EVPPKey&& other);
EVPPKey & operator=(EVPPKey && other);
/// Assignment move operator.
#endif // POCO_ENABLE_CPP11
@ -97,7 +100,7 @@ public:
~EVPPKey();
/// Destroys the EVPPKey.
bool operator == (const EVPPKey& other) const;
bool operator==(const EVPPKey & other) const;
/// Comparison operator.
/// Returns true if public key components and parameters
/// of the other key are equal to this key.
@ -105,7 +108,7 @@ public:
/// Works as expected when one key contains only public key,
/// while the other one contains private (thus also public) key.
bool operator != (const EVPPKey& other) const;
bool operator!=(const EVPPKey & other) const;
/// Comparison operator.
/// Returns true if public key components and parameters
/// of the other key are different from this key.
@ -113,13 +116,15 @@ public:
/// Works as expected when one key contains only public key,
/// while the other one contains private (thus also public) key.
void save(const std::string& publicKeyFile, const std::string& privateKeyFile = "", const std::string& privateKeyPassphrase = "") const;
void save(const std::string & publicKeyFile, const std::string & privateKeyFile = "", const std::string & privateKeyPassphrase = "")
const;
/// Exports the public and/or private keys to the given files.
///
/// If an empty filename is specified, the corresponding key
/// is not exported.
void save(std::ostream* pPublicKeyStream, std::ostream* pPrivateKeyStream = 0, const std::string& privateKeyPassphrase = "") const;
void
save(std::ostream * pPublicKeyStream, std::ostream * pPrivateKeyStream = 0, const std::string & privateKeyPassphrase = "") const;
/// Exports the public and/or private key to the given streams.
///
/// If a null pointer is passed for a stream, the corresponding
@ -131,224 +136,234 @@ public:
bool isSupported(int type) const;
/// Returns true if OpenSSL type is supported
operator const EVP_PKEY*() const;
operator const EVP_PKEY *() const;
/// Returns const pointer to the OpenSSL EVP_PKEY structure.
operator EVP_PKEY*();
operator EVP_PKEY *();
/// Returns pointer to the OpenSSL EVP_PKEY structure.
static EVP_PKEY* duplicate(const EVP_PKEY* pFromKey, EVP_PKEY** pToKey);
static EVP_PKEY * duplicate(const EVP_PKEY * pFromKey, EVP_PKEY ** pToKey);
/// Duplicates pFromKey into *pToKey and returns
// the pointer to duplicated EVP_PKEY.
private:
private:
EVPPKey();
static int type(const EVP_PKEY* pEVPPKey);
void newECKey(const char* group);
void duplicate(EVP_PKEY* pEVPPKey);
static int type(const EVP_PKEY * pEVPPKey);
void newECKey(const char * group);
void duplicate(EVP_PKEY * pEVPPKey);
void setKey(ECKey* pKey);
void setKey(RSAKey* pKey);
void setKey(EC_KEY* pKey);
void setKey(RSA* pKey);
static int passCB(char* buf, int size, int, void* pass);
void setKey(ECKey * pKey);
void setKey(RSAKey * pKey);
void setKey(EC_KEY * pKey);
void setKey(RSA * pKey);
static int passCB(char * buf, int size, int, void * pass);
typedef EVP_PKEY* (*PEM_read_FILE_Key_fn)(FILE*, EVP_PKEY**, pem_password_cb*, void*);
typedef EVP_PKEY* (*PEM_read_BIO_Key_fn)(BIO*, EVP_PKEY**, pem_password_cb*, void*);
typedef void* (*EVP_PKEY_get_Key_fn)(EVP_PKEY*);
typedef EVP_PKEY * (*PEM_read_FILE_Key_fn)(FILE *, EVP_PKEY **, pem_password_cb *, void *);
typedef EVP_PKEY * (*PEM_read_BIO_Key_fn)(BIO *, EVP_PKEY **, pem_password_cb *, void *);
typedef void * (*EVP_PKEY_get_Key_fn)(EVP_PKEY *);
// The following load*() functions are used by both native and EVP_PKEY type key
// loading from BIO/FILE.
// When used for EVP key loading, getFunc is null (ie. native key is not extracted
// from the loaded EVP_PKEY).
template <typename K, typename F>
static bool loadKey(K** ppKey,
PEM_read_FILE_Key_fn readFunc,
F getFunc,
const std::string& keyFile,
const std::string& pass = "")
static bool
loadKey(K ** ppKey, PEM_read_FILE_Key_fn readFunc, F getFunc, const std::string & keyFile, const std::string & pass = "")
{
poco_assert_dbg (((typeid(K*) == typeid(RSA*) || typeid(K*) == typeid(EC_KEY*)) && getFunc) ||
((typeid(K*) == typeid(EVP_PKEY*)) && !getFunc));
poco_check_ptr (ppKey);
poco_assert_dbg (!*ppKey);
poco_assert_dbg(
((typeid(K *) == typeid(RSA *) || typeid(K *) == typeid(EC_KEY *)) && getFunc)
|| ((typeid(K *) == typeid(EVP_PKEY *)) && !getFunc));
poco_check_ptr(ppKey);
poco_assert_dbg(!*ppKey);
FILE* pFile = 0;
FILE * pFile = 0;
if (!keyFile.empty())
{
if (!getFunc) *ppKey = (K*)EVP_PKEY_new();
EVP_PKEY* pKey = getFunc ? EVP_PKEY_new() : (EVP_PKEY*)*ppKey;
if (!getFunc)
*ppKey = (K *)EVP_PKEY_new();
EVP_PKEY * pKey = getFunc ? EVP_PKEY_new() : (EVP_PKEY *)*ppKey;
if (pKey)
{
pFile = fopen(keyFile.c_str(), "r");
if (pFile)
{
pem_password_cb* pCB = pass.empty() ? (pem_password_cb*)0 : &passCB;
void* pPassword = pass.empty() ? (void*)0 : (void*)pass.c_str();
pem_password_cb * pCB = pass.empty() ? (pem_password_cb *)0 : &passCB;
void * pPassword = pass.empty() ? (void *)0 : (void *)pass.c_str();
if (readFunc(pFile, &pKey, pCB, pPassword))
{
fclose(pFile); pFile = 0;
if(getFunc)
fclose(pFile);
pFile = 0;
if (getFunc)
{
*ppKey = (K*)getFunc(pKey);
*ppKey = (K *)getFunc(pKey);
EVP_PKEY_free(pKey);
}
else
{
poco_assert_dbg (typeid(K*) == typeid(EVP_PKEY*));
*ppKey = (K*)pKey;
poco_assert_dbg(typeid(K *) == typeid(EVP_PKEY *));
*ppKey = (K *)pKey;
}
if(!*ppKey) goto error;
if (!*ppKey)
goto error;
return true;
}
goto error;
}
else
{
if (getFunc) EVP_PKEY_free(pKey);
if (getFunc)
EVP_PKEY_free(pKey);
throw IOException("ECKeyImpl, cannot open file", keyFile);
}
}
else goto error;
else
goto error;
}
return false;
error:
if (pFile) fclose(pFile);
if (pFile)
fclose(pFile);
throw OpenSSLException("EVPKey::loadKey(string)");
}
template <typename K, typename F>
static bool loadKey(K** ppKey,
PEM_read_BIO_Key_fn readFunc,
F getFunc,
std::istream* pIstr,
const std::string& pass = "")
static bool loadKey(K ** ppKey, PEM_read_BIO_Key_fn readFunc, F getFunc, std::istream * pIstr, const std::string & pass = "")
{
poco_assert_dbg (((typeid(K*) == typeid(RSA*) || typeid(K*) == typeid(EC_KEY*)) && getFunc) ||
((typeid(K*) == typeid(EVP_PKEY*)) && !getFunc));
poco_assert_dbg(
((typeid(K *) == typeid(RSA *) || typeid(K *) == typeid(EC_KEY *)) && getFunc)
|| ((typeid(K *) == typeid(EVP_PKEY *)) && !getFunc));
poco_check_ptr(ppKey);
poco_assert_dbg(!*ppKey);
BIO* pBIO = 0;
BIO * pBIO = 0;
if (pIstr)
{
std::ostringstream ostr;
Poco::StreamCopier::copyStream(*pIstr, ostr);
std::string key = ostr.str();
pBIO = BIO_new_mem_buf(const_cast<char*>(key.data()), static_cast<int>(key.size()));
pBIO = BIO_new_mem_buf(const_cast<char *>(key.data()), static_cast<int>(key.size()));
if (pBIO)
{
if (!getFunc) *ppKey = (K*)EVP_PKEY_new();
EVP_PKEY* pKey = getFunc ? EVP_PKEY_new() : (EVP_PKEY*)*ppKey;
if (!getFunc)
*ppKey = (K *)EVP_PKEY_new();
EVP_PKEY * pKey = getFunc ? EVP_PKEY_new() : (EVP_PKEY *)*ppKey;
if (pKey)
{
pem_password_cb* pCB = pass.empty() ? (pem_password_cb*)0 : &passCB;
void* pPassword = pass.empty() ? (void*)0 : (void*)pass.c_str();
pem_password_cb * pCB = pass.empty() ? (pem_password_cb *)0 : &passCB;
void * pPassword = pass.empty() ? (void *)0 : (void *)pass.c_str();
if (readFunc(pBIO, &pKey, pCB, pPassword))
{
BIO_free(pBIO); pBIO = 0;
BIO_free(pBIO);
pBIO = 0;
if (getFunc)
{
*ppKey = (K*)getFunc(pKey);
*ppKey = (K *)getFunc(pKey);
EVP_PKEY_free(pKey);
}
else
{
poco_assert_dbg (typeid(K*) == typeid(EVP_PKEY*));
*ppKey = (K*)pKey;
poco_assert_dbg(typeid(K *) == typeid(EVP_PKEY *));
*ppKey = (K *)pKey;
}
if (!*ppKey) goto error;
if (!*ppKey)
goto error;
return true;
}
if (getFunc) EVP_PKEY_free(pKey);
if (getFunc)
EVP_PKEY_free(pKey);
goto error;
}
else goto error;
else
goto error;
}
else goto error;
else
goto error;
}
return false;
error:
if (pBIO) BIO_free(pBIO);
if (pBIO)
BIO_free(pBIO);
throw OpenSSLException("EVPKey::loadKey(stream)");
}
EVP_PKEY* _pEVPPKey;
EVP_PKEY * _pEVPPKey;
friend class ECKeyImpl;
friend class RSAKeyImpl;
};
};
//
// inlines
//
//
// inlines
//
inline bool EVPPKey::operator == (const EVPPKey& other) const
{
poco_check_ptr (other._pEVPPKey);
poco_check_ptr (_pEVPPKey);
inline bool EVPPKey::operator==(const EVPPKey & other) const
{
poco_check_ptr(other._pEVPPKey);
poco_check_ptr(_pEVPPKey);
return (1 == EVP_PKEY_cmp(_pEVPPKey, other._pEVPPKey));
}
}
inline bool EVPPKey::operator != (const EVPPKey& other) const
{
inline bool EVPPKey::operator!=(const EVPPKey & other) const
{
return !(other == *this);
}
}
inline int EVPPKey::type(const EVP_PKEY* pEVPPKey)
{
if (!pEVPPKey) return NID_undef;
inline int EVPPKey::type(const EVP_PKEY * pEVPPKey)
{
if (!pEVPPKey)
return NID_undef;
return EVP_PKEY_type(EVP_PKEY_id(pEVPPKey));
}
}
inline int EVPPKey::type() const
{
inline int EVPPKey::type() const
{
return type(_pEVPPKey);
}
}
inline bool EVPPKey::isSupported(int type) const
{
inline bool EVPPKey::isSupported(int type) const
{
return type == EVP_PKEY_EC || type == EVP_PKEY_RSA;
}
}
inline EVPPKey::operator const EVP_PKEY*() const
{
inline EVPPKey::operator const EVP_PKEY *() const
{
return _pEVPPKey;
}
}
inline EVPPKey::operator EVP_PKEY*()
{
inline EVPPKey::operator EVP_PKEY *()
{
return _pEVPPKey;
}
}
inline void EVPPKey::setKey(EC_KEY* pKey)
{
inline void EVPPKey::setKey(EC_KEY * pKey)
{
if (!EVP_PKEY_set1_EC_KEY(_pEVPPKey, pKey))
throw OpenSSLException();
}
}
inline void EVPPKey::setKey(RSA* pKey)
{
inline void EVPPKey::setKey(RSA * pKey)
{
if (!EVP_PKEY_set1_RSA(_pEVPPKey, pKey))
throw OpenSSLException();
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_EVPPKeyImpl_INCLUDED

View File

@ -23,22 +23,24 @@
#include "Poco/Crypto/KeyPairImpl.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class X509Certificate;
class X509Certificate;
class Crypto_API KeyPair
class Crypto_API KeyPair
/// This is a parent class for classes storing a key pair, consisting
/// of private and public key. Storage of the private key is optional.
///
/// If a private key is available, the KeyPair can be
/// used for decrypting data (encrypted with the public key)
/// or computing secure digital signatures.
{
public:
{
public:
enum Type
{
KT_RSA = KeyPairImpl::KT_RSA_IMPL,
@ -54,17 +56,19 @@ public:
virtual int size() const;
/// Returns the RSA modulus size.
virtual void save(const std::string& publicKeyPairFile,
const std::string& privateKeyPairFile = "",
const std::string& privateKeyPairPassphrase = "") const;
virtual void save(
const std::string & publicKeyPairFile,
const std::string & privateKeyPairFile = "",
const std::string & privateKeyPairPassphrase = "") const;
/// Exports the public and private keys to the given files.
///
/// If an empty filename is specified, the corresponding key
/// is not exported.
virtual void save(std::ostream* pPublicKeyPairStream,
std::ostream* pPrivateKeyPairStream = 0,
const std::string& privateKeyPairPassphrase = "") const;
virtual void save(
std::ostream * pPublicKeyPairStream,
std::ostream * pPrivateKeyPairStream = 0,
const std::string & privateKeyPairPassphrase = "") const;
/// Exports the public and private key to the given streams.
///
/// If a null pointer is passed for a stream, the corresponding
@ -73,61 +77,60 @@ public:
KeyPairImpl::Ptr impl() const;
/// Returns the impl object.
const std::string& name() const;
const std::string & name() const;
/// Returns key pair name
Type type() const;
/// Returns key pair type
private:
private:
KeyPairImpl::Ptr _pImpl;
};
};
//
// inlines
//
//
// inlines
//
inline int KeyPair::size() const
{
inline int KeyPair::size() const
{
return _pImpl->size();
}
}
inline void KeyPair::save(const std::string& publicKeyFile,
const std::string& privateKeyFile,
const std::string& privateKeyPassphrase) const
{
inline void
KeyPair::save(const std::string & publicKeyFile, const std::string & privateKeyFile, const std::string & privateKeyPassphrase) const
{
_pImpl->save(publicKeyFile, privateKeyFile, privateKeyPassphrase);
}
}
inline void KeyPair::save(std::ostream* pPublicKeyStream,
std::ostream* pPrivateKeyStream,
const std::string& privateKeyPassphrase) const
{
inline void
KeyPair::save(std::ostream * pPublicKeyStream, std::ostream * pPrivateKeyStream, const std::string & privateKeyPassphrase) const
{
_pImpl->save(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase);
}
}
inline const std::string& KeyPair::name() const
{
inline const std::string & KeyPair::name() const
{
return _pImpl->name();
}
}
inline KeyPairImpl::Ptr KeyPair::impl() const
{
inline KeyPairImpl::Ptr KeyPair::impl() const
{
return _pImpl;
}
}
inline KeyPair::Type KeyPair::type() const
{
inline KeyPair::Type KeyPair::type() const
{
return (KeyPair::Type)impl()->type();
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_KeyPair_INCLUDED

View File

@ -19,22 +19,24 @@
#define Crypto_KeyPairImplImpl_INCLUDED
#include <string>
#include <vector>
#include "Poco/AutoPtr.h"
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <string>
#include <vector>
namespace Poco {
namespace Crypto {
class KeyPairImpl: public Poco::RefCountedObject
/// Class KeyPairImpl
namespace Poco
{
public:
namespace Crypto
{
class KeyPairImpl : public Poco::RefCountedObject
/// Class KeyPairImpl
{
public:
enum Type
{
KT_RSA_IMPL = 0,
@ -44,7 +46,7 @@ public:
typedef Poco::AutoPtr<KeyPairImpl> Ptr;
typedef std::vector<unsigned char> ByteVec;
KeyPairImpl(const std::string& name, Type type);
KeyPairImpl(const std::string & name, Type type);
/// Create KeyPairImpl with specified type and name.
virtual ~KeyPairImpl();
@ -53,55 +55,56 @@ public:
virtual int size() const = 0;
/// Returns the key size.
virtual void save(const std::string& publicKeyFile,
const std::string& privateKeyFile = "",
const std::string& privateKeyPassphrase = "") const = 0;
virtual void save(
const std::string & publicKeyFile,
const std::string & privateKeyFile = "",
const std::string & privateKeyPassphrase = "") const = 0;
/// Exports the public and private keys to the given files.
///
/// If an empty filename is specified, the corresponding key
/// is not exported.
virtual void save(std::ostream* pPublicKeyStream,
std::ostream* pPrivateKeyStream = 0,
const std::string& privateKeyPassphrase = "") const = 0;
virtual void save(
std::ostream * pPublicKeyStream, std::ostream * pPrivateKeyStream = 0, const std::string & privateKeyPassphrase = "") const = 0;
/// Exports the public and private key to the given streams.
///
/// If a null pointer is passed for a stream, the corresponding
/// key is not exported.
const std::string& name() const;
const std::string & name() const;
/// Returns key pair name
Type type() const;
/// Returns key pair type
private:
private:
KeyPairImpl();
std::string _name;
Type _type;
OpenSSLInitializer _openSSLInitializer;
};
};
//
// inlines
//
//
// inlines
//
inline const std::string& KeyPairImpl::name() const
{
inline const std::string & KeyPairImpl::name() const
{
return _name;
}
}
inline KeyPairImpl::Type KeyPairImpl::type() const
{
inline KeyPairImpl::Type KeyPairImpl::type() const
{
return _type;
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_KeyPairImplImpl_INCLUDED

View File

@ -18,36 +18,37 @@
#define Crypto_OpenSSLInitializer_INCLUDED
#include <openssl/crypto.h>
#include "Poco/AtomicCounter.h"
#include "Poco/Crypto/Crypto.h"
#include "Poco/Mutex.h"
#include "Poco/AtomicCounter.h"
#include <openssl/crypto.h>
#if defined(OPENSSL_FIPS) && OPENSSL_VERSION_NUMBER < 0x010001000L
#include <openssl/fips.h>
# include <openssl/fips.h>
#endif
extern "C"
extern "C" {
struct CRYPTO_dynlock_value
{
struct CRYPTO_dynlock_value
{
Poco::FastMutex _mutex;
};
};
}
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class Crypto_API OpenSSLInitializer
class Crypto_API OpenSSLInitializer
/// Initializes the OpenSSL library.
///
/// The class ensures the earliest initialization and the
/// latest shutdown of the OpenSSL library.
{
public:
{
public:
OpenSSLInitializer();
/// Automatically initialize OpenSSL on startup.
@ -66,50 +67,51 @@ public:
static void enableFIPSMode(bool enabled);
// Enable or disable FIPS mode. If FIPS is not available, this method doesn't do anything.
protected:
protected:
enum
{
SEEDSIZE = 256
};
// OpenSSL multithreading support
static void lock(int mode, int n, const char* file, int line);
static void lock(int mode, int n, const char * file, int line);
static unsigned long id();
static struct CRYPTO_dynlock_value* dynlockCreate(const char* file, int line);
static void dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line);
static void dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line);
static struct CRYPTO_dynlock_value * dynlockCreate(const char * file, int line);
static void dynlock(int mode, struct CRYPTO_dynlock_value * lock, const char * file, int line);
static void dynlockDestroy(struct CRYPTO_dynlock_value * lock, const char * file, int line);
private:
static Poco::FastMutex* _mutexes;
private:
static Poco::FastMutex * _mutexes;
static Poco::AtomicCounter _rc;
};
};
//
// inlines
//
inline bool OpenSSLInitializer::isFIPSEnabled()
{
//
// inlines
//
inline bool OpenSSLInitializer::isFIPSEnabled()
{
#ifdef OPENSSL_FIPS
return FIPS_mode() ? true : false;
#else
return false;
#endif
}
}
#ifdef OPENSSL_FIPS
inline void OpenSSLInitializer::enableFIPSMode(bool enabled)
{
inline void OpenSSLInitializer::enableFIPSMode(bool enabled)
{
FIPS_mode_set(enabled);
}
}
#else
inline void OpenSSLInitializer::enableFIPSMode(bool /*enabled*/)
{
}
inline void OpenSSLInitializer::enableFIPSMode(bool /*enabled*/)
{
}
#endif
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_OpenSSLInitializer_INCLUDED

View File

@ -18,45 +18,47 @@
#define Crypto_PKCS12Container_INCLUDED
#include <istream>
#include <memory>
#include <openssl/pkcs12.h>
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/EVPPKey.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/Crypto/X509Certificate.h"
#include "Poco/Crypto/EVPPKey.h"
#include "Poco/Path.h"
#include <memory>
#include <istream>
#include <openssl/pkcs12.h>
namespace Poco {
namespace Crypto {
class Crypto_API PKCS12Container
/// This class implements PKCS#12 container functionality.
namespace Poco
{
public:
namespace Crypto
{
class Crypto_API PKCS12Container
/// This class implements PKCS#12 container functionality.
{
public:
typedef X509Certificate::List CAList;
typedef std::vector<std::string> CANameList;
explicit PKCS12Container(std::istream& istr, const std::string& password = "");
explicit PKCS12Container(std::istream & istr, const std::string & password = "");
/// Creates the PKCS12Container object from a stream.
explicit PKCS12Container(const std::string& path, const std::string& password = "");
explicit PKCS12Container(const std::string & path, const std::string & password = "");
/// Creates the PKCS12Container object from a file.
PKCS12Container(const PKCS12Container& cont);
PKCS12Container(const PKCS12Container & cont);
/// Copy constructor.
PKCS12Container& operator = (const PKCS12Container& cont);
PKCS12Container & operator=(const PKCS12Container & cont);
/// Assignment operator.
#ifdef POCO_ENABLE_CPP11
PKCS12Container(PKCS12Container&& cont);
PKCS12Container(PKCS12Container && cont);
/// Move constructor.
PKCS12Container& operator = (PKCS12Container&& cont);
PKCS12Container & operator=(PKCS12Container && cont);
/// Move assignment operator.
#endif // POCO_ENABLE_CPP11
@ -73,22 +75,22 @@ public:
bool hasX509Certificate() const;
/// Returns true if container has X509 certificate.
const X509Certificate& getX509Certificate() const;
const X509Certificate & getX509Certificate() const;
/// Returns the X509 certificate.
/// Throws NotFoundException if there is no certificate.
const CAList& getCACerts() const;
const CAList & getCACerts() const;
/// Returns the list of CA certificates in this container.
const std::string& getFriendlyName() const;
const std::string & getFriendlyName() const;
/// Returns the friendly name of the certificate bag.
const CANameList& getFriendlyNamesCA() const;
const CANameList & getFriendlyNamesCA() const;
/// Returns a list of CA certificates friendly names.
private:
void load(PKCS12* pPKCS12, const std::string& password = "");
std::string extractFriendlyName(X509* pCert);
private:
void load(PKCS12 * pPKCS12, const std::string & password = "");
std::string extractFriendlyName(X509 * pCert);
#ifdef POCO_ENABLE_CPP11
typedef std::unique_ptr<X509Certificate> CertPtr;
@ -97,63 +99,64 @@ private:
#endif // #ifdef POCO_ENABLE_CPP11
OpenSSLInitializer _openSSLInitializer;
EVP_PKEY* _pKey;
EVP_PKEY * _pKey;
CertPtr _pX509Cert;
CAList _caCertList;
CANameList _caCertNames;
std::string _pkcsFriendlyName;
};
};
//
// inlines
//
//
// inlines
//
inline bool PKCS12Container::hasX509Certificate() const
{
inline bool PKCS12Container::hasX509Certificate() const
{
return _pX509Cert.get() != 0;
}
}
inline const X509Certificate& PKCS12Container::getX509Certificate() const
{
inline const X509Certificate & PKCS12Container::getX509Certificate() const
{
if (!hasX509Certificate())
throw NotFoundException("PKCS12Container X509 certificate");
return *_pX509Cert;
}
}
inline const std::string& PKCS12Container::getFriendlyName() const
{
inline const std::string & PKCS12Container::getFriendlyName() const
{
return _pkcsFriendlyName;
}
}
inline const PKCS12Container::CAList& PKCS12Container::getCACerts() const
{
inline const PKCS12Container::CAList & PKCS12Container::getCACerts() const
{
return _caCertList;
}
}
inline const PKCS12Container::CANameList& PKCS12Container::getFriendlyNamesCA() const
{
inline const PKCS12Container::CANameList & PKCS12Container::getFriendlyNamesCA() const
{
return _caCertNames;
}
}
inline bool PKCS12Container::hasKey() const
{
inline bool PKCS12Container::hasKey() const
{
return _pKey != 0;
}
}
inline EVPPKey PKCS12Container::getKey() const
{
inline EVPPKey PKCS12Container::getKey() const
{
return EVPPKey(_pKey);
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_PKCS12Container_INCLUDED

View File

@ -18,18 +18,20 @@
#define Crypto_RSACipherImpl_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/Cipher.h"
#include "Poco/Crypto/RSAKey.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include <openssl/evp.h>
#include "Poco/Crypto/Cipher.h"
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/Crypto/RSAKey.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class RSACipherImpl: public Cipher
class RSACipherImpl : public Cipher
/// An implementation of the Cipher class for
/// asymmetric (public-private key) encryption
/// based on the the RSA algorithm in OpenSSL's
@ -37,41 +39,42 @@ class RSACipherImpl: public Cipher
///
/// Encryption is using the public key, decryption
/// requires the private key.
{
public:
RSACipherImpl(const RSAKey& key, RSAPaddingMode paddingMode);
{
public:
RSACipherImpl(const RSAKey & key, RSAPaddingMode paddingMode);
/// Creates a new RSACipherImpl object for the given RSAKey
/// and using the given padding mode.
virtual ~RSACipherImpl();
/// Destroys the RSACipherImpl.
const std::string& name() const;
const std::string & name() const;
/// Returns the name of the Cipher.
CryptoTransform* createEncryptor();
CryptoTransform * createEncryptor();
/// Creates an encryptor object.
CryptoTransform* createDecryptor();
CryptoTransform * createDecryptor();
/// Creates a decryptor object.
private:
private:
RSAKey _key;
RSAPaddingMode _paddingMode;
OpenSSLInitializer _openSSLInitializer;
};
};
//
// Inlines
//
inline const std::string& RSACipherImpl::name() const
{
//
// Inlines
//
inline const std::string & RSACipherImpl::name() const
{
return _key.name();
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_RSACipherImpl_INCLUDED

View File

@ -18,19 +18,21 @@
#define Crypto_RSADigestEngine_INCLUDED
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/RSAKey.h"
#include "Poco/DigestEngine.h"
#include "Poco/Crypto/DigestEngine.h"
#include <istream>
#include <ostream>
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/DigestEngine.h"
#include "Poco/Crypto/RSAKey.h"
#include "Poco/DigestEngine.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class Crypto_API RSADigestEngine: public Poco::DigestEngine
class Crypto_API RSADigestEngine : public Poco::DigestEngine
/// This class implements a Poco::DigestEngine that can be
/// used to compute a secure digital signature.
///
@ -43,8 +45,8 @@ class Crypto_API RSADigestEngine: public Poco::DigestEngine
/// member function. It will decrypt the signature
/// using the RSA public key and compare the resulting
/// hash with the actual hash of the data.
{
public:
{
public:
enum DigestType
{
DIGEST_MD5,
@ -52,12 +54,12 @@ public:
};
//@ deprecated
RSADigestEngine(const RSAKey& key, DigestType digestType = DIGEST_SHA1);
RSADigestEngine(const RSAKey & key, DigestType digestType = DIGEST_SHA1);
/// Creates the RSADigestEngine with the given RSA key,
/// using the MD5 or SHA-1 hash algorithm.
/// Kept for backward compatibility
RSADigestEngine(const RSAKey& key, const std::string &name);
RSADigestEngine(const RSAKey & key, const std::string & name);
/// Creates the RSADigestEngine with the given RSA key,
/// using the hash algorithm with the given name
/// (e.g., "MD5", "SHA1", "SHA256", "SHA512", etc.).
@ -75,37 +77,38 @@ public:
/// Resets the engine so that a new
/// digest can be computed.
const DigestEngine::Digest& digest();
const DigestEngine::Digest & digest();
/// Finishes the computation of the digest
/// (the first time it's called) and
/// returns the message digest.
///
/// Can be called multiple times.
const DigestEngine::Digest& signature();
const DigestEngine::Digest & signature();
/// Signs the digest using the RSA algorithm
/// and the private key (the first time it's
/// called) and returns the result.
///
/// Can be called multiple times.
bool verify(const DigestEngine::Digest& signature);
bool verify(const DigestEngine::Digest & signature);
/// Verifies the data against the signature.
///
/// Returns true if the signature can be verified, false otherwise.
protected:
void updateImpl(const void* data, std::size_t length);
protected:
void updateImpl(const void * data, std::size_t length);
private:
private:
RSAKey _key;
Poco::Crypto::DigestEngine _engine;
Poco::DigestEngine::Digest _digest;
Poco::DigestEngine::Digest _signature;
};
};
} } // namespace Poco::Crypto
}
} // namespace Poco::Crypto
#endif // Crypto_RSADigestEngine_INCLUDED

View File

@ -23,15 +23,17 @@
#include "Poco/Crypto/RSAKeyImpl.h"
namespace Poco {
namespace Crypto {
namespace Poco
{
namespace Crypto
{
class X509Certificate;
class PKCS12Container;
class X509Certificate;
class PKCS12Container;
class Crypto_API RSAKey : public KeyPair
class Crypto_API RSAKey : public KeyPair
/// This class stores an RSA key pair, consisting
/// of private and public key. Storage of the private
/// key is optional.
@ -39,8 +41,8 @@ class Crypto_API RSAKey : public KeyPair
/// If a private key is available, the RSAKey can be
/// used for decrypting data (encrypted with the public key)
/// or computing secure digital signatures.
{
public:
{
public:
enum KeyLength
{
KL_512 = 512,
@ -55,22 +57,20 @@ public:
EXP_LARGE
};
RSAKey(const EVPPKey& key);
RSAKey(const EVPPKey & key);
/// Constructs ECKeyImpl by extracting the EC key.
RSAKey(const X509Certificate& cert);
RSAKey(const X509Certificate & cert);
/// Extracts the RSA public key from the given certificate.
RSAKey(const PKCS12Container& cert);
RSAKey(const PKCS12Container & cert);
/// Extracts the RSA private key from the given certificate.
RSAKey(KeyLength keyLength, Exponent exp);
/// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
/// Can be used to sign data and verify signatures.
RSAKey(const std::string& publicKeyFile,
const std::string& privateKeyFile = "",
const std::string& privateKeyPassphrase = "");
RSAKey(const std::string & publicKeyFile, const std::string & privateKeyFile = "", const std::string & privateKeyPassphrase = "");
/// Creates the RSAKey, by reading public and private key from the given files and
/// using the given passphrase for the private key.
///
@ -79,9 +79,7 @@ public:
/// If a private key is specified, you don't need to specify a public key file.
/// OpenSSL will auto-create the public key from the private key.
RSAKey(std::istream* pPublicKeyStream,
std::istream* pPrivateKeyStream = 0,
const std::string& privateKeyPassphrase = "");
RSAKey(std::istream * pPublicKeyStream, std::istream * pPrivateKeyStream = 0, const std::string & privateKeyPassphrase = "");
/// Creates the RSAKey, by reading public and private key from the given streams and
/// using the given passphrase for the private key.
///
@ -105,21 +103,22 @@ public:
RSAKeyImpl::Ptr impl() const;
/// Returns the impl object.
private:
private:
RSAKeyImpl::Ptr _pImpl;
};
};
//
// inlines
//
inline RSAKeyImpl::Ptr RSAKey::impl() const
{
//
// inlines
//
inline RSAKeyImpl::Ptr RSAKey::impl() const
{
return _pImpl;
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_RSAKey_INCLUDED

View File

@ -18,15 +18,15 @@
#define Crypto_RSAKeyImplImpl_INCLUDED
#include <istream>
#include <ostream>
#include <vector>
#include "Poco/AutoPtr.h"
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/EVPPKey.h"
#include "Poco/Crypto/KeyPairImpl.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <istream>
#include <ostream>
#include <vector>
struct bignum_st;
@ -35,40 +35,42 @@ typedef struct bignum_st BIGNUM;
typedef struct rsa_st RSA;
namespace Poco {
namespace Crypto {
class X509Certificate;
class PKCS12Container;
class RSAKeyImpl: public KeyPairImpl
/// class RSAKeyImpl
namespace Poco
{
public:
namespace Crypto
{
class X509Certificate;
class PKCS12Container;
class RSAKeyImpl : public KeyPairImpl
/// class RSAKeyImpl
{
public:
typedef Poco::AutoPtr<RSAKeyImpl> Ptr;
typedef std::vector<unsigned char> ByteVec;
RSAKeyImpl(const EVPPKey& key);
RSAKeyImpl(const EVPPKey & key);
/// Constructs ECKeyImpl by extracting the EC key.
RSAKeyImpl(const X509Certificate& cert);
RSAKeyImpl(const X509Certificate & cert);
/// Extracts the RSA public key from the given certificate.
RSAKeyImpl(const PKCS12Container& cert);
RSAKeyImpl(const PKCS12Container & cert);
/// Extracts the EC private key from the given certificate.
RSAKeyImpl(int keyLength, unsigned long exponent);
/// Creates the RSAKey. Creates a new public/private keypair using the given parameters.
/// Can be used to sign data and verify signatures.
RSAKeyImpl(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase);
RSAKeyImpl(const std::string & publicKeyFile, const std::string & privateKeyFile, const std::string & privateKeyPassphrase);
/// Creates the RSAKey, by reading public and private key from the given files and
/// using the given passphrase for the private key. Can only by used for signing if
/// a private key is available.
RSAKeyImpl(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase);
RSAKeyImpl(std::istream * pPublicKeyStream, std::istream * pPrivateKeyStream, const std::string & privateKeyPassphrase);
/// Creates the RSAKey. Can only by used for signing if pPrivKey
/// is not null. If a private key file is specified, you don't need to
/// specify a public key file. OpenSSL will auto-create it from the private key.
@ -76,10 +78,10 @@ public:
~RSAKeyImpl();
/// Destroys the RSAKeyImpl.
RSA* getRSA();
RSA * getRSA();
/// Returns the OpenSSL RSA object.
const RSA* getRSA() const;
const RSA * getRSA() const;
/// Returns the OpenSSL RSA object.
int size() const;
@ -94,48 +96,47 @@ public:
ByteVec decryptionExponent() const;
/// Returns the RSA decryption exponent.
void save(const std::string& publicKeyFile,
const std::string& privateKeyFile = "",
const std::string& privateKeyPassphrase = "") const;
void save(const std::string & publicKeyFile, const std::string & privateKeyFile = "", const std::string & privateKeyPassphrase = "")
const;
/// Exports the public and private keys to the given files.
///
/// If an empty filename is specified, the corresponding key
/// is not exported.
void save(std::ostream* pPublicKeyStream,
std::ostream* pPrivateKeyStream = 0,
const std::string& privateKeyPassphrase = "") const;
void
save(std::ostream * pPublicKeyStream, std::ostream * pPrivateKeyStream = 0, const std::string & privateKeyPassphrase = "") const;
/// Exports the public and private key to the given streams.
///
/// If a null pointer is passed for a stream, the corresponding
/// key is not exported.
private:
private:
RSAKeyImpl();
void freeRSA();
static ByteVec convertToByteVec(const BIGNUM* bn);
static ByteVec convertToByteVec(const BIGNUM * bn);
RSA* _pRSA;
};
RSA * _pRSA;
};
//
// inlines
//
inline RSA* RSAKeyImpl::getRSA()
{
//
// inlines
//
inline RSA * RSAKeyImpl::getRSA()
{
return _pRSA;
}
}
inline const RSA* RSAKeyImpl::getRSA() const
{
inline const RSA * RSAKeyImpl::getRSA() const
{
return _pRSA;
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_RSAKeyImplImpl_INCLUDED

View File

@ -18,24 +18,26 @@
#define Crypto_X509Certificate_INCLUDED
#include <istream>
#include <set>
#include <vector>
#include <openssl/ssl.h>
#include "Poco/Crypto/Crypto.h"
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/DateTime.h"
#include "Poco/SharedPtr.h"
#include <vector>
#include <set>
#include <istream>
#include <openssl/ssl.h>
namespace Poco {
namespace Crypto {
class Crypto_API X509Certificate
/// This class represents a X509 Certificate.
namespace Poco
{
public:
namespace Crypto
{
class Crypto_API X509Certificate
/// This class represents a X509 Certificate.
{
public:
typedef std::vector<X509Certificate> List;
enum NID
@ -52,32 +54,32 @@ public:
NID_SERIAL_NUMBER = 105
};
explicit X509Certificate(std::istream& istr);
explicit X509Certificate(std::istream & istr);
/// Creates the X509Certificate object by reading
/// a certificate in PEM format from a stream.
explicit X509Certificate(const std::string& path);
explicit X509Certificate(const std::string & path);
/// Creates the X509Certificate object by reading
/// a certificate in PEM format from a file.
explicit X509Certificate(X509* pCert);
explicit X509Certificate(X509 * pCert);
/// Creates the X509Certificate from an existing
/// OpenSSL certificate. Ownership is taken of
/// the certificate.
X509Certificate(X509* pCert, bool shared);
X509Certificate(X509 * pCert, bool shared);
/// Creates the X509Certificate from an existing
/// OpenSSL certificate. Ownership is taken of
/// the certificate. If shared is true, the
/// certificate's reference count is incremented.
X509Certificate(const X509Certificate& cert);
X509Certificate(const X509Certificate & cert);
/// Creates the certificate by copying another one.
X509Certificate& operator = (const X509Certificate& cert);
X509Certificate & operator=(const X509Certificate & cert);
/// Assigns a certificate.
void swap(X509Certificate& cert);
void swap(X509Certificate & cert);
/// Exchanges the certificate with another one.
~X509Certificate();
@ -86,11 +88,11 @@ public:
long version() const;
/// Returns the version of the certificate.
const std::string& serialNumber() const;
const std::string & serialNumber() const;
/// Returns the certificate serial number as a
/// string in decimal encoding.
const std::string& issuerName() const;
const std::string & issuerName() const;
/// Returns the certificate issuer's distinguished name.
std::string issuerName(NID nid) const;
@ -98,7 +100,7 @@ public:
/// NID (name identifier) from the certificate issuer's
/// distinguished name.
const std::string& subjectName() const;
const std::string & subjectName() const;
/// Returns the certificate subject's distinguished name.
std::string subjectName(NID nid) const;
@ -110,7 +112,7 @@ public:
/// Returns the common name stored in the certificate
/// subject's distinguished name.
void extractNames(std::string& commonName, std::set<std::string>& domainNames) const;
void extractNames(std::string & commonName, std::set<std::string> & domainNames) const;
/// Extracts the common name and the alias domain names from the
/// certificate.
@ -120,15 +122,15 @@ public:
Poco::DateTime expiresOn() const;
/// Returns the date and time the certificate expires.
void save(std::ostream& stream) const;
void save(std::ostream & stream) const;
/// Writes the certificate to the given stream.
/// The certificate is written in PEM format.
void save(const std::string& path) const;
void save(const std::string & path) const;
/// Writes the certificate to the file given by path.
/// The certificate is written in PEM format.
bool issuedBy(const X509Certificate& issuerCertificate) const;
bool issuedBy(const X509Certificate & issuerCertificate) const;
/// Checks whether the certificate has been issued by
/// the issuer given by issuerCertificate. This can be
/// used to validate a certificate chain.
@ -140,7 +142,7 @@ public:
/// Returns true if verification against the issuer certificate
/// was successful, false otherwise.
bool equals(const X509Certificate& otherCertificate) const;
bool equals(const X509Certificate & otherCertificate) const;
/// Checks whether the certificate is equal to
/// the other certificate, by comparing the hashes
/// of both certificates.
@ -148,10 +150,10 @@ public:
/// Returns true if both certificates are identical,
/// otherwise false.
const X509* certificate() const;
const X509 * certificate() const;
/// Returns the underlying OpenSSL certificate.
X509* dup() const;
X509 * dup() const;
/// Duplicates and returns the underlying OpenSSL certificate. Note that
/// the caller assumes responsibility for the lifecycle of the created
/// certificate.
@ -159,29 +161,29 @@ public:
std::string signatureAlgorithm() const;
/// Returns the certificate signature algorithm long name.
void print(std::ostream& out) const;
void print(std::ostream & out) const;
/// Prints the certificate information to ostream.
static List readPEM(const std::string& pemFileName);
static List readPEM(const std::string & pemFileName);
/// Reads and returns a list of certificates from
/// the specified PEM file.
static void writePEM(const std::string& pemFileName, const List& list);
static void writePEM(const std::string & pemFileName, const List & list);
/// Writes the list of certificates to the specified PEM file.
protected:
void load(std::istream& stream);
protected:
void load(std::istream & stream);
/// Loads the certificate from the given stream. The
/// certificate must be in PEM format.
void load(const std::string& path);
void load(const std::string & path);
/// Loads the certificate from the given file. The
/// certificate must be in PEM format.
void init();
/// Extracts issuer and subject name from the certificate.
private:
private:
enum
{
NAME_BUFFER_SIZE = 256
@ -190,56 +192,57 @@ private:
std::string _issuerName;
std::string _subjectName;
std::string _serialNumber;
X509* _pCert;
X509 * _pCert;
OpenSSLInitializer _openSSLInitializer;
};
};
//
// inlines
//
//
// inlines
//
inline long X509Certificate::version() const
{
inline long X509Certificate::version() const
{
// This is defined by standards (X.509 et al) to be
// one less than the certificate version.
// So, eg. a version 3 certificate will return 2.
return X509_get_version(_pCert) + 1;
}
}
inline const std::string& X509Certificate::serialNumber() const
{
inline const std::string & X509Certificate::serialNumber() const
{
return _serialNumber;
}
}
inline const std::string& X509Certificate::issuerName() const
{
inline const std::string & X509Certificate::issuerName() const
{
return _issuerName;
}
}
inline const std::string& X509Certificate::subjectName() const
{
inline const std::string & X509Certificate::subjectName() const
{
return _subjectName;
}
}
inline const X509* X509Certificate::certificate() const
{
inline const X509 * X509Certificate::certificate() const
{
return _pCert;
}
}
inline X509* X509Certificate::dup() const
{
inline X509 * X509Certificate::dup() const
{
return X509_dup(_pCert);
}
}
} } // namespace Poco::Crypto
} // namespace Poco::Crypto
#endif // Crypto_X509Certificate_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@ -18,79 +18,84 @@
#define Data_ODBC_ConnectionHandle_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/EnvironmentHandle.h"
#include "Poco/Data/ODBC/ODBC.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqltypes.h>
namespace Poco {
namespace Data {
namespace ODBC {
class ODBC_API ConnectionHandle
/// ODBC connection handle class
namespace Poco
{
public:
ConnectionHandle(EnvironmentHandle* pEnvironment = 0);
namespace Data
{
namespace ODBC
{
class ODBC_API ConnectionHandle
/// ODBC connection handle class
{
public:
ConnectionHandle(EnvironmentHandle * pEnvironment = 0);
/// Creates the ConnectionHandle.
~ConnectionHandle();
/// Creates the ConnectionHandle.
operator const SQLHDBC& () const;
operator const SQLHDBC &() const;
/// Const conversion operator into reference to native type.
const SQLHDBC& handle() const;
const SQLHDBC & handle() const;
/// Returns const reference to handle;
private:
operator SQLHDBC& ();
private:
operator SQLHDBC &();
/// Conversion operator into reference to native type.
SQLHDBC& handle();
SQLHDBC & handle();
/// Returns reference to handle;
ConnectionHandle(const ConnectionHandle&);
const ConnectionHandle& operator=(const ConnectionHandle&);
ConnectionHandle(const ConnectionHandle &);
const ConnectionHandle & operator=(const ConnectionHandle &);
const EnvironmentHandle* _pEnvironment;
const EnvironmentHandle * _pEnvironment;
SQLHDBC _hdbc;
bool _ownsEnvironment;
};
};
//
// inlines
//
inline ConnectionHandle::operator const SQLHDBC& () const
{
//
// inlines
//
inline ConnectionHandle::operator const SQLHDBC &() const
{
return handle();
}
}
inline const SQLHDBC& ConnectionHandle::handle() const
{
inline const SQLHDBC & ConnectionHandle::handle() const
{
return _hdbc;
}
}
inline ConnectionHandle::operator SQLHDBC& ()
{
inline ConnectionHandle::operator SQLHDBC &()
{
return handle();
}
}
inline SQLHDBC& ConnectionHandle::handle()
{
inline SQLHDBC & ConnectionHandle::handle()
{
return _hdbc;
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif

View File

@ -18,19 +18,22 @@
#define Data_ODBC_Connector_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/Connector.h"
#include "Poco/Data/ODBC/ODBC.h"
namespace Poco {
namespace Data {
namespace ODBC {
class ODBC_API Connector: public Poco::Data::Connector
/// Connector instantiates SqLite SessionImpl objects.
namespace Poco
{
public:
namespace Data
{
namespace ODBC
{
class ODBC_API Connector : public Poco::Data::Connector
/// Connector instantiates SqLite SessionImpl objects.
{
public:
static const std::string KEY;
/// Keyword for creating ODBC sessions.
@ -40,11 +43,11 @@ public:
~Connector();
/// Destroys the Connector.
const std::string& name() const;
const std::string & name() const;
/// Returns the name associated with this connector.
Poco::AutoPtr<Poco::Data::SessionImpl> createSession(const std::string& connectionString,
std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT);
Poco::AutoPtr<Poco::Data::SessionImpl>
createSession(const std::string & connectionString, std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT);
/// Creates a ODBC SessionImpl object and initializes it with the given connectionString.
static void registerConnector();
@ -70,27 +73,29 @@ public:
/// Returns true if std::string is bound to SQL_LONGVARCHAR,
/// otherwise false (bound to SQL_VARCHAR).
private:
private:
static bool _bindStringToLongVarChar;
};
};
///
/// inlines
///
inline const std::string& Connector::name() const
{
///
/// inlines
///
inline const std::string & Connector::name() const
{
return KEY;
}
}
inline bool Connector::stringBoundToLongVarChar()
{
inline bool Connector::stringBoundToLongVarChar()
{
return _bindStringToLongVarChar;
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif // Data_ODBC_Connector_INCLUDED

View File

@ -18,29 +18,32 @@
#define Data_ODBC_Diagnostics_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include <vector>
#include <cstring>
#include <vector>
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Utility.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqlext.h>
namespace Poco {
namespace Data {
namespace ODBC {
namespace Poco
{
namespace Data
{
namespace ODBC
{
template <typename H, SQLSMALLINT handleType>
class Diagnostics
template <typename H, SQLSMALLINT handleType>
class Diagnostics
/// Utility class providing functionality for retrieving ODBC diagnostic
/// records. Diagnostics object must be created with corresponding handle
/// as constructor argument. During construction, diagnostic records fields
/// are populated and the object is ready for querying.
{
public:
{
public:
static const unsigned int SQL_STATE_SIZE = SQL_SQLSTATE_SIZE + 1;
static const unsigned int SQL_MESSAGE_LENGTH = SQL_MAX_MESSAGE_LENGTH + 1;
static const unsigned int SQL_NAME_LENGTH = 128;
@ -57,7 +60,7 @@ public:
typedef std::vector<DiagnosticFields> FieldVec;
typedef typename FieldVec::const_iterator Iterator;
explicit Diagnostics(const H& handle): _handle(handle)
explicit Diagnostics(const H & handle) : _handle(handle)
/// Creates and initializes the Diagnostics.
{
std::memset(_connectionName, 0, sizeof(_connectionName));
@ -73,21 +76,21 @@ public:
std::string sqlState(int index) const
/// Returns SQL state.
{
poco_assert (index < count());
return std::string((char*) _fields[index]._sqlState);
poco_assert(index < count());
return std::string((char *)_fields[index]._sqlState);
}
std::string message(int index) const
/// Returns error message.
{
poco_assert (index < count());
return std::string((char*) _fields[index]._message);
poco_assert(index < count());
return std::string((char *)_fields[index]._message);
}
long nativeError(int index) const
/// Returns native error code.
{
poco_assert (index < count());
poco_assert(index < count());
return _fields[index]._nativeError;
}
@ -97,7 +100,7 @@ public:
/// If connection name is not applicable for query context (such as when querying environment handle),
/// connection name defaults to NOT_APPLICABLE.
{
return std::string((char*) _connectionName);
return std::string((char *)_connectionName);
}
std::string serverName() const
@ -106,13 +109,13 @@ public:
/// If server name is not applicable for query context (such as when querying environment handle),
/// connection name defaults to NOT_APPLICABLE.
{
return std::string((char*) _serverName);
return std::string((char *)_serverName);
}
int count() const
/// Returns the number of contained diagnostic records.
{
return (int) _fields.size();
return (int)_fields.size();
}
void reset()
@ -121,22 +124,13 @@ public:
_fields.clear();
}
const FieldVec& fields() const
{
return _fields;
}
const FieldVec & fields() const { return _fields; }
Iterator begin() const
{
return _fields.begin();
}
Iterator begin() const { return _fields.begin(); }
Iterator end() const
{
return _fields.end();
}
Iterator end() const { return _fields.end(); }
const Diagnostics& diagnostics()
const Diagnostics & diagnostics()
{
DiagnosticFields df;
SQLSMALLINT count = 1;
@ -146,21 +140,16 @@ public:
reset();
while (!Utility::isError(SQLGetDiagRec(handleType,
_handle,
count,
df._sqlState,
&df._nativeError,
df._message,
SQL_MESSAGE_LENGTH,
&messageLength)))
while (!Utility::isError(SQLGetDiagRec(
handleType, _handle, count, df._sqlState, &df._nativeError, df._message, SQL_MESSAGE_LENGTH, &messageLength)))
{
if (1 == count)
{
// success of the following two calls is optional
// (they fail if connection has not been established yet
// or return empty string if not applicable for the context)
if (Utility::isError(SQLGetDiagField(handleType,
if (Utility::isError(SQLGetDiagField(
handleType,
_handle,
count,
SQL_DIAG_CONNECTION_NAME,
@ -168,33 +157,24 @@ public:
sizeof(_connectionName),
&messageLength)))
{
std::size_t len = sizeof(_connectionName) > none.length() ?
none.length() : sizeof(_connectionName) - 1;
std::size_t len = sizeof(_connectionName) > none.length() ? none.length() : sizeof(_connectionName) - 1;
std::memcpy(_connectionName, none.c_str(), len);
}
else if (0 == _connectionName[0])
{
std::size_t len = sizeof(_connectionName) > na.length() ?
na.length() : sizeof(_connectionName) - 1;
std::size_t len = sizeof(_connectionName) > na.length() ? na.length() : sizeof(_connectionName) - 1;
std::memcpy(_connectionName, na.c_str(), len);
}
if (Utility::isError(SQLGetDiagField(handleType,
_handle,
count,
SQL_DIAG_SERVER_NAME,
_serverName,
sizeof(_serverName),
&messageLength)))
if (Utility::isError(SQLGetDiagField(
handleType, _handle, count, SQL_DIAG_SERVER_NAME, _serverName, sizeof(_serverName), &messageLength)))
{
std::size_t len = sizeof(_serverName) > none.length() ?
none.length() : sizeof(_serverName) - 1;
std::size_t len = sizeof(_serverName) > none.length() ? none.length() : sizeof(_serverName) - 1;
std::memcpy(_serverName, none.c_str(), len);
}
else if (0 == _serverName[0])
{
std::size_t len = sizeof(_serverName) > na.length() ?
na.length() : sizeof(_serverName) - 1;
std::size_t len = sizeof(_serverName) > na.length() ? na.length() : sizeof(_serverName) - 1;
std::memcpy(_serverName, na.c_str(), len);
}
}
@ -211,8 +191,7 @@ public:
return *this;
}
private:
private:
Diagnostics();
/// SQLGetDiagField fields
@ -223,17 +202,19 @@ private:
FieldVec _fields;
/// Context handle
const H& _handle;
};
const H & _handle;
};
typedef Diagnostics<SQLHENV, SQL_HANDLE_ENV> EnvironmentDiagnostics;
typedef Diagnostics<SQLHDBC, SQL_HANDLE_DBC> ConnectionDiagnostics;
typedef Diagnostics<SQLHSTMT, SQL_HANDLE_STMT> StatementDiagnostics;
typedef Diagnostics<SQLHDESC, SQL_HANDLE_DESC> DescriptorDiagnostics;
typedef Diagnostics<SQLHENV, SQL_HANDLE_ENV> EnvironmentDiagnostics;
typedef Diagnostics<SQLHDBC, SQL_HANDLE_DBC> ConnectionDiagnostics;
typedef Diagnostics<SQLHSTMT, SQL_HANDLE_STMT> StatementDiagnostics;
typedef Diagnostics<SQLHDESC, SQL_HANDLE_DESC> DescriptorDiagnostics;
} } } // namespace Poco::Data::ODBC
}
}
} // namespace Poco::Data::ODBC
#endif

View File

@ -20,75 +20,80 @@
#include "Poco/Data/ODBC/ODBC.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqltypes.h>
namespace Poco {
namespace Data {
namespace ODBC {
class ODBC_API EnvironmentHandle
/// ODBC environment handle class
namespace Poco
{
public:
namespace Data
{
namespace ODBC
{
class ODBC_API EnvironmentHandle
/// ODBC environment handle class
{
public:
EnvironmentHandle();
/// Creates the EnvironmentHandle.
~EnvironmentHandle();
/// Destroys the EnvironmentHandle.
operator const SQLHENV& () const;
operator const SQLHENV &() const;
/// Const conversion operator into reference to native type.
const SQLHENV& handle() const;
const SQLHENV & handle() const;
/// Returns const reference to handle.
private:
operator SQLHENV& ();
private:
operator SQLHENV &();
/// Conversion operator into reference to native type.
SQLHENV& handle();
SQLHENV & handle();
/// Returns reference to handle.
EnvironmentHandle(const EnvironmentHandle&);
const EnvironmentHandle& operator=(const EnvironmentHandle&);
EnvironmentHandle(const EnvironmentHandle &);
const EnvironmentHandle & operator=(const EnvironmentHandle &);
SQLHENV _henv;
bool _isOwner;
};
};
///
/// inlines
///
inline EnvironmentHandle::operator const SQLHENV& () const
{
///
/// inlines
///
inline EnvironmentHandle::operator const SQLHENV &() const
{
return handle();
}
}
inline const SQLHENV& EnvironmentHandle::handle() const
{
inline const SQLHENV & EnvironmentHandle::handle() const
{
return _henv;
}
}
inline EnvironmentHandle::operator SQLHENV& ()
{
inline EnvironmentHandle::operator SQLHENV &()
{
return handle();
}
}
inline SQLHENV& EnvironmentHandle::handle()
{
inline SQLHENV & EnvironmentHandle::handle()
{
return _henv;
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif

View File

@ -18,30 +18,33 @@
#define Data_ODBC_Error_INCLUDED
#include <vector>
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Format.h"
#include <vector>
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqlext.h>
namespace Poco {
namespace Data {
namespace ODBC {
namespace Poco
{
namespace Data
{
namespace ODBC
{
template <typename H, SQLSMALLINT handleType>
class Error
template <typename H, SQLSMALLINT handleType>
class Error
/// Class encapsulating ODBC diagnostic record collection. Collection is generated
/// during construction. Class provides access and string generation for the collection
/// as well as individual diagnostic records.
{
public:
explicit Error(const H& handle) : _diagnostics(handle)
{
public:
explicit Error(const H & handle) : _diagnostics(handle)
/// Creates the Error.
{
}
@ -51,7 +54,7 @@ public:
{
}
const Diagnostics<H, handleType>& diagnostics() const
const Diagnostics<H, handleType> & diagnostics() const
/// Returns the associated diagnostics.
{
return _diagnostics;
@ -60,17 +63,18 @@ public:
int count() const
/// Returns the count of diagnostic records.
{
return (int) _diagnostics.count();
return (int)_diagnostics.count();
}
std::string& toString(int index, std::string& str) const
std::string & toString(int index, std::string & str) const
/// Generates the string for the diagnostic record.
{
if ((index < 0) || (index > (count() - 1)))
return str;
std::string s;
Poco::format(s,
Poco::format(
s,
"===========================\n"
"ODBC Diagnostic record #%d:\n"
"===========================\n"
@ -90,10 +94,7 @@ public:
{
std::string str;
Poco::format(str,
"Connection:%s\nServer:%s\n",
_diagnostics.connectionName(),
_diagnostics.serverName());
Poco::format(str, "Connection:%s\nServer:%s\n", _diagnostics.connectionName(), _diagnostics.serverName());
std::string s;
for (int i = 0; i < count(); ++i)
@ -105,20 +106,22 @@ public:
return str;
}
private:
private:
Error();
Diagnostics<H, handleType> _diagnostics;
};
};
typedef Error<SQLHENV, SQL_HANDLE_ENV> EnvironmentError;
typedef Error<SQLHDBC, SQL_HANDLE_DBC> ConnectionError;
typedef Error<SQLHSTMT, SQL_HANDLE_STMT> StatementError;
typedef Error<SQLHSTMT, SQL_HANDLE_DESC> DescriptorError;
typedef Error<SQLHENV, SQL_HANDLE_ENV> EnvironmentError;
typedef Error<SQLHDBC, SQL_HANDLE_DBC> ConnectionError;
typedef Error<SQLHSTMT, SQL_HANDLE_STMT> StatementError;
typedef Error<SQLHSTMT, SQL_HANDLE_DESC> DescriptorError;
} } } // namespace Poco::Data::ODBC
}
}
} // namespace Poco::Data::ODBC
#endif

View File

@ -18,315 +18,317 @@
#define Data_ODBC_Extractor_INCLUDED
#include "Poco/Data/Constants.h"
#include "Poco/Data/ODBC/ODBC.h"
#include <map>
#include "Poco/Any.h"
#include "Poco/Data/AbstractExtractor.h"
#include "Poco/Data/ODBC/Preparator.h"
#include "Poco/Data/ODBC/ODBCMetaColumn.h"
#include "Poco/Data/ODBC/Error.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/Constants.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/ODBC/Error.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/ODBCMetaColumn.h"
#include "Poco/Data/ODBC/Preparator.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/Time.h"
#include "Poco/DateTime.h"
#include "Poco/Any.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/Exception.h"
#include "Poco/Nullable.h"
#include "Poco/UTFString.h"
#include "Poco/Exception.h"
#include <map>
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqltypes.h>
namespace Poco {
namespace Data {
namespace ODBC {
namespace Poco
{
namespace Data
{
namespace ODBC
{
class ODBC_API Extractor: public Poco::Data::AbstractExtractor
class ODBC_API Extractor : public Poco::Data::AbstractExtractor
/// Extracts and converts data values from the result row returned by ODBC.
/// If NULL is received, the incoming val value is not changed and false is returned
{
public:
{
public:
typedef Preparator::Ptr PreparatorPtr;
Extractor(const StatementHandle& rStmt,
Preparator::Ptr pPreparator);
Extractor(const StatementHandle & rStmt, Preparator::Ptr pPreparator);
/// Creates the Extractor.
~Extractor();
/// Destroys the Extractor.
bool extract(std::size_t pos, Poco::Int8& val);
bool extract(std::size_t pos, Poco::Int8 & val);
/// Extracts an Int8.
bool extract(std::size_t pos, std::vector<Poco::Int8>& val);
bool extract(std::size_t pos, std::vector<Poco::Int8> & val);
/// Extracts an Int8 vector.
bool extract(std::size_t pos, std::deque<Poco::Int8>& val);
bool extract(std::size_t pos, std::deque<Poco::Int8> & val);
/// Extracts an Int8 deque.
bool extract(std::size_t pos, std::list<Poco::Int8>& val);
bool extract(std::size_t pos, std::list<Poco::Int8> & val);
/// Extracts an Int8 list.
bool extract(std::size_t pos, Poco::UInt8& val);
bool extract(std::size_t pos, Poco::UInt8 & val);
/// Extracts an UInt8.
bool extract(std::size_t pos, std::vector<Poco::UInt8>& val);
bool extract(std::size_t pos, std::vector<Poco::UInt8> & val);
/// Extracts an UInt8 vector.
bool extract(std::size_t pos, std::deque<Poco::UInt8>& val);
bool extract(std::size_t pos, std::deque<Poco::UInt8> & val);
/// Extracts an UInt8 deque.
bool extract(std::size_t pos, std::list<Poco::UInt8>& val);
bool extract(std::size_t pos, std::list<Poco::UInt8> & val);
/// Extracts an UInt8 list.
bool extract(std::size_t pos, Poco::Int16& val);
bool extract(std::size_t pos, Poco::Int16 & val);
/// Extracts an Int16.
bool extract(std::size_t pos, std::vector<Poco::Int16>& val);
bool extract(std::size_t pos, std::vector<Poco::Int16> & val);
/// Extracts an Int16 vector.
bool extract(std::size_t pos, std::deque<Poco::Int16>& val);
bool extract(std::size_t pos, std::deque<Poco::Int16> & val);
/// Extracts an Int16 deque.
bool extract(std::size_t pos, std::list<Poco::Int16>& val);
bool extract(std::size_t pos, std::list<Poco::Int16> & val);
/// Extracts an Int16 list.
bool extract(std::size_t pos, Poco::UInt16& val);
bool extract(std::size_t pos, Poco::UInt16 & val);
/// Extracts an UInt16.
bool extract(std::size_t pos, std::vector<Poco::UInt16>& val);
bool extract(std::size_t pos, std::vector<Poco::UInt16> & val);
/// Extracts an UInt16 vector.
bool extract(std::size_t pos, std::deque<Poco::UInt16>& val);
bool extract(std::size_t pos, std::deque<Poco::UInt16> & val);
/// Extracts an UInt16 deque.
bool extract(std::size_t pos, std::list<Poco::UInt16>& val);
bool extract(std::size_t pos, std::list<Poco::UInt16> & val);
/// Extracts an UInt16 list.
bool extract(std::size_t pos, Poco::Int32& val);
bool extract(std::size_t pos, Poco::Int32 & val);
/// Extracts an Int32.
bool extract(std::size_t pos, std::vector<Poco::Int32>& val);
bool extract(std::size_t pos, std::vector<Poco::Int32> & val);
/// Extracts an Int32 vector.
bool extract(std::size_t pos, std::deque<Poco::Int32>& val);
bool extract(std::size_t pos, std::deque<Poco::Int32> & val);
/// Extracts an Int32 deque.
bool extract(std::size_t pos, std::list<Poco::Int32>& val);
bool extract(std::size_t pos, std::list<Poco::Int32> & val);
/// Extracts an Int32 list.
bool extract(std::size_t pos, Poco::UInt32& val);
bool extract(std::size_t pos, Poco::UInt32 & val);
/// Extracts an UInt32.
bool extract(std::size_t pos, std::vector<Poco::UInt32>& val);
bool extract(std::size_t pos, std::vector<Poco::UInt32> & val);
/// Extracts an UInt32 vector.
bool extract(std::size_t pos, std::deque<Poco::UInt32>& val);
bool extract(std::size_t pos, std::deque<Poco::UInt32> & val);
/// Extracts an UInt32 deque.
bool extract(std::size_t pos, std::list<Poco::UInt32>& val);
bool extract(std::size_t pos, std::list<Poco::UInt32> & val);
/// Extracts an UInt32 list.
bool extract(std::size_t pos, Poco::Int64& val);
bool extract(std::size_t pos, Poco::Int64 & val);
/// Extracts an Int64.
bool extract(std::size_t pos, std::vector<Poco::Int64>& val);
bool extract(std::size_t pos, std::vector<Poco::Int64> & val);
/// Extracts an Int64 vector.
bool extract(std::size_t pos, std::deque<Poco::Int64>& val);
bool extract(std::size_t pos, std::deque<Poco::Int64> & val);
/// Extracts an Int64 deque.
bool extract(std::size_t pos, std::list<Poco::Int64>& val);
bool extract(std::size_t pos, std::list<Poco::Int64> & val);
/// Extracts an Int64 list.
bool extract(std::size_t pos, Poco::UInt64& val);
bool extract(std::size_t pos, Poco::UInt64 & val);
/// Extracts an UInt64.
bool extract(std::size_t pos, std::vector<Poco::UInt64>& val);
bool extract(std::size_t pos, std::vector<Poco::UInt64> & val);
/// Extracts an UInt64 vector.
bool extract(std::size_t pos, std::deque<Poco::UInt64>& val);
bool extract(std::size_t pos, std::deque<Poco::UInt64> & val);
/// Extracts an UInt64 deque.
bool extract(std::size_t pos, std::list<Poco::UInt64>& val);
bool extract(std::size_t pos, std::list<Poco::UInt64> & val);
/// Extracts an UInt64 list.
#ifndef POCO_LONG_IS_64_BIT
bool extract(std::size_t pos, long& val);
bool extract(std::size_t pos, long & val);
/// Extracts a long.
bool extract(std::size_t pos, unsigned long& val);
bool extract(std::size_t pos, unsigned long & val);
/// Extracts an unsigned long.
bool extract(std::size_t pos, std::vector<long>& val);
bool extract(std::size_t pos, std::vector<long> & val);
/// Extracts a long vector.
bool extract(std::size_t pos, std::deque<long>& val);
bool extract(std::size_t pos, std::deque<long> & val);
/// Extracts a long deque.
bool extract(std::size_t pos, std::list<long>& val);
bool extract(std::size_t pos, std::list<long> & val);
/// Extracts a long list.
#endif
bool extract(std::size_t pos, bool& val);
bool extract(std::size_t pos, bool & val);
/// Extracts a boolean.
bool extract(std::size_t pos, std::vector<bool>& val);
bool extract(std::size_t pos, std::vector<bool> & val);
/// Extracts a boolean vector.
bool extract(std::size_t pos, std::deque<bool>& val);
bool extract(std::size_t pos, std::deque<bool> & val);
/// Extracts a boolean deque.
bool extract(std::size_t pos, std::list<bool>& val);
bool extract(std::size_t pos, std::list<bool> & val);
/// Extracts a boolean list.
bool extract(std::size_t pos, float& val);
bool extract(std::size_t pos, float & val);
/// Extracts a float.
bool extract(std::size_t pos, std::vector<float>& val);
bool extract(std::size_t pos, std::vector<float> & val);
/// Extracts a float vector.
bool extract(std::size_t pos, std::deque<float>& val);
bool extract(std::size_t pos, std::deque<float> & val);
/// Extracts a float deque.
bool extract(std::size_t pos, std::list<float>& val);
bool extract(std::size_t pos, std::list<float> & val);
/// Extracts a float list.
bool extract(std::size_t pos, double& val);
bool extract(std::size_t pos, double & val);
/// Extracts a double.
bool extract(std::size_t pos, std::vector<double>& val);
bool extract(std::size_t pos, std::vector<double> & val);
/// Extracts a double vector.
bool extract(std::size_t pos, std::deque<double>& val);
bool extract(std::size_t pos, std::deque<double> & val);
/// Extracts a double deque.
bool extract(std::size_t pos, std::list<double>& val);
bool extract(std::size_t pos, std::list<double> & val);
/// Extracts a double list.
bool extract(std::size_t pos, char& val);
bool extract(std::size_t pos, char & val);
/// Extracts a single character.
bool extract(std::size_t pos, std::vector<char>& val);
bool extract(std::size_t pos, std::vector<char> & val);
/// Extracts a single character vector.
bool extract(std::size_t pos, std::deque<char>& val);
bool extract(std::size_t pos, std::deque<char> & val);
/// Extracts a single character deque.
bool extract(std::size_t pos, std::list<char>& val);
bool extract(std::size_t pos, std::list<char> & val);
/// Extracts a single character list.
bool extract(std::size_t pos, std::string& val);
bool extract(std::size_t pos, std::string & val);
/// Extracts a string.
bool extract(std::size_t pos, std::vector<std::string>& val);
bool extract(std::size_t pos, std::vector<std::string> & val);
/// Extracts a string vector.
bool extract(std::size_t pos, std::deque<std::string>& val);
bool extract(std::size_t pos, std::deque<std::string> & val);
/// Extracts a string deque.
bool extract(std::size_t pos, std::list<std::string>& val);
bool extract(std::size_t pos, std::list<std::string> & val);
/// Extracts a string list.
/// Extracts a single character list.
bool extract(std::size_t pos, UTF16String& val);
bool extract(std::size_t pos, UTF16String & val);
/// Extracts a string.
bool extract(std::size_t pos, std::vector<UTF16String>& val);
bool extract(std::size_t pos, std::vector<UTF16String> & val);
/// Extracts a string vector.
bool extract(std::size_t pos, std::deque<UTF16String>& val);
bool extract(std::size_t pos, std::deque<UTF16String> & val);
/// Extracts a string deque.
bool extract(std::size_t pos, std::list<UTF16String>& val);
bool extract(std::size_t pos, std::list<UTF16String> & val);
/// Extracts a string list.
bool extract(std::size_t pos, Poco::Data::BLOB& val);
bool extract(std::size_t pos, Poco::Data::BLOB & val);
/// Extracts a BLOB.
bool extract(std::size_t pos, Poco::Data::CLOB& val);
bool extract(std::size_t pos, Poco::Data::CLOB & val);
/// Extracts a CLOB.
bool extract(std::size_t pos, std::vector<Poco::Data::BLOB>& val);
bool extract(std::size_t pos, std::vector<Poco::Data::BLOB> & val);
/// Extracts a BLOB vector.
bool extract(std::size_t pos, std::deque<Poco::Data::BLOB>& val);
bool extract(std::size_t pos, std::deque<Poco::Data::BLOB> & val);
/// Extracts a BLOB deque.
bool extract(std::size_t pos, std::list<Poco::Data::BLOB>& val);
bool extract(std::size_t pos, std::list<Poco::Data::BLOB> & val);
/// Extracts a BLOB list.
bool extract(std::size_t pos, std::vector<Poco::Data::CLOB>& val);
bool extract(std::size_t pos, std::vector<Poco::Data::CLOB> & val);
/// Extracts a CLOB vector.
bool extract(std::size_t pos, std::deque<Poco::Data::CLOB>& val);
bool extract(std::size_t pos, std::deque<Poco::Data::CLOB> & val);
/// Extracts a CLOB deque.
bool extract(std::size_t pos, std::list<Poco::Data::CLOB>& val);
bool extract(std::size_t pos, std::list<Poco::Data::CLOB> & val);
/// Extracts a CLOB list.
bool extract(std::size_t pos, Poco::Data::Date& val);
bool extract(std::size_t pos, Poco::Data::Date & val);
/// Extracts a Date.
bool extract(std::size_t pos, std::vector<Poco::Data::Date>& val);
bool extract(std::size_t pos, std::vector<Poco::Data::Date> & val);
/// Extracts a Date vector.
bool extract(std::size_t pos, std::deque<Poco::Data::Date>& val);
bool extract(std::size_t pos, std::deque<Poco::Data::Date> & val);
/// Extracts a Date deque.
bool extract(std::size_t pos, std::list<Poco::Data::Date>& val);
bool extract(std::size_t pos, std::list<Poco::Data::Date> & val);
/// Extracts a Date list.
bool extract(std::size_t pos, Poco::Data::Time& val);
bool extract(std::size_t pos, Poco::Data::Time & val);
/// Extracts a Time.
bool extract(std::size_t pos, std::vector<Poco::Data::Time>& val);
bool extract(std::size_t pos, std::vector<Poco::Data::Time> & val);
/// Extracts a Time vector.
bool extract(std::size_t pos, std::deque<Poco::Data::Time>& val);
bool extract(std::size_t pos, std::deque<Poco::Data::Time> & val);
/// Extracts a Time deque.
bool extract(std::size_t pos, std::list<Poco::Data::Time>& val);
bool extract(std::size_t pos, std::list<Poco::Data::Time> & val);
/// Extracts a Time list.
bool extract(std::size_t pos, Poco::DateTime& val);
bool extract(std::size_t pos, Poco::DateTime & val);
/// Extracts a DateTime.
bool extract(std::size_t pos, std::vector<Poco::DateTime>& val);
bool extract(std::size_t pos, std::vector<Poco::DateTime> & val);
/// Extracts a DateTime vector.
bool extract(std::size_t pos, std::deque<Poco::DateTime>& val);
bool extract(std::size_t pos, std::deque<Poco::DateTime> & val);
/// Extracts a DateTime deque.
bool extract(std::size_t pos, std::list<Poco::DateTime>& val);
bool extract(std::size_t pos, std::list<Poco::DateTime> & val);
/// Extracts a DateTime list.
bool extract(std::size_t pos, Poco::Any& val);
bool extract(std::size_t pos, Poco::Any & val);
/// Extracts an Any.
bool extract(std::size_t pos, std::vector<Poco::Any>& val);
bool extract(std::size_t pos, std::vector<Poco::Any> & val);
/// Extracts an Any vector.
bool extract(std::size_t pos, std::deque<Poco::Any>& val);
bool extract(std::size_t pos, std::deque<Poco::Any> & val);
/// Extracts an Any deque.
bool extract(std::size_t pos, std::list<Poco::Any>& val);
bool extract(std::size_t pos, std::list<Poco::Any> & val);
/// Extracts an Any list.
bool extract(std::size_t pos, Poco::DynamicAny& val);
bool extract(std::size_t pos, Poco::DynamicAny & val);
/// Extracts a DynamicAny.
bool extract(std::size_t pos, std::vector<Poco::DynamicAny>& val);
bool extract(std::size_t pos, std::vector<Poco::DynamicAny> & val);
/// Extracts a DynamicAny vector.
bool extract(std::size_t pos, std::deque<Poco::DynamicAny>& val);
bool extract(std::size_t pos, std::deque<Poco::DynamicAny> & val);
/// Extracts a DynamicAny deque.
bool extract(std::size_t pos, std::list<Poco::DynamicAny>& val);
bool extract(std::size_t pos, std::list<Poco::DynamicAny> & val);
/// Extracts a DynamicAny list.
void setDataExtraction(Preparator::DataExtraction ext);
@ -341,7 +343,7 @@ public:
void reset();
/// Resets the internally cached length indicators.
private:
private:
static const int CHUNK_SIZE = 1024;
/// Amount of data retrieved in one SQLGetData() request when doing manual extract.
@ -360,51 +362,52 @@ private:
/// Resizes the vector holding extracted data lengths to the
/// appropriate size.
template<typename T>
bool extractBoundImpl(std::size_t pos, T& val)
template <typename T>
bool extractBoundImpl(std::size_t pos, T & val)
{
if (isNull(pos)) return false;
poco_assert_dbg (typeid(T) == _pPreparator->at(pos).type());
if (isNull(pos))
return false;
poco_assert_dbg(typeid(T) == _pPreparator->at(pos).type());
val = *AnyCast<T>(&_pPreparator->at(pos));
return true;
}
bool extractBoundImpl(std::size_t pos, Poco::Data::BLOB& val);
bool extractBoundImpl(std::size_t pos, Poco::Data::CLOB& val);
bool extractBoundImpl(std::size_t pos, Poco::Data::BLOB & val);
bool extractBoundImpl(std::size_t pos, Poco::Data::CLOB & val);
template <typename C>
bool extractBoundImplContainer(std::size_t pos, C& val)
bool extractBoundImplContainer(std::size_t pos, C & val)
{
typedef typename C::value_type Type;
poco_assert_dbg (typeid(std::vector<Type>) == _pPreparator->at(pos).type());
std::vector<Type>& v = RefAnyCast<std::vector<Type> >(_pPreparator->at(pos));
poco_assert_dbg(typeid(std::vector<Type>) == _pPreparator->at(pos).type());
std::vector<Type> & v = RefAnyCast<std::vector<Type>>(_pPreparator->at(pos));
val.assign(v.begin(), v.end());
return true;
}
bool extractBoundImplContainer(std::size_t pos, std::vector<std::string>& values);
bool extractBoundImplContainer(std::size_t pos, std::deque<std::string>& values);
bool extractBoundImplContainer(std::size_t pos, std::list<std::string>& values);
bool extractBoundImplContainer(std::size_t pos, std::vector<Poco::UTF16String>& values);
bool extractBoundImplContainer(std::size_t pos, std::deque<Poco::UTF16String>& values);
bool extractBoundImplContainer(std::size_t pos, std::list<Poco::UTF16String>& values);
bool extractBoundImplContainer(std::size_t pos, std::vector<Poco::Data::CLOB>& values);
bool extractBoundImplContainer(std::size_t pos, std::deque<Poco::Data::CLOB>& values);
bool extractBoundImplContainer(std::size_t pos, std::list<Poco::Data::CLOB>& values);
bool extractBoundImplContainer(std::size_t pos, std::vector<Poco::Data::BLOB>& values);
bool extractBoundImplContainer(std::size_t pos, std::deque<Poco::Data::BLOB>& values);
bool extractBoundImplContainer(std::size_t pos, std::list<Poco::Data::BLOB>& values);
bool extractBoundImplContainer(std::size_t pos, std::vector<std::string> & values);
bool extractBoundImplContainer(std::size_t pos, std::deque<std::string> & values);
bool extractBoundImplContainer(std::size_t pos, std::list<std::string> & values);
bool extractBoundImplContainer(std::size_t pos, std::vector<Poco::UTF16String> & values);
bool extractBoundImplContainer(std::size_t pos, std::deque<Poco::UTF16String> & values);
bool extractBoundImplContainer(std::size_t pos, std::list<Poco::UTF16String> & values);
bool extractBoundImplContainer(std::size_t pos, std::vector<Poco::Data::CLOB> & values);
bool extractBoundImplContainer(std::size_t pos, std::deque<Poco::Data::CLOB> & values);
bool extractBoundImplContainer(std::size_t pos, std::list<Poco::Data::CLOB> & values);
bool extractBoundImplContainer(std::size_t pos, std::vector<Poco::Data::BLOB> & values);
bool extractBoundImplContainer(std::size_t pos, std::deque<Poco::Data::BLOB> & values);
bool extractBoundImplContainer(std::size_t pos, std::list<Poco::Data::BLOB> & values);
template <typename C>
bool extractBoundImplContainerString(std::size_t pos, C& values)
bool extractBoundImplContainerString(std::size_t pos, C & values)
{
typedef typename C::value_type StringType;
typedef typename C::iterator ItType;
typedef typename StringType::value_type CharType;
CharType** pc = AnyCast<CharType*>(&(_pPreparator->at(pos)));
poco_assert_dbg (pc);
poco_assert_dbg (_pPreparator->bulkSize() == values.size());
CharType ** pc = AnyCast<CharType *>(&(_pPreparator->at(pos)));
poco_assert_dbg(pc);
poco_assert_dbg(_pPreparator->bulkSize() == values.size());
std::size_t colWidth = columnSize(pos);
ItType it = values.begin();
ItType end = values.end();
@ -417,25 +420,28 @@ private:
typename StringType::reverse_iterator sEnd = it->rend();
for (; sIt != sEnd; ++sIt)
{
if (*sIt == '\0') ++trimLen;
else break;
if (*sIt == '\0')
++trimLen;
else
break;
}
if (trimLen) it->assign(it->begin(), it->begin() + it->length() - trimLen);
if (trimLen)
it->assign(it->begin(), it->begin() + it->length() - trimLen);
}
return true;
}
template <typename C>
bool extractBoundImplContainerLOB(std::size_t pos, C& values)
bool extractBoundImplContainerLOB(std::size_t pos, C & values)
{
typedef typename C::value_type LOBType;
typedef typename LOBType::ValueType CharType;
typedef typename C::iterator ItType;
CharType** pc = AnyCast<CharType*>(&(_pPreparator->at(pos)));
poco_assert_dbg (pc);
poco_assert_dbg (_pPreparator->bulkSize() == values.size());
CharType ** pc = AnyCast<CharType *>(&(_pPreparator->at(pos)));
poco_assert_dbg(pc);
poco_assert_dbg(_pPreparator->bulkSize() == values.size());
std::size_t colWidth = _pPreparator->maxDataSize(pos);
ItType it = values.begin();
ItType end = values.end();
@ -445,29 +451,31 @@ private:
return true;
}
template<typename T>
bool extractBoundImplLOB(std::size_t pos, Poco::Data::LOB<T>& val)
template <typename T>
bool extractBoundImplLOB(std::size_t pos, Poco::Data::LOB<T> & val)
{
if (isNull(pos)) return false;
if (isNull(pos))
return false;
std::size_t dataSize = _pPreparator->actualDataSize(pos);
checkDataSize(dataSize);
T* sp = AnyCast<T*>(_pPreparator->at(pos));
T * sp = AnyCast<T *>(_pPreparator->at(pos));
val.assignRaw(sp, dataSize);
return true;
}
template<typename T>
bool extractManualImpl(std::size_t pos, T& val, SQLSMALLINT cType)
template <typename T>
bool extractManualImpl(std::size_t pos, T & val, SQLSMALLINT cType)
{
SQLRETURN rc = 0;
T value = (T) 0;
T value = (T)0;
resizeLengths(pos);
rc = SQLGetData(_rStmt,
(SQLUSMALLINT) pos + 1,
rc = SQLGetData(
_rStmt,
(SQLUSMALLINT)pos + 1,
cType, //C data type
&value, //returned value
0, //buffer length (ignored)
@ -482,7 +490,7 @@ private:
{
//for fixed-length data, buffer must be large enough
//otherwise, driver may write past the end
poco_assert_dbg (_lengths[pos] <= sizeof(T));
poco_assert_dbg(_lengths[pos] <= sizeof(T));
val = value;
}
@ -490,7 +498,7 @@ private:
}
template <typename T, typename NT>
bool extAny(std::size_t pos, T& val)
bool extAny(std::size_t pos, T & val)
{
NT i;
if (extract(pos, i))
@ -506,66 +514,84 @@ private:
}
template <typename T>
bool extractImpl(std::size_t pos, T& val)
bool extractImpl(std::size_t pos, T & val)
/// Utility function for extraction of Any and DynamicAny.
{
ODBCMetaColumn column(_rStmt, pos);
switch (column.type())
{
case MetaColumn::FDT_INT8:
{ return extAny<T, Poco::Int8>(pos, val); }
case MetaColumn::FDT_INT8: {
return extAny<T, Poco::Int8>(pos, val);
}
case MetaColumn::FDT_UINT8:
{ return extAny<T, Poco::UInt8>(pos, val); }
case MetaColumn::FDT_UINT8: {
return extAny<T, Poco::UInt8>(pos, val);
}
case MetaColumn::FDT_INT16:
{ return extAny<T, Poco::Int16>(pos, val); }
case MetaColumn::FDT_INT16: {
return extAny<T, Poco::Int16>(pos, val);
}
case MetaColumn::FDT_UINT16:
{ return extAny<T, Poco::UInt16>(pos, val); }
case MetaColumn::FDT_UINT16: {
return extAny<T, Poco::UInt16>(pos, val);
}
case MetaColumn::FDT_INT32:
{ return extAny<T, Poco::Int32>(pos, val); }
case MetaColumn::FDT_INT32: {
return extAny<T, Poco::Int32>(pos, val);
}
case MetaColumn::FDT_UINT32:
{ return extAny<T, Poco::UInt32>(pos, val); }
case MetaColumn::FDT_UINT32: {
return extAny<T, Poco::UInt32>(pos, val);
}
case MetaColumn::FDT_INT64:
{ return extAny<T, Poco::Int64>(pos, val); }
case MetaColumn::FDT_INT64: {
return extAny<T, Poco::Int64>(pos, val);
}
case MetaColumn::FDT_UINT64:
{ return extAny<T, Poco::UInt64>(pos, val); }
case MetaColumn::FDT_UINT64: {
return extAny<T, Poco::UInt64>(pos, val);
}
case MetaColumn::FDT_BOOL:
{ return extAny<T, bool>(pos, val); }
case MetaColumn::FDT_BOOL: {
return extAny<T, bool>(pos, val);
}
case MetaColumn::FDT_FLOAT:
{ return extAny<T, float>(pos, val); }
case MetaColumn::FDT_FLOAT: {
return extAny<T, float>(pos, val);
}
case MetaColumn::FDT_DOUBLE:
{ return extAny<T, double>(pos, val); }
case MetaColumn::FDT_DOUBLE: {
return extAny<T, double>(pos, val);
}
case MetaColumn::FDT_STRING:
{ return extAny<T, std::string>(pos, val); }
case MetaColumn::FDT_STRING: {
return extAny<T, std::string>(pos, val);
}
case MetaColumn::FDT_WSTRING:
{ return extAny<T, Poco::UTF16String>(pos, val); }
case MetaColumn::FDT_WSTRING: {
return extAny<T, Poco::UTF16String>(pos, val);
}
case MetaColumn::FDT_BLOB:
{ return extAny<T, Poco::Data::BLOB>(pos, val); }
case MetaColumn::FDT_BLOB: {
return extAny<T, Poco::Data::BLOB>(pos, val);
}
case MetaColumn::FDT_CLOB:
{ return extAny<T, Poco::Data::CLOB>(pos, val); }
case MetaColumn::FDT_CLOB: {
return extAny<T, Poco::Data::CLOB>(pos, val);
}
case MetaColumn::FDT_DATE:
{ return extAny<T, Poco::Data::Date>(pos, val); }
case MetaColumn::FDT_DATE: {
return extAny<T, Poco::Data::Date>(pos, val);
}
case MetaColumn::FDT_TIME:
{ return extAny<T, Poco::Data::Time>(pos, val); }
case MetaColumn::FDT_TIME: {
return extAny<T, Poco::Data::Time>(pos, val);
}
case MetaColumn::FDT_TIMESTAMP:
{ return extAny<T, Poco::DateTime>(pos, val); }
case MetaColumn::FDT_TIMESTAMP: {
return extAny<T, Poco::DateTime>(pos, val);
}
default:
throw DataFormatException("Unsupported data type.");
@ -581,148 +607,145 @@ private:
SQLINTEGER columnSize(std::size_t pos) const;
const StatementHandle& _rStmt;
const StatementHandle & _rStmt;
PreparatorPtr _pPreparator;
Preparator::DataExtraction _dataExtraction;
std::vector<SQLLEN> _lengths;
};
};
///
/// inlines
///
///
/// inlines
///
inline bool Extractor::extractBoundImpl(std::size_t pos, Poco::Data::BLOB& val)
{
inline bool Extractor::extractBoundImpl(std::size_t pos, Poco::Data::BLOB & val)
{
return extractBoundImplLOB<BLOB::ValueType>(pos, val);
}
}
inline bool Extractor::extractBoundImpl(std::size_t pos, Poco::Data::CLOB& val)
{
inline bool Extractor::extractBoundImpl(std::size_t pos, Poco::Data::CLOB & val)
{
return extractBoundImplLOB<CLOB::ValueType>(pos, val);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::vector<std::string>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::vector<std::string> & values)
{
return extractBoundImplContainerString(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::deque<std::string>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::deque<std::string> & values)
{
return extractBoundImplContainerString(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::list<std::string>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::list<std::string> & values)
{
return extractBoundImplContainerString(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::vector<Poco::UTF16String>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::vector<Poco::UTF16String> & values)
{
return extractBoundImplContainerString(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::deque<Poco::UTF16String>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::deque<Poco::UTF16String> & values)
{
return extractBoundImplContainerString(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::list<Poco::UTF16String>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::list<Poco::UTF16String> & values)
{
return extractBoundImplContainerString(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::vector<Poco::Data::CLOB>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::vector<Poco::Data::CLOB> & values)
{
return extractBoundImplContainerLOB(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::deque<Poco::Data::CLOB>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::deque<Poco::Data::CLOB> & values)
{
return extractBoundImplContainerLOB(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::list<Poco::Data::CLOB>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::list<Poco::Data::CLOB> & values)
{
return extractBoundImplContainerLOB(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::vector<Poco::Data::BLOB>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::vector<Poco::Data::BLOB> & values)
{
return extractBoundImplContainerLOB(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::deque<Poco::Data::BLOB>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::deque<Poco::Data::BLOB> & values)
{
return extractBoundImplContainerLOB(pos, values);
}
}
inline bool Extractor::extractBoundImplContainer(std::size_t pos,
std::list<Poco::Data::BLOB>& values)
{
inline bool Extractor::extractBoundImplContainer(std::size_t pos, std::list<Poco::Data::BLOB> & values)
{
return extractBoundImplContainerLOB(pos, values);
}
}
inline void Extractor::setDataExtraction(Preparator::DataExtraction ext)
{
inline void Extractor::setDataExtraction(Preparator::DataExtraction ext)
{
_pPreparator->setDataExtraction(_dataExtraction = ext);
}
}
inline Preparator::DataExtraction Extractor::getDataExtraction() const
{
inline Preparator::DataExtraction Extractor::getDataExtraction() const
{
return _dataExtraction;
}
}
inline void Extractor::reset()
{
inline void Extractor::reset()
{
_lengths.clear();
}
}
inline void Extractor::resizeLengths(std::size_t pos)
{
inline void Extractor::resizeLengths(std::size_t pos)
{
if (pos >= _lengths.size())
_lengths.resize(pos + 1, (SQLLEN) 0);
}
_lengths.resize(pos + 1, (SQLLEN)0);
}
inline bool Extractor::isNullLengthIndicator(SQLLEN val) const
{
return SQL_NULL_DATA == (int) val;
}
inline bool Extractor::isNullLengthIndicator(SQLLEN val) const
{
return SQL_NULL_DATA == (int)val;
}
inline SQLINTEGER Extractor::columnSize(std::size_t pos) const
{
inline SQLINTEGER Extractor::columnSize(std::size_t pos) const
{
std::size_t size = ODBCMetaColumn(_rStmt, pos).length();
std::size_t maxSize = _pPreparator->maxDataSize(pos);
if (size > maxSize) size = maxSize;
return (SQLINTEGER) size;
if (size > maxSize)
size = maxSize;
return (SQLINTEGER)size;
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif // Data_ODBC_Extractor_INCLUDED

View File

@ -18,35 +18,34 @@
#define Data_ODBC_Handle_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/EnvironmentHandle.h"
#include "Poco/Data/ODBC/ConnectionHandle.h"
#include "Poco/Data/ODBC/EnvironmentHandle.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/ODBC/Utility.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqltypes.h>
namespace Poco {
namespace Data {
namespace ODBC {
template <typename H, SQLSMALLINT handleType>
class Handle
/// ODBC handle class template
namespace Poco
{
public:
Handle(const ConnectionHandle& rConnection):
_rConnection(rConnection),
_handle(0)
namespace Data
{
namespace ODBC
{
template <typename H, SQLSMALLINT handleType>
class Handle
/// ODBC handle class template
{
public:
Handle(const ConnectionHandle & rConnection) : _rConnection(rConnection), _handle(0)
/// Creates the Handle.
{
if (Utility::isError(SQLAllocHandle(handleType,
_rConnection,
&_handle)))
if (Utility::isError(SQLAllocHandle(handleType, _rConnection, &_handle)))
{
throw ODBCException("Could not allocate statement handle.");
}
@ -60,7 +59,7 @@ public:
SQLRETURN rc = SQLFreeHandle(handleType, _handle);
// N.B. Destructors should not throw, but neither do we want to
// leak resources. So, we throw here in debug mode if things go bad.
poco_assert_dbg (!Utility::isError(rc));
poco_assert_dbg(!Utility::isError(rc));
}
catch (...)
{
@ -68,46 +67,48 @@ public:
}
}
operator const H& () const
operator const H &() const
/// Const conversion operator into reference to native type.
{
return handle();
}
const H& handle() const
const H & handle() const
/// Returns const reference to native type.
{
return _handle;
}
private:
Handle(const Handle&);
const Handle& operator=(const Handle&);
private:
Handle(const Handle &);
const Handle & operator=(const Handle &);
operator H& ()
operator H &()
/// Conversion operator into reference to native type.
{
return handle();
}
H& handle()
H & handle()
/// Returns reference to native type.
{
return _handle;
}
const ConnectionHandle& _rConnection;
const ConnectionHandle & _rConnection;
H _handle;
friend class ODBCStatementImpl;
};
};
typedef Handle<SQLHSTMT, SQL_HANDLE_STMT> StatementHandle;
typedef Handle<SQLHDESC, SQL_HANDLE_DESC> DescriptorHandle;
typedef Handle<SQLHSTMT, SQL_HANDLE_STMT> StatementHandle;
typedef Handle<SQLHDESC, SQL_HANDLE_DESC> DescriptorHandle;
} } } // namespace Poco::Data::ODBC
}
}
} // namespace Poco::Data::ODBC
#endif

View File

@ -22,7 +22,7 @@
#include "Poco/Foundation.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
@ -35,24 +35,23 @@
// defined with this macro as being exported.
//
#if defined(_WIN32) && defined(POCO_DLL)
#if defined(ODBC_EXPORTS)
#define ODBC_API __declspec(dllexport)
#else
#define ODBC_API __declspec(dllimport)
#endif
# if defined(ODBC_EXPORTS)
# define ODBC_API __declspec(dllexport)
# else
# define ODBC_API __declspec(dllimport)
# endif
#endif
#if !defined(ODBC_API)
#if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4)
#define ODBC_API __attribute__ ((visibility ("default")))
#else
#define ODBC_API
#endif
# if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined(__GNUC__) && (__GNUC__ >= 4)
# define ODBC_API __attribute__((visibility("default")))
# else
# define ODBC_API
# endif
#endif
#include "Poco/Data/ODBC/Unicode.h"
@ -60,9 +59,9 @@
// Automatically link Data library.
//
#if defined(_MSC_VER)
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(ODBC_EXPORTS)
#pragma comment(lib, "PocoDataODBC" POCO_LIB_SUFFIX)
#endif
# if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(ODBC_EXPORTS)
# pragma comment(lib, "PocoDataODBC" POCO_LIB_SUFFIX)
# endif
#endif

View File

@ -18,60 +18,56 @@
#define Data_ODBC_ODBCException_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/ODBC/Diagnostics.h"
#include "Poco/Data/ODBC/Error.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Utility.h"
#include "Poco/Format.h"
namespace Poco {
namespace Data {
namespace ODBC {
POCO_DECLARE_EXCEPTION(ODBC_API, ODBCException, Poco::Data::DataException)
POCO_DECLARE_EXCEPTION(ODBC_API, InsufficientStorageException, ODBCException)
POCO_DECLARE_EXCEPTION(ODBC_API, UnknownDataLengthException, ODBCException)
POCO_DECLARE_EXCEPTION(ODBC_API, DataTruncatedException, ODBCException)
template <class H, SQLSMALLINT handleType>
class HandleException: public ODBCException
namespace Poco
{
public:
HandleException(const H& handle): _error(handle)
namespace Data
{
namespace ODBC
{
POCO_DECLARE_EXCEPTION(ODBC_API, ODBCException, Poco::Data::DataException)
POCO_DECLARE_EXCEPTION(ODBC_API, InsufficientStorageException, ODBCException)
POCO_DECLARE_EXCEPTION(ODBC_API, UnknownDataLengthException, ODBCException)
POCO_DECLARE_EXCEPTION(ODBC_API, DataTruncatedException, ODBCException)
template <class H, SQLSMALLINT handleType>
class HandleException : public ODBCException
{
public:
HandleException(const H & handle) : _error(handle)
/// Creates HandleException
{
message(_error.toString());
}
HandleException(const H& handle, const std::string& msg):
ODBCException(msg),
_error(handle)
HandleException(const H & handle, const std::string & msg) : ODBCException(msg), _error(handle)
/// Creates HandleException
{
extendedMessage(_error.toString());
}
HandleException(const H& handle, const std::string& msg, const std::string& arg):
ODBCException(msg, arg),
_error(handle)
HandleException(const H & handle, const std::string & msg, const std::string & arg) : ODBCException(msg, arg), _error(handle)
/// Creates HandleException
{
}
HandleException(const H& handle, const std::string& msg, const Poco::Exception& exc):
ODBCException(msg, exc),
_error(handle)
HandleException(const H & handle, const std::string & msg, const Poco::Exception & exc)
: ODBCException(msg, exc), _error(handle)
/// Creates HandleException
{
}
HandleException(const HandleException& exc):
ODBCException(exc),
_error(exc._error)
HandleException(const HandleException & exc) : ODBCException(exc), _error(exc._error)
/// Creates HandleException
{
}
@ -81,27 +77,28 @@ public:
{
}
HandleException& operator = (const HandleException& exc)
HandleException & operator=(const HandleException & exc)
/// Assignment operator
{
if (&exc != this) _error = exc._error;
if (&exc != this)
_error = exc._error;
return *this;
}
const char* name() const throw()
const char * name() const throw()
/// Returns the name of the exception
{
return "ODBC handle exception";
}
const char* className() const throw()
const char * className() const throw()
/// Returns the HandleException class name.
{
return typeid(*this).name();
}
Poco::Exception* clone() const
Poco::Exception * clone() const
/// Clones the HandleException
{
return new HandleException(*this);
@ -113,7 +110,7 @@ public:
throw *this;
}
const Diagnostics<H, handleType>& diagnostics() const
const Diagnostics<H, handleType> & diagnostics() const
/// Returns error diagnostics.
{
return _error.diagnostics();
@ -122,29 +119,29 @@ public:
std::string toString() const
/// Returns the formatted error diagnostics for the handle.
{
return Poco::format("ODBC Error: %s\n===================\n%s\n",
std::string(what()),
_error.toString());
return Poco::format("ODBC Error: %s\n===================\n%s\n", std::string(what()), _error.toString());
}
static std::string errorString(const H& handle)
static std::string errorString(const H & handle)
/// Returns the error diagnostics string for the handle.
{
return Error<H, handleType>(handle).toString();
}
private:
private:
Error<H, handleType> _error;
};
};
typedef HandleException<SQLHENV, SQL_HANDLE_ENV> EnvironmentException;
typedef HandleException<SQLHDBC, SQL_HANDLE_DBC> ConnectionException;
typedef HandleException<SQLHSTMT, SQL_HANDLE_STMT> StatementException;
typedef HandleException<SQLHDESC, SQL_HANDLE_DESC> DescriptorException;
typedef HandleException<SQLHENV, SQL_HANDLE_ENV> EnvironmentException;
typedef HandleException<SQLHDBC, SQL_HANDLE_DBC> ConnectionException;
typedef HandleException<SQLHSTMT, SQL_HANDLE_STMT> StatementException;
typedef HandleException<SQLHDESC, SQL_HANDLE_DESC> DescriptorException;
} } } // namespace Poco::Data::ODBC
}
}
} // namespace Poco::Data::ODBC
#endif

View File

@ -18,26 +18,29 @@
#define Data_ODBC_ODBCColumn_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/MetaColumn.h"
#include "Poco/Data/ODBC/Error.h"
#include "Poco/Data/ODBC/Handle.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/MetaColumn.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqlext.h>
namespace Poco {
namespace Data {
namespace ODBC {
class ODBC_API ODBCMetaColumn: public MetaColumn
namespace Poco
{
public:
explicit ODBCMetaColumn(const StatementHandle& rStmt, std::size_t position);
namespace Data
{
namespace ODBC
{
class ODBC_API ODBCMetaColumn : public MetaColumn
{
public:
explicit ODBCMetaColumn(const StatementHandle & rStmt, std::size_t position);
/// Creates the ODBCMetaColumn.
~ODBCMetaColumn();
@ -53,7 +56,7 @@ public:
bool isUnsigned() const;
/// Returns true if column is unsigned or a non-numeric data type.
private:
private:
ODBCMetaColumn();
static const int NAME_BUFFER_LENGTH = 2048;
@ -72,21 +75,23 @@ private:
void getDescription();
SQLLEN _dataLength;
const StatementHandle& _rStmt;
const StatementHandle & _rStmt;
ColumnDescription _columnDesc;
};
};
///
/// inlines
///
inline std::size_t ODBCMetaColumn::dataLength() const
{
///
/// inlines
///
inline std::size_t ODBCMetaColumn::dataLength() const
{
return _dataLength;
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif

View File

@ -18,39 +18,42 @@
#define Data_ODBC_ODBCStatementImpl_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/SessionImpl.h"
#include <sstream>
#include "Poco/Data/Column.h"
#include "Poco/Data/ODBC/Binder.h"
#include "Poco/Data/ODBC/Extractor.h"
#include "Poco/Data/ODBC/Preparator.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/ODBCMetaColumn.h"
#include "Poco/Data/ODBC/Preparator.h"
#include "Poco/Data/ODBC/SessionImpl.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/Column.h"
#include "Poco/SharedPtr.h"
#include "Poco/Format.h"
#include <sstream>
#include "Poco/SharedPtr.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqltypes.h>
namespace Poco {
namespace Data {
namespace ODBC {
class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl
/// Implements statement functionality needed for ODBC
namespace Poco
{
public:
ODBCStatementImpl(SessionImpl& rSession);
namespace Data
{
namespace ODBC
{
class ODBC_API ODBCStatementImpl : public Poco::Data::StatementImpl
/// Implements statement functionality needed for ODBC
{
public:
ODBCStatementImpl(SessionImpl & rSession);
/// Creates the ODBCStatementImpl.
~ODBCStatementImpl();
/// Destroys the ODBCStatementImpl.
protected:
protected:
std::size_t columnsReturned() const;
/// Returns number of columns returned by query.
@ -58,7 +61,7 @@ protected:
/// Returns the number of affected rows.
/// Used to find out the number of rows affected by insert or update.
const MetaColumn& metaColumn(std::size_t pos) const;
const MetaColumn & metaColumn(std::size_t pos) const;
/// Returns column meta data.
bool hasNext();
@ -91,7 +94,7 @@ protected:
std::string nativeSQL();
/// Returns the SQL string as modified by the driver.
private:
private:
typedef Poco::Data::AbstractBindingVec Bindings;
typedef Poco::SharedPtr<Binder> BinderPtr;
typedef Poco::Data::AbstractExtractionVec Extractions;
@ -99,7 +102,7 @@ private:
typedef std::vector<PreparatorPtr> PreparatorVec;
typedef Poco::SharedPtr<Extractor> ExtractorPtr;
typedef std::vector<ExtractorPtr> ExtractorVec;
typedef std::vector<ODBCMetaColumn*> ColumnPtrVec;
typedef std::vector<ODBCMetaColumn *> ColumnPtrVec;
typedef std::vector<ColumnPtrVec> ColumnPtrVecVec;
static const std::string INVALID_CURSOR_STATE;
@ -140,9 +143,9 @@ private:
void addPreparator();
void fillColumns();
void checkError(SQLRETURN rc, const std::string& msg="");
void checkError(SQLRETURN rc, const std::string & msg = "");
const SQLHDBC& _rConnection;
const SQLHDBC & _rConnection;
const StatementHandle _stmt;
PreparatorVec _preparations;
BinderPtr _pBinder;
@ -153,54 +156,56 @@ private:
bool _prepared;
mutable std::size_t _affectedRowCount;
bool _canCompile;
};
};
//
// inlines
//
inline AbstractExtraction::ExtractorPtr ODBCStatementImpl::extractor()
{
poco_assert_dbg (currentDataSet() < _extractors.size());
poco_assert_dbg (_extractors[currentDataSet()]);
//
// inlines
//
inline AbstractExtraction::ExtractorPtr ODBCStatementImpl::extractor()
{
poco_assert_dbg(currentDataSet() < _extractors.size());
poco_assert_dbg(_extractors[currentDataSet()]);
return _extractors[currentDataSet()];
}
}
inline AbstractBinding::BinderPtr ODBCStatementImpl::binder()
{
poco_assert_dbg (!_pBinder.isNull());
inline AbstractBinding::BinderPtr ODBCStatementImpl::binder()
{
poco_assert_dbg(!_pBinder.isNull());
return _pBinder;
}
}
inline std::size_t ODBCStatementImpl::columnsReturned() const
{
poco_assert_dbg (currentDataSet() < _preparations.size());
poco_assert_dbg (_preparations[currentDataSet()]);
inline std::size_t ODBCStatementImpl::columnsReturned() const
{
poco_assert_dbg(currentDataSet() < _preparations.size());
poco_assert_dbg(_preparations[currentDataSet()]);
return static_cast<std::size_t>(_preparations[currentDataSet()]->columns());
}
}
inline bool ODBCStatementImpl::hasData() const
{
inline bool ODBCStatementImpl::hasData() const
{
return (columnsReturned() > 0);
}
}
inline bool ODBCStatementImpl::nextRowReady() const
{
inline bool ODBCStatementImpl::nextRowReady() const
{
return (!Utility::isError(_nextResponse));
}
}
inline bool ODBCStatementImpl::canCompile() const
{
inline bool ODBCStatementImpl::canCompile() const
{
return _canCompile;
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif // Data_ODBC_ODBCStatementImpl_INCLUDED

View File

@ -18,23 +18,26 @@
#define Data_ODBC_Parameter_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Handle.h"
#include "Poco/Data/ODBC/ODBC.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqlext.h>
namespace Poco {
namespace Data {
namespace ODBC {
class ODBC_API Parameter
namespace Poco
{
public:
explicit Parameter(const StatementHandle& rStmt, std::size_t colNum);
namespace Data
{
namespace ODBC
{
class ODBC_API Parameter
{
public:
explicit Parameter(const StatementHandle & rStmt, std::size_t colNum);
/// Creates the Parameter.
~Parameter();
@ -57,7 +60,7 @@ public:
bool isNullable() const;
/// Returns true if column allows null values, false otherwise.
private:
private:
Parameter();
void init();
@ -67,45 +70,47 @@ private:
SQLSMALLINT _decimalDigits;
SQLSMALLINT _isNullable;
const StatementHandle& _rStmt;
const StatementHandle & _rStmt;
std::size_t _number;
};
};
///
/// inlines
///
inline std::size_t Parameter::number() const
{
///
/// inlines
///
inline std::size_t Parameter::number() const
{
return _number;
}
}
inline std::size_t Parameter::dataType() const
{
inline std::size_t Parameter::dataType() const
{
return _dataType;
}
}
inline std::size_t Parameter::columnSize() const
{
inline std::size_t Parameter::columnSize() const
{
return _columnSize;
}
}
inline std::size_t Parameter::decimalDigits() const
{
inline std::size_t Parameter::decimalDigits() const
{
return _decimalDigits;
}
}
inline bool Parameter::isNullable() const
{
inline bool Parameter::isNullable() const
{
return SQL_NULLABLE == _isNullable;
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif

File diff suppressed because it is too large Load Diff

View File

@ -18,30 +18,33 @@
#define Data_ODBC_SessionImpl_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/Connector.h"
#include "Poco/Data/ODBC/TypeInfo.h"
#include "Poco/Data/ODBC/Binder.h"
#include "Poco/Data/ODBC/Handle.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/AbstractSessionImpl.h"
#include "Poco/SharedPtr.h"
#include "Poco/Data/ODBC/Binder.h"
#include "Poco/Data/ODBC/Connector.h"
#include "Poco/Data/ODBC/Handle.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/ODBCException.h"
#include "Poco/Data/ODBC/TypeInfo.h"
#include "Poco/Mutex.h"
#include "Poco/SharedPtr.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqltypes.h>
namespace Poco {
namespace Data {
namespace ODBC {
class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl<SessionImpl>
/// Implements SessionImpl interface
namespace Poco
{
public:
namespace Data
{
namespace ODBC
{
class ODBC_API SessionImpl : public Poco::Data::AbstractSessionImpl<SessionImpl>
/// Implements SessionImpl interface
{
public:
static const std::size_t ODBC_MAX_FIELD_SIZE = 1024u;
enum TransactionCapability
@ -51,7 +54,8 @@ public:
ODBC_TXN_CAPABILITY_TRUE = 1
};
SessionImpl(const std::string& connect,
SessionImpl(
const std::string & connect,
std::size_t loginTimeout,
std::size_t maxFieldSize = ODBC_MAX_FIELD_SIZE,
bool autoBind = true,
@ -60,9 +64,10 @@ public:
/// Throws NotConnectedException if connection was not successful.
//@ deprecated
SessionImpl(const std::string& connect,
SessionImpl(
const std::string & connect,
Poco::Any maxFieldSize = ODBC_MAX_FIELD_SIZE,
bool enforceCapability=false,
bool enforceCapability = false,
bool autoBind = true,
bool autoExtract = true);
/// Creates the SessionImpl. Opens a connection to the database.
@ -70,10 +75,10 @@ public:
~SessionImpl();
/// Destroys the SessionImpl.
Poco::Data::StatementImpl* createStatementImpl();
Poco::Data::StatementImpl * createStatementImpl();
/// Returns an ODBC StatementImpl
void open(const std::string& connect = "");
void open(const std::string & connect = "");
/// Opens a connection to the Database
void close();
@ -100,7 +105,7 @@ public:
bool isTransaction();
/// Returns true iff a transaction is in progress.
const std::string& connectorName() const;
const std::string & connectorName() const;
/// Returns the name of the connector.
bool canTransact();
@ -120,38 +125,38 @@ public:
/// Returns true iff the transaction isolation level corresponds
/// to the supplied bitmask.
void autoCommit(const std::string&, bool val);
void autoCommit(const std::string &, bool val);
/// Sets autocommit property for the session.
bool isAutoCommit(const std::string& name="");
bool isAutoCommit(const std::string & name = "");
/// Returns autocommit property value.
void autoBind(const std::string&, bool val);
void autoBind(const std::string &, bool val);
/// Sets automatic binding for the session.
bool isAutoBind(const std::string& name="");
bool isAutoBind(const std::string & name = "");
/// Returns true if binding is automatic for this session.
void autoExtract(const std::string&, bool val);
void autoExtract(const std::string &, bool val);
/// Sets automatic extraction for the session.
bool isAutoExtract(const std::string& name="");
bool isAutoExtract(const std::string & name = "");
/// Returns true if extraction is automatic for this session.
void setMaxFieldSize(const std::string& rName, const Poco::Any& rValue);
void setMaxFieldSize(const std::string & rName, const Poco::Any & rValue);
/// Sets the max field size (the default used when column size is unknown).
Poco::Any getMaxFieldSize(const std::string& rName="");
Poco::Any getMaxFieldSize(const std::string & rName = "");
/// Returns the max field size (the default used when column size is unknown).
int maxStatementLength();
/// Returns maximum length of SQL statement allowed by driver.
void setQueryTimeout(const std::string&, const Poco::Any& value);
void setQueryTimeout(const std::string &, const Poco::Any & value);
/// Sets the timeout (in seconds) for queries.
/// Value must be of type int.
Poco::Any getQueryTimeout(const std::string&);
Poco::Any getQueryTimeout(const std::string &);
/// Returns the timeout (in seconds) for queries,
/// or -1 if no timeout has been set.
@ -159,19 +164,19 @@ public:
/// Returns the timeout (in seconds) for queries,
/// or -1 if no timeout has been set.
const ConnectionHandle& dbc() const;
const ConnectionHandle & dbc() const;
/// Returns the connection handle.
Poco::Any dataTypeInfo(const std::string& rName="");
Poco::Any dataTypeInfo(const std::string & rName = "");
/// Returns the data types information.
private:
void setDataTypeInfo(const std::string& rName, const Poco::Any& rValue);
private:
void setDataTypeInfo(const std::string & rName, const Poco::Any & rValue);
/// No-op. Throws InvalidAccessException.
static const int FUNCTIONS = SQL_API_ODBC3_ALL_FUNCTIONS_SIZE;
void checkError(SQLRETURN rc, const std::string& msg="");
void checkError(SQLRETURN rc, const std::string & msg = "");
Poco::UInt32 getDefaultTransactionIsolation();
@ -187,104 +192,106 @@ private:
bool _inTransaction;
int _queryTimeout;
Poco::FastMutex _mutex;
};
};
///
/// inlines
///
inline void SessionImpl::checkError(SQLRETURN rc, const std::string& msg)
{
///
/// inlines
///
inline void SessionImpl::checkError(SQLRETURN rc, const std::string & msg)
{
if (Utility::isError(rc))
throw ConnectionException(_db, msg);
}
}
inline const ConnectionHandle& SessionImpl::dbc() const
{
inline const ConnectionHandle & SessionImpl::dbc() const
{
return _db;
}
}
inline void SessionImpl::setMaxFieldSize(const std::string& rName, const Poco::Any& rValue)
{
inline void SessionImpl::setMaxFieldSize(const std::string & rName, const Poco::Any & rValue)
{
_maxFieldSize = rValue;
}
}
inline Poco::Any SessionImpl::getMaxFieldSize(const std::string& rName)
{
inline Poco::Any SessionImpl::getMaxFieldSize(const std::string & rName)
{
return _maxFieldSize;
}
}
inline void SessionImpl::setDataTypeInfo(const std::string& rName, const Poco::Any& rValue)
{
inline void SessionImpl::setDataTypeInfo(const std::string & rName, const Poco::Any & rValue)
{
throw InvalidAccessException();
}
}
inline Poco::Any SessionImpl::dataTypeInfo(const std::string& rName)
{
inline Poco::Any SessionImpl::dataTypeInfo(const std::string & rName)
{
return &_dataTypes;
}
}
inline void SessionImpl::autoBind(const std::string&, bool val)
{
inline void SessionImpl::autoBind(const std::string &, bool val)
{
_autoBind = val;
}
}
inline bool SessionImpl::isAutoBind(const std::string& name)
{
inline bool SessionImpl::isAutoBind(const std::string & name)
{
return _autoBind;
}
}
inline void SessionImpl::autoExtract(const std::string&, bool val)
{
inline void SessionImpl::autoExtract(const std::string &, bool val)
{
_autoExtract = val;
}
}
inline bool SessionImpl::isAutoExtract(const std::string& name)
{
inline bool SessionImpl::isAutoExtract(const std::string & name)
{
return _autoExtract;
}
}
inline const std::string& SessionImpl::connectorName() const
{
inline const std::string & SessionImpl::connectorName() const
{
return _connector;
}
}
inline bool SessionImpl::isTransactionIsolation(Poco::UInt32 ti)
{
inline bool SessionImpl::isTransactionIsolation(Poco::UInt32 ti)
{
return 0 != (ti & getTransactionIsolation());
}
}
inline void SessionImpl::setQueryTimeout(const std::string&, const Poco::Any& value)
{
inline void SessionImpl::setQueryTimeout(const std::string &, const Poco::Any & value)
{
_queryTimeout = Poco::AnyCast<int>(value);
}
}
inline Poco::Any SessionImpl::getQueryTimeout(const std::string&)
{
inline Poco::Any SessionImpl::getQueryTimeout(const std::string &)
{
return _queryTimeout;
}
}
inline int SessionImpl::queryTimeout() const
{
inline int SessionImpl::queryTimeout() const
{
return _queryTimeout;
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif // Data_ODBC_SessionImpl_INCLUDED

View File

@ -18,23 +18,26 @@
#define Data_ODBC_DataTypes_INCLUDED
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/NamedTuple.h"
#include "Poco/DynamicAny.h"
#include <vector>
#include <map>
#include <vector>
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/DynamicAny.h"
#include "Poco/NamedTuple.h"
#ifdef POCO_OS_FAMILY_WINDOWS
#include <windows.h>
# include <windows.h>
#endif
#include <sqlext.h>
namespace Poco {
namespace Data {
namespace ODBC {
namespace Poco
{
namespace Data
{
namespace ODBC
{
class ODBC_API TypeInfo
class ODBC_API TypeInfo
/// Datatypes mapping utility class.
///
/// This class provides mapping between C and SQL datatypes as well
@ -45,11 +48,12 @@ class ODBC_API TypeInfo
///
/// Class also provides a convenient debugging function that prints
/// tabulated data to an output stream.
{
public:
{
public:
typedef std::map<int, int> DataTypeMap;
typedef DataTypeMap::value_type ValueType;
typedef Poco::NamedTuple<std::string,
typedef Poco::NamedTuple<
std::string,
SQLSMALLINT,
SQLINTEGER,
std::string,
@ -67,10 +71,11 @@ public:
SQLSMALLINT,
SQLSMALLINT,
SQLINTEGER,
SQLSMALLINT> TypeInfoTup;
SQLSMALLINT>
TypeInfoTup;
typedef std::vector<TypeInfoTup> TypeInfoVec;
explicit TypeInfo(SQLHDBC* pHDBC=0);
explicit TypeInfo(SQLHDBC * pHDBC = 0);
/// Creates the TypeInfo.
~TypeInfo();
@ -85,33 +90,35 @@ public:
void fillTypeInfo(SQLHDBC pHDBC);
/// Fills the data type info structure for the database.
DynamicAny getInfo(SQLSMALLINT type, const std::string& param) const;
DynamicAny getInfo(SQLSMALLINT type, const std::string & param) const;
/// Returns information about specified data type as specified by parameter 'type'.
/// The requested information is specified by parameter 'param'.
/// Will fail with a Poco::NotFoundException thrown if the param is not found
bool tryGetInfo(SQLSMALLINT type, const std::string& param, DynamicAny& result) const;
bool tryGetInfo(SQLSMALLINT type, const std::string & param, DynamicAny & result) const;
/// Returns information about specified data type as specified by parameter 'type' in param result.
/// The requested information is specified by parameter 'param'.
/// Will return false if the param is not found. The value of result will be not changed in this case.
void print(std::ostream& ostr);
void print(std::ostream & ostr);
/// Prints all the types (as reported by the underlying database)
/// to the supplied output stream.
private:
private:
void fillCTypes();
void fillSQLTypes();
DataTypeMap _cDataTypes;
DataTypeMap _sqlDataTypes;
TypeInfoVec _typeInfo;
SQLHDBC* _pHDBC;
};
SQLHDBC * _pHDBC;
};
} } } // namespace Poco::Data::ODBC
}
}
} // namespace Poco::Data::ODBC
#endif

File diff suppressed because it is too large Load Diff

View File

@ -18,34 +18,39 @@
#define Data_ODBC_Unicode_UNIX_INCLUDED
namespace Poco {
namespace Data {
namespace ODBC {
namespace Poco
{
namespace Data
{
namespace ODBC
{
void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, std::string& target);
void makeUTF16(SQLCHAR * pSQLChar, SQLINTEGER length, std::string & target);
/// Utility function for conversion from UTF-8 to UTF-16
inline void makeUTF16(SQLCHAR* pSQLChar, SQLSMALLINT length, std::string& target)
inline void makeUTF16(SQLCHAR * pSQLChar, SQLSMALLINT length, std::string & target)
/// Utility function for conversion from UTF-8 to UTF-16.
{
makeUTF16(pSQLChar, (SQLINTEGER) length, target);
}
{
makeUTF16(pSQLChar, (SQLINTEGER)length, target);
}
void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, SQLINTEGER length, SQLPOINTER pTarget, SQLINTEGER targetLength);
void makeUTF8(Poco::Buffer<SQLWCHAR> & buffer, SQLINTEGER length, SQLPOINTER pTarget, SQLINTEGER targetLength);
/// Utility function for conversion from UTF-16 to UTF-8.
inline void makeUTF8(Poco::Buffer<SQLWCHAR>& buffer, int length, SQLPOINTER pTarget, SQLSMALLINT targetLength)
inline void makeUTF8(Poco::Buffer<SQLWCHAR> & buffer, int length, SQLPOINTER pTarget, SQLSMALLINT targetLength)
/// Utility function for conversion from UTF-16 to UTF-8.
{
makeUTF8(buffer, length, pTarget, (SQLINTEGER) targetLength);
{
makeUTF8(buffer, length, pTarget, (SQLINTEGER)targetLength);
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif // Data_ODBC_Unicode_UNIX_INCLUDED

View File

@ -18,25 +18,28 @@
#define Data_ODBC_Unicode_WIN32_INCLUDED
namespace Poco {
namespace Data {
namespace ODBC {
inline void makeUTF16(SQLCHAR* pSQLChar, SQLINTEGER length, std::wstring& target)
/// Utility function for conversion from UTF-8 to UTF-16
namespace Poco
{
namespace Data
{
namespace ODBC
{
inline void makeUTF16(SQLCHAR * pSQLChar, SQLINTEGER length, std::wstring & target)
/// Utility function for conversion from UTF-8 to UTF-16
{
int len = length;
if (SQL_NTS == len)
len = (int) std::strlen((const char *) pSQLChar);
len = (int)std::strlen((const char *)pSQLChar);
UnicodeConverter::toUTF16((const char *) pSQLChar, len, target);
}
UnicodeConverter::toUTF16((const char *)pSQLChar, len, target);
}
inline void makeUTF8(Poco::Buffer<wchar_t>& buffer, SQLINTEGER length, SQLPOINTER pTarget, SQLINTEGER targetLength)
inline void makeUTF8(Poco::Buffer<wchar_t> & buffer, SQLINTEGER length, SQLPOINTER pTarget, SQLINTEGER targetLength)
/// Utility function for conversion from UTF-16 to UTF-8. Length is in bytes.
{
{
if (buffer.sizeBytes() < length)
throw InvalidArgumentException("Specified length exceeds available length.");
else if ((length % 2) != 0)
@ -47,11 +50,13 @@ inline void makeUTF8(Poco::Buffer<wchar_t>& buffer, SQLINTEGER length, SQLPOINTE
UnicodeConverter::toUTF8(buffer.begin(), length, result);
std::memset(pTarget, 0, targetLength);
std::strncpy((char*) pTarget, result.c_str(), result.size() < targetLength ? result.size() : targetLength);
std::strncpy((char *)pTarget, result.c_str(), result.size() < targetLength ? result.size() : targetLength);
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif // Data_ODBC_Unicode_WIN32_INCLUDED

View File

@ -18,39 +18,42 @@
#define Data_ODBC_Utility_INCLUDED
#include <map>
#include <sstream>
#include <sqltypes.h>
#include "Poco/Data/Date.h"
#include "Poco/Data/ODBC/ODBC.h"
#include "Poco/Data/ODBC/TypeInfo.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/Time.h"
#include "Poco/DateTime.h"
#include <sstream>
#include <map>
#include <sqltypes.h>
namespace Poco {
namespace Data {
namespace ODBC {
class ODBC_API Utility
/// Various utility functions
namespace Poco
{
public:
namespace Data
{
namespace ODBC
{
class ODBC_API Utility
/// Various utility functions
{
public:
typedef std::map<std::string, std::string> DSNMap;
typedef DSNMap DriverMap;
static bool isError(SQLRETURN rc);
/// Returns true if return code is error
static DriverMap& drivers(DriverMap& driverMap);
static DriverMap & drivers(DriverMap & driverMap);
/// Returns driver-attributes map of available ODBC drivers.
static DSNMap& dataSources(DSNMap& dsnMap);
static DSNMap & dataSources(DSNMap & dsnMap);
/// Returns DSN-description map of available ODBC data sources.
template<typename MapType, typename KeyArgType, typename ValueArgType>
static typename MapType::iterator mapInsert(MapType& m, const KeyArgType& k, const ValueArgType& v)
template <typename MapType, typename KeyArgType, typename ValueArgType>
static typename MapType::iterator mapInsert(MapType & m, const KeyArgType & k, const ValueArgType & v)
/// Utility map "insert or replace" function (from S. Meyers: Effective STL, Item 24)
{
typename MapType::iterator lb = m.lower_bound(k);
@ -62,7 +65,7 @@ public:
else
{
typedef typename MapType::value_type MVT;
return m.insert(lb, MVT(k,v));
return m.insert(lb, MVT(k, v));
}
}
@ -72,136 +75,150 @@ public:
static int sqlDataType(int cDataType);
/// Returns SQL data type corresponding to supplied C data type.
static void dateSync(Date& dt, const SQL_DATE_STRUCT& ts);
static void dateSync(Date & dt, const SQL_DATE_STRUCT & ts);
/// Transfers data from ODBC SQL_DATE_STRUCT to Poco::DateTime.
template <typename T, typename F>
static void dateSync(T& d, const F& ds)
static void dateSync(T & d, const F & ds)
/// Transfers data from ODBC SQL_DATE_STRUCT container to Poco::DateTime container.
{
std::size_t size = ds.size();
if (d.size() != size) d.resize(size);
if (d.size() != size)
d.resize(size);
typename T::iterator dIt = d.begin();
typename F::const_iterator it = ds.begin();
typename F::const_iterator end = ds.end();
for (; it != end; ++it, ++dIt) dateSync(*dIt, *it);
for (; it != end; ++it, ++dIt)
dateSync(*dIt, *it);
}
static void timeSync(Time& dt, const SQL_TIME_STRUCT& ts);
static void timeSync(Time & dt, const SQL_TIME_STRUCT & ts);
/// Transfers data from ODBC SQL_TIME_STRUCT to Poco::DateTime.
template <typename T, typename F>
static void timeSync(T& t, const F& ts)
static void timeSync(T & t, const F & ts)
/// Transfers data from ODBC SQL_TIME_STRUCT container to Poco::DateTime container.
{
std::size_t size = ts.size();
if (t.size() != size) t.resize(size);
if (t.size() != size)
t.resize(size);
typename T::iterator dIt = t.begin();
typename F::const_iterator it = ts.begin();
typename F::const_iterator end = ts.end();
for (; it != end; ++it, ++dIt) timeSync(*dIt, *it);
for (; it != end; ++it, ++dIt)
timeSync(*dIt, *it);
}
static void dateTimeSync(Poco::DateTime& dt, const SQL_TIMESTAMP_STRUCT& ts);
static void dateTimeSync(Poco::DateTime & dt, const SQL_TIMESTAMP_STRUCT & ts);
/// Transfers data from ODBC SQL_TIMESTAMP_STRUCT to Poco::DateTime.
template <typename T, typename F>
static void dateTimeSync(T& dt, const F& ts)
static void dateTimeSync(T & dt, const F & ts)
/// Transfers data from ODBC SQL_TIMESTAMP_STRUCT container to Poco::DateTime container.
{
std::size_t size = ts.size();
if (dt.size() != size) dt.resize(size);
if (dt.size() != size)
dt.resize(size);
typename T::iterator dIt = dt.begin();
typename F::const_iterator it = ts.begin();
typename F::const_iterator end = ts.end();
for (; it != end; ++it, ++dIt) dateTimeSync(*dIt, *it);
for (; it != end; ++it, ++dIt)
dateTimeSync(*dIt, *it);
}
static void dateSync(SQL_DATE_STRUCT& ts, const Date& dt);
static void dateSync(SQL_DATE_STRUCT & ts, const Date & dt);
/// Transfers data from Poco::Data::Date to ODBC SQL_DATE_STRUCT.
template <typename C>
static void dateSync(std::vector<SQL_DATE_STRUCT>& ds, const C& d)
static void dateSync(std::vector<SQL_DATE_STRUCT> & ds, const C & d)
/// Transfers data from Poco::Data::Date vector to ODBC SQL_DATE_STRUCT container.
{
std::size_t size = d.size();
if (ds.size() != size) ds.resize(size);
if (ds.size() != size)
ds.resize(size);
std::vector<SQL_DATE_STRUCT>::iterator dIt = ds.begin();
typename C::const_iterator it = d.begin();
typename C::const_iterator end = d.end();
for (; it != end; ++it, ++dIt) dateSync(*dIt, *it);
for (; it != end; ++it, ++dIt)
dateSync(*dIt, *it);
}
static void timeSync(SQL_TIME_STRUCT& ts, const Time& dt);
static void timeSync(SQL_TIME_STRUCT & ts, const Time & dt);
/// Transfers data from Poco::Data::Time to ODBC SQL_TIME_STRUCT.
template <typename C>
static void timeSync(std::vector<SQL_TIME_STRUCT>& ts, const C& t)
static void timeSync(std::vector<SQL_TIME_STRUCT> & ts, const C & t)
/// Transfers data from Poco::Data::Time container to ODBC SQL_TIME_STRUCT vector.
{
std::size_t size = t.size();
if (ts.size() != size) ts.resize(size);
if (ts.size() != size)
ts.resize(size);
std::vector<SQL_TIME_STRUCT>::iterator tIt = ts.begin();
typename C::const_iterator it = t.begin();
typename C::const_iterator end = t.end();
for (; it != end; ++it, ++tIt) timeSync(*tIt, *it);
for (; it != end; ++it, ++tIt)
timeSync(*tIt, *it);
}
static void dateTimeSync(SQL_TIMESTAMP_STRUCT& ts, const Poco::DateTime& dt);
static void dateTimeSync(SQL_TIMESTAMP_STRUCT & ts, const Poco::DateTime & dt);
/// Transfers data from Poco::DateTime to ODBC SQL_TIMESTAMP_STRUCT.
template <typename C>
static void dateTimeSync(std::vector<SQL_TIMESTAMP_STRUCT>& ts, const C& dt)
static void dateTimeSync(std::vector<SQL_TIMESTAMP_STRUCT> & ts, const C & dt)
/// Transfers data from Poco::DateTime to ODBC SQL_TIMESTAMP_STRUCT.
{
std::size_t size = dt.size();
if (ts.size() != size) ts.resize(size);
if (ts.size() != size)
ts.resize(size);
std::vector<SQL_TIMESTAMP_STRUCT>::iterator tIt = ts.begin();
typename C::const_iterator it = dt.begin();
typename C::const_iterator end = dt.end();
for (; it != end; ++it, ++tIt) dateTimeSync(*tIt, *it);
for (; it != end; ++it, ++tIt)
dateTimeSync(*tIt, *it);
}
private:
private:
static const TypeInfo _dataTypes;
/// C <==> SQL data type mapping
};
};
///
/// inlines
///
inline bool Utility::isError(SQLRETURN rc)
{
///
/// inlines
///
inline bool Utility::isError(SQLRETURN rc)
{
return (0 != (rc & (~1)));
}
}
inline int Utility::cDataType(int sqlDataType)
{
inline int Utility::cDataType(int sqlDataType)
{
return _dataTypes.cDataType(sqlDataType);
}
}
inline int Utility::sqlDataType(int cDataType)
{
inline int Utility::sqlDataType(int cDataType)
{
return _dataTypes.sqlDataType(cDataType);
}
}
inline void Utility::dateSync(Date& d, const SQL_DATE_STRUCT& ts)
{
inline void Utility::dateSync(Date & d, const SQL_DATE_STRUCT & ts)
{
d.assign(ts.year, ts.month, ts.day);
}
}
inline void Utility::timeSync(Time& t, const SQL_TIME_STRUCT& ts)
{
inline void Utility::timeSync(Time & t, const SQL_TIME_STRUCT & ts)
{
t.assign(ts.hour, ts.minute, ts.second);
}
}
}
} } } // namespace Poco::Data::ODBC
} // namespace Poco::Data::ODBC
#endif

View File

@ -18,41 +18,44 @@
#define Data_AbstractBinder_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/Time.h"
#include "Poco/Data/LOB.h"
#include "Poco/DateTime.h"
#include "Poco/Nullable.h"
#include "Poco/Any.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/UTFString.h"
#include <vector>
#include <cstddef>
#include <deque>
#include <list>
#include <cstddef>
#include <vector>
#include "Poco/Any.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/Date.h"
#include "Poco/Data/LOB.h"
#include "Poco/Data/Time.h"
#include "Poco/DateTime.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/Nullable.h"
#include "Poco/UTFString.h"
namespace Poco {
namespace Data {
typedef NullType NullData;
namespace Keywords {
static const NullData null = NULL_GENERIC;
} // namespace Keywords
class Data_API AbstractBinder
/// Interface for Binding data types to placeholders.
namespace Poco
{
public:
namespace Data
{
typedef NullType NullData;
namespace Keywords
{
static const NullData null = NULL_GENERIC;
} // namespace Keywords
class Data_API AbstractBinder
/// Interface for Binding data types to placeholders.
{
public:
typedef SharedPtr<AbstractBinder> Ptr;
enum Direction
@ -69,270 +72,270 @@ public:
virtual ~AbstractBinder();
/// Destroys the AbstractBinder.
virtual void bind(std::size_t pos, const Poco::Int8& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Poco::Int8 & val, Direction dir = PD_IN) = 0;
/// Binds an Int8.
virtual void bind(std::size_t pos, const std::vector<Poco::Int8>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Poco::Int8> & val, Direction dir = PD_IN);
/// Binds an Int8 vector.
virtual void bind(std::size_t pos, const std::deque<Poco::Int8>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Poco::Int8> & val, Direction dir = PD_IN);
/// Binds an Int8 deque.
virtual void bind(std::size_t pos, const std::list<Poco::Int8>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Poco::Int8> & val, Direction dir = PD_IN);
/// Binds an Int8 list.
virtual void bind(std::size_t pos, const Poco::UInt8& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Poco::UInt8 & val, Direction dir = PD_IN) = 0;
/// Binds an UInt8.
virtual void bind(std::size_t pos, const std::vector<Poco::UInt8>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Poco::UInt8> & val, Direction dir = PD_IN);
/// Binds an UInt8 vector.
virtual void bind(std::size_t pos, const std::deque<Poco::UInt8>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Poco::UInt8> & val, Direction dir = PD_IN);
/// Binds an UInt8 deque.
virtual void bind(std::size_t pos, const std::list<Poco::UInt8>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Poco::UInt8> & val, Direction dir = PD_IN);
/// Binds an UInt8 list.
virtual void bind(std::size_t pos, const Poco::Int16& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Poco::Int16 & val, Direction dir = PD_IN) = 0;
/// Binds an Int16.
virtual void bind(std::size_t pos, const std::vector<Poco::Int16>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Poco::Int16> & val, Direction dir = PD_IN);
/// Binds an Int16 vector.
virtual void bind(std::size_t pos, const std::deque<Poco::Int16>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Poco::Int16> & val, Direction dir = PD_IN);
/// Binds an Int16 deque.
virtual void bind(std::size_t pos, const std::list<Poco::Int16>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Poco::Int16> & val, Direction dir = PD_IN);
/// Binds an Int16 list.
virtual void bind(std::size_t pos, const Poco::UInt16& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Poco::UInt16 & val, Direction dir = PD_IN) = 0;
/// Binds an UInt16.
virtual void bind(std::size_t pos, const std::vector<Poco::UInt16>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Poco::UInt16> & val, Direction dir = PD_IN);
/// Binds an UInt16 vector.
virtual void bind(std::size_t pos, const std::deque<Poco::UInt16>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Poco::UInt16> & val, Direction dir = PD_IN);
/// Binds an UInt16 deque.
virtual void bind(std::size_t pos, const std::list<Poco::UInt16>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Poco::UInt16> & val, Direction dir = PD_IN);
/// Binds an UInt16 list.
virtual void bind(std::size_t pos, const Poco::Int32& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Poco::Int32 & val, Direction dir = PD_IN) = 0;
/// Binds an Int32.
virtual void bind(std::size_t pos, const std::vector<Poco::Int32>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Poco::Int32> & val, Direction dir = PD_IN);
/// Binds an Int32 vector.
virtual void bind(std::size_t pos, const std::deque<Poco::Int32>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Poco::Int32> & val, Direction dir = PD_IN);
/// Binds an Int32 deque.
virtual void bind(std::size_t pos, const std::list<Poco::Int32>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Poco::Int32> & val, Direction dir = PD_IN);
/// Binds an Int32 list.
virtual void bind(std::size_t pos, const Poco::UInt32& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Poco::UInt32 & val, Direction dir = PD_IN) = 0;
/// Binds an UInt32.
virtual void bind(std::size_t pos, const std::vector<Poco::UInt32>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Poco::UInt32> & val, Direction dir = PD_IN);
/// Binds an UInt32 vector.
virtual void bind(std::size_t pos, const std::deque<Poco::UInt32>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Poco::UInt32> & val, Direction dir = PD_IN);
/// Binds an UInt32 deque.
virtual void bind(std::size_t pos, const std::list<Poco::UInt32>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Poco::UInt32> & val, Direction dir = PD_IN);
/// Binds an UInt32 list.
virtual void bind(std::size_t pos, const Poco::Int64& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Poco::Int64 & val, Direction dir = PD_IN) = 0;
/// Binds an Int64.
virtual void bind(std::size_t pos, const std::vector<Poco::Int64>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Poco::Int64> & val, Direction dir = PD_IN);
/// Binds an Int64 vector.
virtual void bind(std::size_t pos, const std::deque<Poco::Int64>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Poco::Int64> & val, Direction dir = PD_IN);
/// Binds an Int64 deque.
virtual void bind(std::size_t pos, const std::list<Poco::Int64>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Poco::Int64> & val, Direction dir = PD_IN);
/// Binds an Int64 list.
virtual void bind(std::size_t pos, const Poco::UInt64& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Poco::UInt64 & val, Direction dir = PD_IN) = 0;
/// Binds an UInt64.
virtual void bind(std::size_t pos, const std::vector<Poco::UInt64>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Poco::UInt64> & val, Direction dir = PD_IN);
/// Binds an UInt64 vector.
virtual void bind(std::size_t pos, const std::deque<Poco::UInt64>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Poco::UInt64> & val, Direction dir = PD_IN);
/// Binds an UInt64 deque.
virtual void bind(std::size_t pos, const std::list<Poco::UInt64>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Poco::UInt64> & val, Direction dir = PD_IN);
/// Binds an UInt64 list.
#ifndef POCO_LONG_IS_64_BIT
virtual void bind(std::size_t pos, const long& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const long & val, Direction dir = PD_IN) = 0;
/// Binds a long.
virtual void bind(std::size_t pos, const unsigned long& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const unsigned long & val, Direction dir = PD_IN) = 0;
/// Binds an unsigned long.
virtual void bind(std::size_t pos, const std::vector<long>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<long> & val, Direction dir = PD_IN);
/// Binds a long vector.
virtual void bind(std::size_t pos, const std::deque<long>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<long> & val, Direction dir = PD_IN);
/// Binds a long deque.
virtual void bind(std::size_t pos, const std::list<long>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<long> & val, Direction dir = PD_IN);
/// Binds a long list.
#endif
virtual void bind(std::size_t pos, const bool& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const bool & val, Direction dir = PD_IN) = 0;
/// Binds a boolean.
virtual void bind(std::size_t pos, const std::vector<bool>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<bool> & val, Direction dir = PD_IN);
/// Binds a boolean vector.
virtual void bind(std::size_t pos, const std::deque<bool>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<bool> & val, Direction dir = PD_IN);
/// Binds a boolean deque.
virtual void bind(std::size_t pos, const std::list<bool>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<bool> & val, Direction dir = PD_IN);
/// Binds a boolean list.
virtual void bind(std::size_t pos, const float& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const float & val, Direction dir = PD_IN) = 0;
/// Binds a float.
virtual void bind(std::size_t pos, const std::vector<float>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<float> & val, Direction dir = PD_IN);
/// Binds a float vector.
virtual void bind(std::size_t pos, const std::deque<float>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<float> & val, Direction dir = PD_IN);
/// Binds a float deque.
virtual void bind(std::size_t pos, const std::list<float>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<float> & val, Direction dir = PD_IN);
/// Binds a float list.
virtual void bind(std::size_t pos, const double& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const double & val, Direction dir = PD_IN) = 0;
/// Binds a double.
virtual void bind(std::size_t pos, const std::vector<double>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<double> & val, Direction dir = PD_IN);
/// Binds a double vector.
virtual void bind(std::size_t pos, const std::deque<double>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<double> & val, Direction dir = PD_IN);
/// Binds a double deque.
virtual void bind(std::size_t pos, const std::list<double>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<double> & val, Direction dir = PD_IN);
/// Binds a double list.
virtual void bind(std::size_t pos, const char& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const char & val, Direction dir = PD_IN) = 0;
/// Binds a single character.
virtual void bind(std::size_t pos, const std::vector<char>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<char> & val, Direction dir = PD_IN);
/// Binds a character vector.
virtual void bind(std::size_t pos, const std::deque<char>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<char> & val, Direction dir = PD_IN);
/// Binds a character deque.
virtual void bind(std::size_t pos, const std::list<char>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<char> & val, Direction dir = PD_IN);
/// Binds a character list.
virtual void bind(std::size_t pos, const char* const& pVal, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const char * const & pVal, Direction dir = PD_IN) = 0;
/// Binds a const char ptr.
virtual void bind(std::size_t pos, const std::string& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const std::string & val, Direction dir = PD_IN) = 0;
/// Binds a string.
virtual void bind(std::size_t pos, const std::vector<std::string>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<std::string> & val, Direction dir = PD_IN);
/// Binds a string vector.
virtual void bind(std::size_t pos, const std::deque<std::string>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<std::string> & val, Direction dir = PD_IN);
/// Binds a string deque.
virtual void bind(std::size_t pos, const std::list<std::string>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<std::string> & val, Direction dir = PD_IN);
/// Binds a string list.
virtual void bind(std::size_t pos, const UTF16String& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const UTF16String & val, Direction dir = PD_IN);
/// Binds a UTF-16 Unicode string.
virtual void bind(std::size_t pos, const std::vector<UTF16String>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<UTF16String> & val, Direction dir = PD_IN);
/// Binds a UTF-16 Unicode string vector.
virtual void bind(std::size_t pos, const std::deque<UTF16String>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<UTF16String> & val, Direction dir = PD_IN);
/// Binds a UTF-16 Unicode string deque.
virtual void bind(std::size_t pos, const std::list<UTF16String>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<UTF16String> & val, Direction dir = PD_IN);
/// Binds a UTF-16 Unicode string list.
virtual void bind(std::size_t pos, const BLOB& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const BLOB & val, Direction dir = PD_IN) = 0;
/// Binds a BLOB.
virtual void bind(std::size_t pos, const CLOB& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const CLOB & val, Direction dir = PD_IN) = 0;
/// Binds a CLOB.
virtual void bind(std::size_t pos, const std::vector<BLOB>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<BLOB> & val, Direction dir = PD_IN);
/// Binds a BLOB vector.
virtual void bind(std::size_t pos, const std::deque<BLOB>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<BLOB> & val, Direction dir = PD_IN);
/// Binds a BLOB deque.
virtual void bind(std::size_t pos, const std::list<BLOB>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<BLOB> & val, Direction dir = PD_IN);
/// Binds a BLOB list.
virtual void bind(std::size_t pos, const std::vector<CLOB>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<CLOB> & val, Direction dir = PD_IN);
/// Binds a CLOB vector.
virtual void bind(std::size_t pos, const std::deque<CLOB>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<CLOB> & val, Direction dir = PD_IN);
/// Binds a CLOB deque.
virtual void bind(std::size_t pos, const std::list<CLOB>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<CLOB> & val, Direction dir = PD_IN);
/// Binds a CLOB list.
virtual void bind(std::size_t pos, const DateTime& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const DateTime & val, Direction dir = PD_IN) = 0;
/// Binds a DateTime.
virtual void bind(std::size_t pos, const std::vector<DateTime>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<DateTime> & val, Direction dir = PD_IN);
/// Binds a DateTime vector.
virtual void bind(std::size_t pos, const std::deque<DateTime>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<DateTime> & val, Direction dir = PD_IN);
/// Binds a DateTime deque.
virtual void bind(std::size_t pos, const std::list<DateTime>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<DateTime> & val, Direction dir = PD_IN);
/// Binds a DateTime list.
virtual void bind(std::size_t pos, const Date& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Date & val, Direction dir = PD_IN) = 0;
/// Binds a Date.
virtual void bind(std::size_t pos, const std::vector<Date>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Date> & val, Direction dir = PD_IN);
/// Binds a Date vector.
virtual void bind(std::size_t pos, const std::deque<Date>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Date> & val, Direction dir = PD_IN);
/// Binds a Date deque.
virtual void bind(std::size_t pos, const std::list<Date>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Date> & val, Direction dir = PD_IN);
/// Binds a Date list.
virtual void bind(std::size_t pos, const Time& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const Time & val, Direction dir = PD_IN) = 0;
/// Binds a Time.
virtual void bind(std::size_t pos, const std::vector<Time>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<Time> & val, Direction dir = PD_IN);
/// Binds a Time vector.
virtual void bind(std::size_t pos, const std::deque<Time>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<Time> & val, Direction dir = PD_IN);
/// Binds a Time deque.
virtual void bind(std::size_t pos, const std::list<Time>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<Time> & val, Direction dir = PD_IN);
/// Binds a Time list.
virtual void bind(std::size_t pos, const NullData& val, Direction dir = PD_IN) = 0;
virtual void bind(std::size_t pos, const NullData & val, Direction dir = PD_IN) = 0;
/// Binds a null.
virtual void bind(std::size_t pos, const std::vector<NullData>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::vector<NullData> & val, Direction dir = PD_IN);
/// Binds a null vector.
virtual void bind(std::size_t pos, const std::deque<NullData>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::deque<NullData> & val, Direction dir = PD_IN);
/// Binds a null deque.
virtual void bind(std::size_t pos, const std::list<NullData>& val, Direction dir = PD_IN);
virtual void bind(std::size_t pos, const std::list<NullData> & val, Direction dir = PD_IN);
/// Binds a null list.
void bind(std::size_t pos, const Any& val, Direction dir = PD_IN);
void bind(std::size_t pos, const Any & val, Direction dir = PD_IN);
/// Binds an Any.
void bind(std::size_t pos, const Poco::Dynamic::Var& val, Direction dir = PD_IN);
void bind(std::size_t pos, const Poco::Dynamic::Var & val, Direction dir = PD_IN);
/// Binds a Var.
virtual void reset();
@ -343,31 +346,32 @@ public:
static bool isInBound(Direction dir);
/// Returns true if direction is in bound;
};
};
//
// inlines
//
inline void AbstractBinder::reset()
{
//
// inlines
//
inline void AbstractBinder::reset()
{
//no-op
}
}
inline bool AbstractBinder::isOutBound(Direction dir)
{
inline bool AbstractBinder::isOutBound(Direction dir)
{
return PD_OUT == dir || PD_IN_OUT == dir;
}
}
inline bool AbstractBinder::isInBound(Direction dir)
{
inline bool AbstractBinder::isInBound(Direction dir)
{
return PD_IN == dir || PD_IN_OUT == dir;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_AbstractBinder_INCLUDED

View File

@ -18,25 +18,27 @@
#define Data_AbstractBinding_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/AbstractBinder.h"
#include "Poco/Any.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <vector>
#include <list>
#include <deque>
#include <cstddef>
#include <deque>
#include <list>
#include <vector>
#include "Poco/Any.h"
#include "Poco/AutoPtr.h"
#include "Poco/Data/AbstractBinder.h"
#include "Poco/Data/Data.h"
#include "Poco/RefCountedObject.h"
namespace Poco {
namespace Data {
class Data_API AbstractBinding
/// AbstractBinding connects a value with a placeholder via an AbstractBinder interface.
namespace Poco
{
public:
namespace Data
{
class Data_API AbstractBinding
/// AbstractBinding connects a value with a placeholder via an AbstractBinder interface.
{
public:
typedef SharedPtr<AbstractBinding> Ptr;
typedef AbstractBinder::Ptr BinderPtr;
@ -47,7 +49,7 @@ public:
PD_IN_OUT = AbstractBinder::PD_IN_OUT
};
AbstractBinding(const std::string& name = "", Direction direction = PD_IN, Poco::UInt32 bulkSize = 0);
AbstractBinding(const std::string & name = "", Direction direction = PD_IN, Poco::UInt32 bulkSize = 0);
/// Creates the AbstractBinding.
virtual ~AbstractBinding();
@ -83,7 +85,7 @@ public:
AbstractBinder::Direction getDirection() const;
/// Returns the binding direction.
const std::string& name() const;
const std::string & name() const;
/// Returns the name for this binding.
bool isBulk() const;
@ -92,53 +94,54 @@ public:
Poco::UInt32 bulkSize() const;
/// Returns the size of the bulk binding.
private:
private:
BinderPtr _pBinder;
std::string _name;
Direction _direction;
Poco::UInt32 _bulkSize;
};
};
typedef std::vector<AbstractBinding::Ptr> AbstractBindingVec;
typedef std::deque<AbstractBinding::Ptr> AbstractBindingDeq;
typedef std::list<AbstractBinding::Ptr> AbstractBindingLst;
typedef std::vector<AbstractBinding::Ptr> AbstractBindingVec;
typedef std::deque<AbstractBinding::Ptr> AbstractBindingDeq;
typedef std::list<AbstractBinding::Ptr> AbstractBindingLst;
//
// inlines
//
inline AbstractBinder::Ptr AbstractBinding::getBinder() const
{
//
// inlines
//
inline AbstractBinder::Ptr AbstractBinding::getBinder() const
{
return _pBinder;
}
}
inline const std::string& AbstractBinding::name() const
{
inline const std::string & AbstractBinding::name() const
{
return _name;
}
}
inline AbstractBinder::Direction AbstractBinding::getDirection() const
{
return (AbstractBinder::Direction) _direction;
}
inline AbstractBinder::Direction AbstractBinding::getDirection() const
{
return (AbstractBinder::Direction)_direction;
}
inline bool AbstractBinding::isBulk() const
{
inline bool AbstractBinding::isBulk() const
{
return _bulkSize > 0;
}
}
inline Poco::UInt32 AbstractBinding::bulkSize() const
{
inline Poco::UInt32 AbstractBinding::bulkSize() const
{
return _bulkSize;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_AbstractBinding_INCLUDED

View File

@ -18,37 +18,38 @@
#define Data_AbstractExtraction_INCLUDED
#include "Poco/Data/Data.h"
#include <cstddef>
#include <deque>
#include <list>
#include <vector>
#include "Poco/AutoPtr.h"
#include "Poco/Data/AbstractExtractor.h"
#include "Poco/Data/AbstractPreparation.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/Limit.h"
#include "Poco/RefCountedObject.h"
#include "Poco/UTFString.h"
#include "Poco/AutoPtr.h"
#include <vector>
#include <deque>
#include <list>
#include <cstddef>
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class AbstractPreparator;
class AbstractPreparator;
class Data_API AbstractExtraction
class Data_API AbstractExtraction
/// AbstractExtraction is the interface class that connects output positions to concrete values
/// retrieved via an AbstractExtractor.
{
public:
{
public:
typedef SharedPtr<AbstractExtraction> Ptr;
typedef SharedPtr<AbstractExtractor> ExtractorPtr;
typedef SharedPtr<AbstractPreparator> PreparatorPtr;
AbstractExtraction(Poco::UInt32 limit = Limit::LIMIT_UNLIMITED,
Poco::UInt32 position = 0, bool bulk = false);
AbstractExtraction(Poco::UInt32 limit = Limit::LIMIT_UNLIMITED, Poco::UInt32 position = 0, bool bulk = false);
/// Creates the AbstractExtraction. A limit value equal to EXTRACT_UNLIMITED (0xffffffffu)
/// means that we extract as much data as possible during one execute.
/// Otherwise the limit value is used to partition data extracting to a limited amount of rows.
@ -92,7 +93,7 @@ public:
virtual bool canExtract() const;
/// Returns true. Implementations should override it for different behavior.
virtual AbstractPreparation::Ptr createPreparation(PreparatorPtr& pPrep, std::size_t pos) = 0;
virtual AbstractPreparation::Ptr createPreparation(PreparatorPtr & pPrep, std::size_t pos) = 0;
/// Creates and returns shared pointer to Preparation object for the extracting object.
void setLimit(Poco::UInt32 limit);
@ -125,7 +126,7 @@ public:
/// Returns the force empty string flag.
template <typename T>
bool isValueNull(const T& str, bool deflt)
bool isValueNull(const T & str, bool deflt)
/// Utility function to determine the nullness of the value.
/// This generic version always returns default value
/// (i.e. does nothing). The std::string overload does
@ -135,7 +136,7 @@ public:
return deflt;
}
bool isValueNull(const std::string& str, bool deflt);
bool isValueNull(const std::string & str, bool deflt);
/// Overload for const reference to std::string.
///
/// Returns true when following conditions are met:
@ -143,7 +144,7 @@ public:
/// - string is empty
/// - getEmptyStringIsNull() returns true
bool isValueNull(const Poco::UTF16String& str, bool deflt);
bool isValueNull(const Poco::UTF16String & str, bool deflt);
/// Overload for const reference to UTF16String.
///
/// Returns true when following conditions are met:
@ -151,11 +152,12 @@ public:
/// - string is empty
/// - getEmptyStringIsNull() returns true
private:
private:
template <typename S>
bool isStringNull(const S& str, bool deflt)
bool isStringNull(const S & str, bool deflt)
{
if (getForceEmptyString()) return false;
if (getForceEmptyString())
return false;
if (getEmptyStringIsNull() && str.empty())
return true;
@ -169,110 +171,111 @@ private:
bool _bulk;
bool _emptyStringIsNull;
bool _forceEmptyString;
};
};
typedef std::vector<AbstractExtraction::Ptr> AbstractExtractionVec;
typedef std::vector<AbstractExtractionVec> AbstractExtractionVecVec;
typedef std::deque<AbstractExtraction::Ptr> AbstractExtractionDeq;
typedef std::vector<AbstractExtractionDeq> AbstractExtractionDeqVec;
typedef std::list<AbstractExtraction::Ptr> AbstractExtractionLst;
typedef std::vector<AbstractExtractionLst> AbstractExtractionLstVec;
typedef std::vector<AbstractExtraction::Ptr> AbstractExtractionVec;
typedef std::vector<AbstractExtractionVec> AbstractExtractionVecVec;
typedef std::deque<AbstractExtraction::Ptr> AbstractExtractionDeq;
typedef std::vector<AbstractExtractionDeq> AbstractExtractionDeqVec;
typedef std::list<AbstractExtraction::Ptr> AbstractExtractionLst;
typedef std::vector<AbstractExtractionLst> AbstractExtractionLstVec;
//
// inlines
//
inline void AbstractExtraction::setExtractor(ExtractorPtr pExtractor)
{
//
// inlines
//
inline void AbstractExtraction::setExtractor(ExtractorPtr pExtractor)
{
_pExtractor = pExtractor;
}
}
inline AbstractExtraction::ExtractorPtr AbstractExtraction::getExtractor() const
{
inline AbstractExtraction::ExtractorPtr AbstractExtraction::getExtractor() const
{
return _pExtractor;
}
}
inline void AbstractExtraction::setLimit(Poco::UInt32 limit)
{
inline void AbstractExtraction::setLimit(Poco::UInt32 limit)
{
_limit = limit;
}
}
inline Poco::UInt32 AbstractExtraction::getLimit() const
{
inline Poco::UInt32 AbstractExtraction::getLimit() const
{
return _limit;
}
}
inline bool AbstractExtraction::isNull(std::size_t row) const
{
inline bool AbstractExtraction::isNull(std::size_t row) const
{
throw NotImplementedException("Check for null values not implemented.");
}
}
inline Poco::UInt32 AbstractExtraction::position() const
{
inline Poco::UInt32 AbstractExtraction::position() const
{
return _position;
}
}
inline bool AbstractExtraction::isBulk() const
{
inline bool AbstractExtraction::isBulk() const
{
return _bulk;
}
}
inline void AbstractExtraction::reset()
{
}
inline void AbstractExtraction::reset()
{
}
inline bool AbstractExtraction::canExtract() const
{
inline bool AbstractExtraction::canExtract() const
{
return true;
}
}
inline void AbstractExtraction::setEmptyStringIsNull(bool emptyStringIsNull)
{
inline void AbstractExtraction::setEmptyStringIsNull(bool emptyStringIsNull)
{
_emptyStringIsNull = emptyStringIsNull;
}
}
inline bool AbstractExtraction::getEmptyStringIsNull() const
{
inline bool AbstractExtraction::getEmptyStringIsNull() const
{
return _emptyStringIsNull;
}
}
inline void AbstractExtraction::setForceEmptyString(bool forceEmptyString)
{
inline void AbstractExtraction::setForceEmptyString(bool forceEmptyString)
{
_forceEmptyString = forceEmptyString;
}
}
inline bool AbstractExtraction::getForceEmptyString() const
{
inline bool AbstractExtraction::getForceEmptyString() const
{
return _forceEmptyString;
}
}
inline bool AbstractExtraction::isValueNull(const std::string& str, bool deflt)
{
inline bool AbstractExtraction::isValueNull(const std::string & str, bool deflt)
{
return isStringNull(str, deflt);
}
}
inline bool AbstractExtraction::isValueNull(const Poco::UTF16String& str, bool deflt)
{
inline bool AbstractExtraction::isValueNull(const Poco::UTF16String & str, bool deflt)
{
return isStringNull(str, deflt);
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_AbstractExtraction_INCLUDED

View File

@ -18,39 +18,42 @@
#define Data_AbstractExtractor_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/Constants.h"
#include "Poco/Data/LOB.h"
#include "Poco/UTFString.h"
#include <vector>
#include <cstddef>
#include <deque>
#include <list>
#include <string>
#include <cstddef>
#include <vector>
#include "Poco/Data/Constants.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/LOB.h"
#include "Poco/UTFString.h"
namespace Poco {
namespace Poco
{
class DateTime;
class Any;
namespace Dynamic {
class Var;
namespace Dynamic
{
class Var;
}
namespace Data {
namespace Data
{
class Date;
class Time;
class Date;
class Time;
class Data_API AbstractExtractor
class Data_API AbstractExtractor
/// Interface used to extract data from a single result row.
/// If an extractor receives null it is not allowed to change val!
{
public:
{
public:
typedef SharedPtr<AbstractExtractor> Ptr;
AbstractExtractor();
@ -59,273 +62,273 @@ public:
virtual ~AbstractExtractor();
/// Destroys the AbstractExtractor.
virtual bool extract(std::size_t pos, Poco::Int8& val) = 0;
virtual bool extract(std::size_t pos, Poco::Int8 & val) = 0;
/// Extracts an Int8. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::Int8>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::Int8> & val);
/// Extracts an Int8 vector.
virtual bool extract(std::size_t pos, std::deque<Poco::Int8>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::Int8> & val);
/// Extracts an Int8 deque.
virtual bool extract(std::size_t pos, std::list<Poco::Int8>& val);
virtual bool extract(std::size_t pos, std::list<Poco::Int8> & val);
/// Extracts an Int8 list.
virtual bool extract(std::size_t pos, Poco::UInt8& val) = 0;
virtual bool extract(std::size_t pos, Poco::UInt8 & val) = 0;
/// Extracts an UInt8. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::UInt8>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::UInt8> & val);
/// Extracts an UInt8 vector.
virtual bool extract(std::size_t pos, std::deque<Poco::UInt8>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::UInt8> & val);
/// Extracts an UInt8 deque.
virtual bool extract(std::size_t pos, std::list<Poco::UInt8>& val);
virtual bool extract(std::size_t pos, std::list<Poco::UInt8> & val);
/// Extracts an UInt8 list.
virtual bool extract(std::size_t pos, Poco::Int16& val) = 0;
virtual bool extract(std::size_t pos, Poco::Int16 & val) = 0;
/// Extracts an Int16. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::Int16>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::Int16> & val);
/// Extracts an Int16 vector.
virtual bool extract(std::size_t pos, std::deque<Poco::Int16>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::Int16> & val);
/// Extracts an Int16 deque.
virtual bool extract(std::size_t pos, std::list<Poco::Int16>& val);
virtual bool extract(std::size_t pos, std::list<Poco::Int16> & val);
/// Extracts an Int16 list.
virtual bool extract(std::size_t pos, Poco::UInt16& val) = 0;
virtual bool extract(std::size_t pos, Poco::UInt16 & val) = 0;
/// Extracts an UInt16. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::UInt16>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::UInt16> & val);
/// Extracts an UInt16 vector.
virtual bool extract(std::size_t pos, std::deque<Poco::UInt16>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::UInt16> & val);
/// Extracts an UInt16 deque.
virtual bool extract(std::size_t pos, std::list<Poco::UInt16>& val);
virtual bool extract(std::size_t pos, std::list<Poco::UInt16> & val);
/// Extracts an UInt16 list.
virtual bool extract(std::size_t pos, Poco::Int32& val) = 0;
virtual bool extract(std::size_t pos, Poco::Int32 & val) = 0;
/// Extracts an Int32. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::Int32>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::Int32> & val);
/// Extracts an Int32 vector.
virtual bool extract(std::size_t pos, std::deque<Poco::Int32>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::Int32> & val);
/// Extracts an Int32 deque.
virtual bool extract(std::size_t pos, std::list<Poco::Int32>& val);
virtual bool extract(std::size_t pos, std::list<Poco::Int32> & val);
/// Extracts an Int32 list.
virtual bool extract(std::size_t pos, Poco::UInt32& val) = 0;
virtual bool extract(std::size_t pos, Poco::UInt32 & val) = 0;
/// Extracts an UInt32. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::UInt32>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::UInt32> & val);
/// Extracts an UInt32 vector.
virtual bool extract(std::size_t pos, std::deque<Poco::UInt32>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::UInt32> & val);
/// Extracts an UInt32 deque.
virtual bool extract(std::size_t pos, std::list<Poco::UInt32>& val);
virtual bool extract(std::size_t pos, std::list<Poco::UInt32> & val);
/// Extracts an UInt32 list.
virtual bool extract(std::size_t pos, Poco::Int64& val) = 0;
virtual bool extract(std::size_t pos, Poco::Int64 & val) = 0;
/// Extracts an Int64. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::Int64>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::Int64> & val);
/// Extracts an Int64 vector.
virtual bool extract(std::size_t pos, std::deque<Poco::Int64>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::Int64> & val);
/// Extracts an Int64 deque.
virtual bool extract(std::size_t pos, std::list<Poco::Int64>& val);
virtual bool extract(std::size_t pos, std::list<Poco::Int64> & val);
/// Extracts an Int64 list.
virtual bool extract(std::size_t pos, Poco::UInt64& val) = 0;
virtual bool extract(std::size_t pos, Poco::UInt64 & val) = 0;
/// Extracts an UInt64. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::UInt64>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::UInt64> & val);
/// Extracts an UInt64 vector.
virtual bool extract(std::size_t pos, std::deque<Poco::UInt64>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::UInt64> & val);
/// Extracts an UInt64 deque.
virtual bool extract(std::size_t pos, std::list<Poco::UInt64>& val);
virtual bool extract(std::size_t pos, std::list<Poco::UInt64> & val);
/// Extracts an UInt64 list.
#ifndef POCO_LONG_IS_64_BIT
virtual bool extract(std::size_t pos, long& val) = 0;
virtual bool extract(std::size_t pos, long & val) = 0;
/// Extracts a long. Returns false if null was received.
virtual bool extract(std::size_t pos, unsigned long& val) = 0;
virtual bool extract(std::size_t pos, unsigned long & val) = 0;
/// Extracts an unsigned long. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<long>& val);
virtual bool extract(std::size_t pos, std::vector<long> & val);
/// Extracts a long vector.
virtual bool extract(std::size_t pos, std::deque<long>& val);
virtual bool extract(std::size_t pos, std::deque<long> & val);
/// Extracts a long deque.
virtual bool extract(std::size_t pos, std::list<long>& val);
virtual bool extract(std::size_t pos, std::list<long> & val);
/// Extracts a long list.
#endif
virtual bool extract(std::size_t pos, bool& val) = 0;
virtual bool extract(std::size_t pos, bool & val) = 0;
/// Extracts a boolean. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<bool>& val);
virtual bool extract(std::size_t pos, std::vector<bool> & val);
/// Extracts a boolean vector.
virtual bool extract(std::size_t pos, std::deque<bool>& val);
virtual bool extract(std::size_t pos, std::deque<bool> & val);
/// Extracts a boolean deque.
virtual bool extract(std::size_t pos, std::list<bool>& val);
virtual bool extract(std::size_t pos, std::list<bool> & val);
/// Extracts a boolean list.
virtual bool extract(std::size_t pos, float& val) = 0;
virtual bool extract(std::size_t pos, float & val) = 0;
/// Extracts a float. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<float>& val);
virtual bool extract(std::size_t pos, std::vector<float> & val);
/// Extracts a float vector.
virtual bool extract(std::size_t pos, std::deque<float>& val);
virtual bool extract(std::size_t pos, std::deque<float> & val);
/// Extracts a float deque.
virtual bool extract(std::size_t pos, std::list<float>& val);
virtual bool extract(std::size_t pos, std::list<float> & val);
/// Extracts a float list.
virtual bool extract(std::size_t pos, double& val) = 0;
virtual bool extract(std::size_t pos, double & val) = 0;
/// Extracts a double. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<double>& val);
virtual bool extract(std::size_t pos, std::vector<double> & val);
/// Extracts a double vector.
virtual bool extract(std::size_t pos, std::deque<double>& val);
virtual bool extract(std::size_t pos, std::deque<double> & val);
/// Extracts a double deque.
virtual bool extract(std::size_t pos, std::list<double>& val);
virtual bool extract(std::size_t pos, std::list<double> & val);
/// Extracts a double list.
virtual bool extract(std::size_t pos, char& val) = 0;
virtual bool extract(std::size_t pos, char & val) = 0;
/// Extracts a single character. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<char>& val);
virtual bool extract(std::size_t pos, std::vector<char> & val);
/// Extracts a character vector.
virtual bool extract(std::size_t pos, std::deque<char>& val);
virtual bool extract(std::size_t pos, std::deque<char> & val);
/// Extracts a character deque.
virtual bool extract(std::size_t pos, std::list<char>& val);
virtual bool extract(std::size_t pos, std::list<char> & val);
/// Extracts a character list.
virtual bool extract(std::size_t pos, std::string& val) = 0;
virtual bool extract(std::size_t pos, std::string & val) = 0;
/// Extracts a string. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<std::string>& val);
virtual bool extract(std::size_t pos, std::vector<std::string> & val);
/// Extracts a string vector.
virtual bool extract(std::size_t pos, std::deque<std::string>& val);
virtual bool extract(std::size_t pos, std::deque<std::string> & val);
/// Extracts a string deque.
virtual bool extract(std::size_t pos, std::list<std::string>& val);
virtual bool extract(std::size_t pos, std::list<std::string> & val);
/// Extracts a string list.
virtual bool extract(std::size_t pos, UTF16String& val);
virtual bool extract(std::size_t pos, UTF16String & val);
/// Extracts a UTF16String. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<UTF16String>& val);
virtual bool extract(std::size_t pos, std::vector<UTF16String> & val);
/// Extracts a UTF16String vector.
virtual bool extract(std::size_t pos, std::deque<UTF16String>& val);
virtual bool extract(std::size_t pos, std::deque<UTF16String> & val);
/// Extracts a UTF16String deque.
virtual bool extract(std::size_t pos, std::list<UTF16String>& val);
virtual bool extract(std::size_t pos, std::list<UTF16String> & val);
/// Extracts a UTF16String list.
virtual bool extract(std::size_t pos, BLOB& val) = 0;
virtual bool extract(std::size_t pos, BLOB & val) = 0;
/// Extracts a BLOB. Returns false if null was received.
virtual bool extract(std::size_t pos, CLOB& val) = 0;
virtual bool extract(std::size_t pos, CLOB & val) = 0;
/// Extracts a CLOB. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<BLOB>& val);
virtual bool extract(std::size_t pos, std::vector<BLOB> & val);
/// Extracts a BLOB vector.
virtual bool extract(std::size_t pos, std::deque<BLOB>& val);
virtual bool extract(std::size_t pos, std::deque<BLOB> & val);
/// Extracts a BLOB deque.
virtual bool extract(std::size_t pos, std::list<BLOB>& val);
virtual bool extract(std::size_t pos, std::list<BLOB> & val);
/// Extracts a BLOB list.
virtual bool extract(std::size_t pos, std::vector<CLOB>& val);
virtual bool extract(std::size_t pos, std::vector<CLOB> & val);
/// Extracts a CLOB vector.
virtual bool extract(std::size_t pos, std::deque<CLOB>& val);
virtual bool extract(std::size_t pos, std::deque<CLOB> & val);
/// Extracts a CLOB deque.
virtual bool extract(std::size_t pos, std::list<CLOB>& val);
virtual bool extract(std::size_t pos, std::list<CLOB> & val);
/// Extracts a CLOB list.
virtual bool extract(std::size_t pos, DateTime& val) = 0;
virtual bool extract(std::size_t pos, DateTime & val) = 0;
/// Extracts a DateTime. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<DateTime>& val);
virtual bool extract(std::size_t pos, std::vector<DateTime> & val);
/// Extracts a DateTime vector.
virtual bool extract(std::size_t pos, std::deque<DateTime>& val);
virtual bool extract(std::size_t pos, std::deque<DateTime> & val);
/// Extracts a DateTime deque.
virtual bool extract(std::size_t pos, std::list<DateTime>& val);
virtual bool extract(std::size_t pos, std::list<DateTime> & val);
/// Extracts a DateTime list.
virtual bool extract(std::size_t pos, Date& val) = 0;
virtual bool extract(std::size_t pos, Date & val) = 0;
/// Extracts a Date. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Date>& val);
virtual bool extract(std::size_t pos, std::vector<Date> & val);
/// Extracts a Date vector.
virtual bool extract(std::size_t pos, std::deque<Date>& val);
virtual bool extract(std::size_t pos, std::deque<Date> & val);
/// Extracts a Date deque.
virtual bool extract(std::size_t pos, std::list<Date>& val);
virtual bool extract(std::size_t pos, std::list<Date> & val);
/// Extracts a Date list.
virtual bool extract(std::size_t pos, Time& val) = 0;
virtual bool extract(std::size_t pos, Time & val) = 0;
/// Extracts a Time. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Time>& val);
virtual bool extract(std::size_t pos, std::vector<Time> & val);
/// Extracts a Time vector.
virtual bool extract(std::size_t pos, std::deque<Time>& val);
virtual bool extract(std::size_t pos, std::deque<Time> & val);
/// Extracts a Time deque.
virtual bool extract(std::size_t pos, std::list<Time>& val);
virtual bool extract(std::size_t pos, std::list<Time> & val);
/// Extracts a Time list.
virtual bool extract(std::size_t pos, Any& val) = 0;
virtual bool extract(std::size_t pos, Any & val) = 0;
/// Extracts an Any. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Any>& val);
virtual bool extract(std::size_t pos, std::vector<Any> & val);
/// Extracts an Any vector.
virtual bool extract(std::size_t pos, std::deque<Any>& val);
virtual bool extract(std::size_t pos, std::deque<Any> & val);
/// Extracts an Any deque.
virtual bool extract(std::size_t pos, std::list<Any>& val);
virtual bool extract(std::size_t pos, std::list<Any> & val);
/// Extracts an Any list.
virtual bool extract(std::size_t pos, Poco::Dynamic::Var& val) = 0;
virtual bool extract(std::size_t pos, Poco::Dynamic::Var & val) = 0;
/// Extracts a Var. Returns false if null was received.
virtual bool extract(std::size_t pos, std::vector<Poco::Dynamic::Var>& val);
virtual bool extract(std::size_t pos, std::vector<Poco::Dynamic::Var> & val);
/// Extracts a Var vector.
virtual bool extract(std::size_t pos, std::deque<Poco::Dynamic::Var>& val);
virtual bool extract(std::size_t pos, std::deque<Poco::Dynamic::Var> & val);
/// Extracts a Var deque.
virtual bool extract(std::size_t pos, std::list<Poco::Dynamic::Var>& val);
virtual bool extract(std::size_t pos, std::list<Poco::Dynamic::Var> & val);
/// Extracts a Var list.
virtual bool isNull(std::size_t col, std::size_t row = POCO_DATA_INVALID_ROW) = 0;
@ -333,19 +336,20 @@ public:
virtual void reset();
/// Resets any information internally cached by the extractor.
};
};
///
/// inlines
///
inline void AbstractExtractor::reset()
{
///
/// inlines
///
inline void AbstractExtractor::reset()
{
//default no-op
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_AbstractExtractor_INCLUDED

View File

@ -18,20 +18,22 @@
#define Data_AbstractPreparation_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/AbstractPreparator.h"
#include "Poco/SharedPtr.h"
#include <cstddef>
#include "Poco/Data/AbstractPreparator.h"
#include "Poco/Data/Data.h"
#include "Poco/SharedPtr.h"
namespace Poco {
namespace Data {
class Data_API AbstractPreparation
/// Interface for calling the appropriate AbstractPreparator method
namespace Poco
{
public:
namespace Data
{
class Data_API AbstractPreparation
/// Interface for calling the appropriate AbstractPreparator method
{
public:
typedef SharedPtr<AbstractPreparation> Ptr;
typedef AbstractPreparator::Ptr PreparatorPtr;
@ -44,28 +46,29 @@ public:
virtual void prepare() = 0;
/// Prepares data.
protected:
protected:
AbstractPreparation();
AbstractPreparation(const AbstractPreparation&);
AbstractPreparation& operator = (const AbstractPreparation&);
AbstractPreparation(const AbstractPreparation &);
AbstractPreparation & operator=(const AbstractPreparation &);
PreparatorPtr preparation();
/// Returns the preparation object
PreparatorPtr _pPreparator;
};
};
//
// inlines
//
inline AbstractPreparation::PreparatorPtr AbstractPreparation::preparation()
{
//
// inlines
//
inline AbstractPreparation::PreparatorPtr AbstractPreparation::preparation()
{
return _pPreparator;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_AbstractPreparation_INCLUDED

View File

@ -18,35 +18,38 @@
#define Data_AbstractPreparator_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/RefCountedObject.h"
#include "Poco/Data/LOB.h"
#include "Poco/UTFString.h"
#include <vector>
#include <cstddef>
#include <deque>
#include <list>
#include <cstddef>
#include <vector>
#include "Poco/Data/Data.h"
#include "Poco/Data/LOB.h"
#include "Poco/RefCountedObject.h"
#include "Poco/UTFString.h"
namespace Poco {
namespace Poco
{
class DateTime;
class Any;
namespace Dynamic {
class Var;
namespace Dynamic
{
class Var;
}
namespace Data {
namespace Data
{
class Date;
class Time;
class Date;
class Time;
class Data_API AbstractPreparator
class Data_API AbstractPreparator
/// Interface used for database preparation where we first have to register all data types
/// (and memory output locations) before extracting data, e.g. ODBC.
/// Extract works as two-phase extract: first we call prepare once, then extract n-times.
@ -55,8 +58,8 @@ class Data_API AbstractPreparator
/// of the data type being prepared, thus all values are passed as const references.
/// Implementing this interface is not mandatory for a connector. Connectors that only extract data
/// after SQL execution (e.g. SQLite) do not need this functionality at all.
{
public:
{
public:
typedef SharedPtr<AbstractPreparator> Ptr;
AbstractPreparator(Poco::UInt32 length = 1u);
@ -65,273 +68,273 @@ public:
virtual ~AbstractPreparator();
/// Destroys the AbstractPreparator.
virtual void prepare(std::size_t pos, const Poco::Int8&) = 0;
virtual void prepare(std::size_t pos, const Poco::Int8 &) = 0;
/// Prepares an Int8.
virtual void prepare(std::size_t pos, const std::vector<Poco::Int8>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::Int8> & val);
/// Prepares an Int8 vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::Int8>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::Int8> & val);
/// Prepares an Int8 deque.
virtual void prepare(std::size_t pos, const std::list<Poco::Int8>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::Int8> & val);
/// Prepares an Int8 list.
virtual void prepare(std::size_t pos, const Poco::UInt8&) = 0;
virtual void prepare(std::size_t pos, const Poco::UInt8 &) = 0;
/// Prepares an UInt8.
virtual void prepare(std::size_t pos, const std::vector<Poco::UInt8>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::UInt8> & val);
/// Prepares an UInt8 vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::UInt8>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::UInt8> & val);
/// Prepares an UInt8 deque.
virtual void prepare(std::size_t pos, const std::list<Poco::UInt8>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::UInt8> & val);
/// Prepares an UInt8 list.
virtual void prepare(std::size_t pos, const Poco::Int16&) = 0;
virtual void prepare(std::size_t pos, const Poco::Int16 &) = 0;
/// Prepares an Int16.
virtual void prepare(std::size_t pos, const std::vector<Poco::Int16>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::Int16> & val);
/// Prepares an Int16 vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::Int16>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::Int16> & val);
/// Prepares an Int16 deque.
virtual void prepare(std::size_t pos, const std::list<Poco::Int16>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::Int16> & val);
/// Prepares an Int16 list.
virtual void prepare(std::size_t pos, const Poco::UInt16&) = 0;
virtual void prepare(std::size_t pos, const Poco::UInt16 &) = 0;
/// Prepares an UInt16.
virtual void prepare(std::size_t pos, const std::vector<Poco::UInt16>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::UInt16> & val);
/// Prepares an UInt16 vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::UInt16>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::UInt16> & val);
/// Prepares an UInt16 deque.
virtual void prepare(std::size_t pos, const std::list<Poco::UInt16>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::UInt16> & val);
/// Prepares an UInt16 list.
virtual void prepare(std::size_t pos, const Poco::Int32&) = 0;
virtual void prepare(std::size_t pos, const Poco::Int32 &) = 0;
/// Prepares an Int32.
virtual void prepare(std::size_t pos, const std::vector<Poco::Int32>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::Int32> & val);
/// Prepares an Int32 vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::Int32>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::Int32> & val);
/// Prepares an Int32 deque.
virtual void prepare(std::size_t pos, const std::list<Poco::Int32>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::Int32> & val);
/// Prepares an Int32 list.
virtual void prepare(std::size_t pos, const Poco::UInt32&) = 0;
virtual void prepare(std::size_t pos, const Poco::UInt32 &) = 0;
/// Prepares an UInt32.
virtual void prepare(std::size_t pos, const std::vector<Poco::UInt32>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::UInt32> & val);
/// Prepares an UInt32 vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::UInt32>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::UInt32> & val);
/// Prepares an UInt32 deque.
virtual void prepare(std::size_t pos, const std::list<Poco::UInt32>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::UInt32> & val);
/// Prepares an UInt32 list.
virtual void prepare(std::size_t pos, const Poco::Int64&) = 0;
virtual void prepare(std::size_t pos, const Poco::Int64 &) = 0;
/// Prepares an Int64.
virtual void prepare(std::size_t pos, const std::vector<Poco::Int64>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::Int64> & val);
/// Prepares an Int64 vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::Int64>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::Int64> & val);
/// Prepares an Int64 deque.
virtual void prepare(std::size_t pos, const std::list<Poco::Int64>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::Int64> & val);
/// Prepares an Int64 list.
virtual void prepare(std::size_t pos, const Poco::UInt64&) = 0;
virtual void prepare(std::size_t pos, const Poco::UInt64 &) = 0;
/// Prepares an UInt64.
virtual void prepare(std::size_t pos, const std::vector<Poco::UInt64>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::UInt64> & val);
/// Prepares an UInt64 vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::UInt64>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::UInt64> & val);
/// Prepares an UInt64 deque.
virtual void prepare(std::size_t pos, const std::list<Poco::UInt64>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::UInt64> & val);
/// Prepares an UInt64 list.
#ifndef POCO_LONG_IS_64_BIT
virtual void prepare(std::size_t pos, const long&) = 0;
virtual void prepare(std::size_t pos, const long &) = 0;
/// Prepares a long.
virtual void prepare(std::size_t pos, const unsigned long&) = 0;
virtual void prepare(std::size_t pos, const unsigned long &) = 0;
/// Prepares an unsigned long.
virtual void prepare(std::size_t pos, const std::vector<long>& val);
virtual void prepare(std::size_t pos, const std::vector<long> & val);
/// Prepares a long vector.
virtual void prepare(std::size_t pos, const std::deque<long>& val);
virtual void prepare(std::size_t pos, const std::deque<long> & val);
/// Prepares a long deque.
virtual void prepare(std::size_t pos, const std::list<long>& val);
virtual void prepare(std::size_t pos, const std::list<long> & val);
/// Prepares a long list.
#endif
virtual void prepare(std::size_t pos, const bool&) = 0;
virtual void prepare(std::size_t pos, const bool &) = 0;
/// Prepares a boolean.
virtual void prepare(std::size_t pos, const std::vector<bool>& val);
virtual void prepare(std::size_t pos, const std::vector<bool> & val);
/// Prepares a boolean vector.
virtual void prepare(std::size_t pos, const std::deque<bool>& val);
virtual void prepare(std::size_t pos, const std::deque<bool> & val);
/// Prepares a boolean deque.
virtual void prepare(std::size_t pos, const std::list<bool>& val);
virtual void prepare(std::size_t pos, const std::list<bool> & val);
/// Prepares a boolean list.
virtual void prepare(std::size_t pos, const float&) = 0;
virtual void prepare(std::size_t pos, const float &) = 0;
/// Prepares a float.
virtual void prepare(std::size_t pos, const std::vector<float>& val);
virtual void prepare(std::size_t pos, const std::vector<float> & val);
/// Prepares a float vector.
virtual void prepare(std::size_t pos, const std::deque<float>& val);
virtual void prepare(std::size_t pos, const std::deque<float> & val);
/// Prepares a float deque.
virtual void prepare(std::size_t pos, const std::list<float>& val);
virtual void prepare(std::size_t pos, const std::list<float> & val);
/// Prepares a float list.
virtual void prepare(std::size_t pos, const double&) = 0;
virtual void prepare(std::size_t pos, const double &) = 0;
/// Prepares a double.
virtual void prepare(std::size_t pos, const std::vector<double>& val);
virtual void prepare(std::size_t pos, const std::vector<double> & val);
/// Prepares a double vector.
virtual void prepare(std::size_t pos, const std::deque<double>& val);
virtual void prepare(std::size_t pos, const std::deque<double> & val);
/// Prepares a double deque.
virtual void prepare(std::size_t pos, const std::list<double>& val);
virtual void prepare(std::size_t pos, const std::list<double> & val);
/// Prepares a double list.
virtual void prepare(std::size_t pos, const char&) = 0;
virtual void prepare(std::size_t pos, const char &) = 0;
/// Prepares a single character.
virtual void prepare(std::size_t pos, const std::vector<char>& val);
virtual void prepare(std::size_t pos, const std::vector<char> & val);
/// Prepares a character vector.
virtual void prepare(std::size_t pos, const std::deque<char>& val);
virtual void prepare(std::size_t pos, const std::deque<char> & val);
/// Prepares a character deque.
virtual void prepare(std::size_t pos, const std::list<char>& val);
virtual void prepare(std::size_t pos, const std::list<char> & val);
/// Prepares a character list.
virtual void prepare(std::size_t pos, const std::string&) = 0;
virtual void prepare(std::size_t pos, const std::string &) = 0;
/// Prepares a string.
virtual void prepare(std::size_t pos, const std::vector<std::string>& val);
virtual void prepare(std::size_t pos, const std::vector<std::string> & val);
/// Prepares a string vector.
virtual void prepare(std::size_t pos, const std::deque<std::string>& val);
virtual void prepare(std::size_t pos, const std::deque<std::string> & val);
/// Prepares a string deque.
virtual void prepare(std::size_t pos, const std::list<std::string>& val);
virtual void prepare(std::size_t pos, const std::list<std::string> & val);
/// Prepares a character list.
virtual void prepare(std::size_t pos, const UTF16String&);
virtual void prepare(std::size_t pos, const UTF16String &);
/// Prepares a UTF16String.
virtual void prepare(std::size_t pos, const std::vector<UTF16String>& val);
virtual void prepare(std::size_t pos, const std::vector<UTF16String> & val);
/// Prepares a UTF16String vector.
virtual void prepare(std::size_t pos, const std::deque<UTF16String>& val);
virtual void prepare(std::size_t pos, const std::deque<UTF16String> & val);
/// Prepares a UTF16String deque.
virtual void prepare(std::size_t pos, const std::list<UTF16String>& val);
virtual void prepare(std::size_t pos, const std::list<UTF16String> & val);
/// Prepares a UTF16String list.
virtual void prepare(std::size_t pos, const BLOB&) = 0;
virtual void prepare(std::size_t pos, const BLOB &) = 0;
/// Prepares a BLOB.
virtual void prepare(std::size_t pos, const CLOB&) = 0;
virtual void prepare(std::size_t pos, const CLOB &) = 0;
/// Prepares a CLOB.
virtual void prepare(std::size_t pos, const std::vector<BLOB>& val);
virtual void prepare(std::size_t pos, const std::vector<BLOB> & val);
/// Prepares a BLOB vector.
virtual void prepare(std::size_t pos, const std::deque<BLOB>& val);
virtual void prepare(std::size_t pos, const std::deque<BLOB> & val);
/// Prepares a BLOB deque.
virtual void prepare(std::size_t pos, const std::list<BLOB>& val);
virtual void prepare(std::size_t pos, const std::list<BLOB> & val);
/// Prepares a BLOB list.
virtual void prepare(std::size_t pos, const std::vector<CLOB>& val);
virtual void prepare(std::size_t pos, const std::vector<CLOB> & val);
/// Prepares a CLOB vector.
virtual void prepare(std::size_t pos, const std::deque<CLOB>& val);
virtual void prepare(std::size_t pos, const std::deque<CLOB> & val);
/// Prepares a CLOB deque.
virtual void prepare(std::size_t pos, const std::list<CLOB>& val);
virtual void prepare(std::size_t pos, const std::list<CLOB> & val);
/// Prepares a CLOB list.
virtual void prepare(std::size_t pos, const DateTime&) = 0;
virtual void prepare(std::size_t pos, const DateTime &) = 0;
/// Prepares a DateTime.
virtual void prepare(std::size_t pos, const std::vector<DateTime>& val);
virtual void prepare(std::size_t pos, const std::vector<DateTime> & val);
/// Prepares a DateTime vector.
virtual void prepare(std::size_t pos, const std::deque<DateTime>& val);
virtual void prepare(std::size_t pos, const std::deque<DateTime> & val);
/// Prepares a DateTime deque.
virtual void prepare(std::size_t pos, const std::list<DateTime>& val);
virtual void prepare(std::size_t pos, const std::list<DateTime> & val);
/// Prepares a DateTime list.
virtual void prepare(std::size_t pos, const Date&) = 0;
virtual void prepare(std::size_t pos, const Date &) = 0;
/// Prepares a Date.
virtual void prepare(std::size_t pos, const std::vector<Date>& val);
virtual void prepare(std::size_t pos, const std::vector<Date> & val);
/// Prepares a Date vector.
virtual void prepare(std::size_t pos, const std::deque<Date>& val);
virtual void prepare(std::size_t pos, const std::deque<Date> & val);
/// Prepares a Date deque.
virtual void prepare(std::size_t pos, const std::list<Date>& val);
virtual void prepare(std::size_t pos, const std::list<Date> & val);
/// Prepares a Date list.
virtual void prepare(std::size_t pos, const Time&) = 0;
virtual void prepare(std::size_t pos, const Time &) = 0;
/// Prepares a Time.
virtual void prepare(std::size_t pos, const std::vector<Time>& val);
virtual void prepare(std::size_t pos, const std::vector<Time> & val);
/// Prepares a Time vector.
virtual void prepare(std::size_t pos, const std::deque<Time>& val);
virtual void prepare(std::size_t pos, const std::deque<Time> & val);
/// Prepares a Time deque.
virtual void prepare(std::size_t pos, const std::list<Time>& val);
virtual void prepare(std::size_t pos, const std::list<Time> & val);
/// Prepares a Time list.
virtual void prepare(std::size_t pos, const Any&) = 0;
virtual void prepare(std::size_t pos, const Any &) = 0;
/// Prepares an Any.
virtual void prepare(std::size_t pos, const std::vector<Any>& val);
virtual void prepare(std::size_t pos, const std::vector<Any> & val);
/// Prepares an Any vector.
virtual void prepare(std::size_t pos, const std::deque<Any>& val);
virtual void prepare(std::size_t pos, const std::deque<Any> & val);
/// Prepares an Any deque.
virtual void prepare(std::size_t pos, const std::list<Any>& val);
virtual void prepare(std::size_t pos, const std::list<Any> & val);
/// Prepares an Any list.
virtual void prepare(std::size_t pos, const Poco::Dynamic::Var&) = 0;
virtual void prepare(std::size_t pos, const Poco::Dynamic::Var &) = 0;
/// Prepares a Var.
virtual void prepare(std::size_t pos, const std::vector<Poco::Dynamic::Var>& val);
virtual void prepare(std::size_t pos, const std::vector<Poco::Dynamic::Var> & val);
/// Prepares a Var vector.
virtual void prepare(std::size_t pos, const std::deque<Poco::Dynamic::Var>& val);
virtual void prepare(std::size_t pos, const std::deque<Poco::Dynamic::Var> & val);
/// Prepares a Var deque.
virtual void prepare(std::size_t pos, const std::list<Poco::Dynamic::Var>& val);
virtual void prepare(std::size_t pos, const std::list<Poco::Dynamic::Var> & val);
/// Prepares a Var list.
void setLength(Poco::UInt32 length);
@ -349,40 +352,41 @@ public:
bool isBulk() const;
/// Returns bulk operation flag.
private:
private:
Poco::UInt32 _length;
bool _bulk;
};
};
///
/// inlines
///
inline void AbstractPreparator::setLength(Poco::UInt32 length)
{
///
/// inlines
///
inline void AbstractPreparator::setLength(Poco::UInt32 length)
{
_length = length;
}
}
inline Poco::UInt32 AbstractPreparator::getLength() const
{
inline Poco::UInt32 AbstractPreparator::getLength() const
{
return _length;
}
}
inline void AbstractPreparator::setBulk(bool bulkPrep)
{
inline void AbstractPreparator::setBulk(bool bulkPrep)
{
_bulk = bulkPrep;
}
}
inline bool AbstractPreparator::isBulk() const
{
inline bool AbstractPreparator::isBulk() const
{
return _bulk;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_AbstractPreparator_INCLUDED

View File

@ -18,44 +18,46 @@
#define Data_AbstractSessionImpl_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/SessionImpl.h"
#include "Poco/Data/DataException.h"
#include <map>
#include "Poco/Data/Data.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/SessionImpl.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
template <class C>
class AbstractSessionImpl: public SessionImpl
template <class C>
class AbstractSessionImpl : public SessionImpl
/// A partial implementation of SessionImpl, providing
/// features and properties management.
///
/// To implement a certain feature or property, a subclass
/// must provide setter and getter methods and register
/// them with addFeature() or addProperty().
{
public:
typedef void (C::*FeatureSetter)(const std::string&, bool);
{
public:
typedef void (C::*FeatureSetter)(const std::string &, bool);
/// The setter method for a feature.
typedef bool (C::*FeatureGetter)(const std::string&);
typedef bool (C::*FeatureGetter)(const std::string &);
/// The getter method for a feature.
typedef void (C::*PropertySetter)(const std::string&, const Poco::Any&);
typedef void (C::*PropertySetter)(const std::string &, const Poco::Any &);
/// The setter method for a property.
typedef Poco::Any (C::*PropertyGetter)(const std::string&);
typedef Poco::Any (C::*PropertyGetter)(const std::string &);
/// The getter method for a property.
AbstractSessionImpl(const std::string& connectionString,
std::size_t timeout = LOGIN_TIMEOUT_DEFAULT): SessionImpl(connectionString, timeout),
_storage(std::string("deque")),
_bulk(false),
_emptyStringIsNull(false),
_forceEmptyString(false)
AbstractSessionImpl(const std::string & connectionString, std::size_t timeout = LOGIN_TIMEOUT_DEFAULT)
: SessionImpl(connectionString, timeout)
, _storage(std::string("deque"))
, _bulk(false)
, _emptyStringIsNull(false)
, _forceEmptyString(false)
/// Creates the AbstractSessionImpl.
///
/// Adds "storage" property and sets the default internal storage container
@ -89,25 +91,15 @@ public:
/// resulting in default underlying database behavior.
///
{
addProperty("storage",
&AbstractSessionImpl<C>::setStorage,
&AbstractSessionImpl<C>::getStorage);
addProperty("storage", &AbstractSessionImpl<C>::setStorage, &AbstractSessionImpl<C>::getStorage);
addProperty("handle",
&AbstractSessionImpl<C>::setHandle,
&AbstractSessionImpl<C>::getHandle);
addProperty("handle", &AbstractSessionImpl<C>::setHandle, &AbstractSessionImpl<C>::getHandle);
addFeature("bulk",
&AbstractSessionImpl<C>::setBulk,
&AbstractSessionImpl<C>::getBulk);
addFeature("bulk", &AbstractSessionImpl<C>::setBulk, &AbstractSessionImpl<C>::getBulk);
addFeature("emptyStringIsNull",
&AbstractSessionImpl<C>::setEmptyStringIsNull,
&AbstractSessionImpl<C>::getEmptyStringIsNull);
addFeature("emptyStringIsNull", &AbstractSessionImpl<C>::setEmptyStringIsNull, &AbstractSessionImpl<C>::getEmptyStringIsNull);
addFeature("forceEmptyString",
&AbstractSessionImpl<C>::setForceEmptyString,
&AbstractSessionImpl<C>::getForceEmptyString);
addFeature("forceEmptyString", &AbstractSessionImpl<C>::setForceEmptyString, &AbstractSessionImpl<C>::getForceEmptyString);
}
~AbstractSessionImpl()
@ -115,7 +107,7 @@ public:
{
}
void setFeature(const std::string& name, bool state)
void setFeature(const std::string & name, bool state)
/// Looks a feature up in the features map
/// and calls the feature's setter, if there is one.
{
@ -123,14 +115,15 @@ public:
if (it != _features.end())
{
if (it->second.setter)
(static_cast<C*>(this)->*it->second.setter)(name, state);
(static_cast<C *>(this)->*it->second.setter)(name, state);
else
throw NotImplementedException("set", name);
}
else throw NotSupportedException(name);
else
throw NotSupportedException(name);
}
bool getFeature(const std::string& name)
bool getFeature(const std::string & name)
/// Looks a feature up in the features map
/// and calls the feature's getter, if there is one.
{
@ -138,14 +131,15 @@ public:
if (it != _features.end())
{
if (it->second.getter)
return (static_cast<C*>(this)->*it->second.getter)(name);
return (static_cast<C *>(this)->*it->second.getter)(name);
else
throw NotImplementedException("get", name);
}
else throw NotSupportedException(name);
else
throw NotSupportedException(name);
}
void setProperty(const std::string& name, const Poco::Any& value)
void setProperty(const std::string & name, const Poco::Any & value)
/// Looks a property up in the properties map
/// and calls the property's setter, if there is one.
{
@ -153,14 +147,15 @@ public:
if (it != _properties.end())
{
if (it->second.setter)
(static_cast<C*>(this)->*it->second.setter)(name, value);
(static_cast<C *>(this)->*it->second.setter)(name, value);
else
throw NotImplementedException("set", name);
}
else throw NotSupportedException(name);
else
throw NotSupportedException(name);
}
Poco::Any getProperty(const std::string& name)
Poco::Any getProperty(const std::string & name)
/// Looks a property up in the properties map
/// and calls the property's getter, if there is one.
{
@ -168,56 +163,57 @@ public:
if (it != _properties.end())
{
if (it->second.getter)
return (static_cast<C*>(this)->*it->second.getter)(name);
return (static_cast<C *>(this)->*it->second.getter)(name);
else
throw NotImplementedException("set", name);
}
else throw NotSupportedException(name);
else
throw NotSupportedException(name);
}
void setStorage(const std::string& value)
void setStorage(const std::string & value)
/// Sets the storage type.
{
_storage = value;
}
void setStorage(const std::string& name, const Poco::Any& value)
void setStorage(const std::string & name, const Poco::Any & value)
/// Sets the storage type.
{
_storage = Poco::RefAnyCast<std::string>(value);
}
Poco::Any getStorage(const std::string& name="")
Poco::Any getStorage(const std::string & name = "")
/// Returns the storage type
{
return _storage;
}
void setHandle(const std::string& name, const Poco::Any& handle)
void setHandle(const std::string & name, const Poco::Any & handle)
/// Sets the native session handle.
{
_handle = handle;
}
Poco::Any getHandle(const std::string& name="")
Poco::Any getHandle(const std::string & name = "")
/// Returns the native session handle.
{
return _handle;
}
void setBulk(const std::string& name, bool bulk)
void setBulk(const std::string & name, bool bulk)
/// Sets the execution type.
{
_bulk = bulk;
}
bool getBulk(const std::string& name="")
bool getBulk(const std::string & name = "")
/// Returns the execution type
{
return _bulk;
}
void setEmptyStringIsNull(const std::string& name, bool emptyStringIsNull)
void setEmptyStringIsNull(const std::string & name, bool emptyStringIsNull)
/// Sets the behavior regarding empty variable length strings.
/// Those are treated as NULL by Oracle and as empty string by
/// most other databases.
@ -229,7 +225,7 @@ public:
_emptyStringIsNull = emptyStringIsNull;
}
bool getEmptyStringIsNull(const std::string& name="")
bool getEmptyStringIsNull(const std::string & name = "")
/// Returns the setting for the behavior regarding empty variable
/// length strings. See setEmptyStringIsNull(const std::string&, bool)
/// and this class documentation for feature rationale and details.
@ -237,7 +233,7 @@ public:
return _emptyStringIsNull;
}
void setForceEmptyString(const std::string& name, bool forceEmptyString)
void setForceEmptyString(const std::string & name, bool forceEmptyString)
/// Sets the behavior regarding empty variable length strings.
/// Those are treated as NULL by Oracle and as empty string by
/// most other databases.
@ -250,7 +246,7 @@ public:
_forceEmptyString = forceEmptyString;
}
bool getForceEmptyString(const std::string& name="")
bool getForceEmptyString(const std::string & name = "")
/// Returns the setting for the behavior regarding empty variable
/// length strings. See setForceEmptyString(const std::string&, bool)
/// and this class documentation for feature rationale and details.
@ -258,8 +254,8 @@ public:
return _forceEmptyString;
}
protected:
void addFeature(const std::string& name, FeatureSetter setter, FeatureGetter getter)
protected:
void addFeature(const std::string & name, FeatureSetter setter, FeatureGetter getter)
/// Adds a feature to the map of supported features.
///
/// The setter or getter can be null, in case setting or getting a feature
@ -271,7 +267,7 @@ protected:
_features[name] = feature;
}
void addProperty(const std::string& name, PropertySetter setter, PropertyGetter getter)
void addProperty(const std::string & name, PropertySetter setter, PropertyGetter getter)
/// Adds a property to the map of supported properties.
///
/// The setter or getter can be null, in case setting or getting a property
@ -283,7 +279,7 @@ protected:
_properties[name] = property;
}
private:
private:
struct Feature
{
FeatureSetter setter;
@ -306,10 +302,11 @@ private:
bool _emptyStringIsNull;
bool _forceEmptyString;
Poco::Any _handle;
};
};
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_AbstractSessionImpl_INCLUDED

View File

@ -21,25 +21,28 @@
#include "Poco/Data/Data.h"
#include "Poco/Data/Session.h"
#include "Poco/DateTime.h"
#include "Poco/Timespan.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/SharedPtr.h"
#include "Poco/Timespan.h"
namespace Poco {
namespace Data {
class Data_API ArchiveStrategy
/// The ArchiveStrategy is used by SQLChannel to archive log rows.
namespace Poco
{
public:
namespace Data
{
class Data_API ArchiveStrategy
/// The ArchiveStrategy is used by SQLChannel to archive log rows.
{
public:
static const std::string DEFAULT_ARCHIVE_DESTINATION;
ArchiveStrategy(const std::string& connector,
const std::string& connect,
const std::string& source,
const std::string& destination = DEFAULT_ARCHIVE_DESTINATION);
ArchiveStrategy(
const std::string & connector,
const std::string & connect,
const std::string & source,
const std::string & destination = DEFAULT_ARCHIVE_DESTINATION);
/// Creates archive strategy.
virtual ~ArchiveStrategy();
@ -51,42 +54,42 @@ public:
virtual void archive() = 0;
/// Archives the rows.
const std::string& getSource() const;
const std::string & getSource() const;
/// Returns the name of the source table containing rows to be archived.
void setSource(const std::string& source);
void setSource(const std::string & source);
/// Sets the name of the source table.
const std::string& getDestination() const;
const std::string & getDestination() const;
/// Returns the name of the destination table for rows to be archived.
void setDestination(const std::string& destination);
void setDestination(const std::string & destination);
/// Sets the name of the destination table.
virtual const std::string& getThreshold() const = 0;
virtual const std::string & getThreshold() const = 0;
/// Returns the archive threshold.
virtual void setThreshold(const std::string& threshold) = 0;
virtual void setThreshold(const std::string & threshold) = 0;
/// Sets the archive threshold.
protected:
protected:
typedef Poco::SharedPtr<Session> SessionPtr;
typedef Poco::SharedPtr<Statement> StatementPtr;
Session& session();
Session & session();
void setCopyStatement();
void setDeleteStatement();
void setCountStatement();
Statement& getCopyStatement();
Statement& getDeleteStatement();
Statement& getCountStatement();
private:
Statement & getCopyStatement();
Statement & getDeleteStatement();
Statement & getCountStatement();
private:
ArchiveStrategy();
ArchiveStrategy(const ArchiveStrategy&);
ArchiveStrategy& operator = (const ArchiveStrategy&);
ArchiveStrategy(const ArchiveStrategy &);
ArchiveStrategy & operator=(const ArchiveStrategy &);
std::string _connector;
std::string _connect;
@ -96,106 +99,106 @@ private:
StatementPtr _pCountStatement;
std::string _source;
std::string _destination;
};
};
//
// inlines
//
//
// inlines
//
inline const std::string& ArchiveStrategy::getSource() const
{
inline const std::string & ArchiveStrategy::getSource() const
{
return _source;
}
}
inline void ArchiveStrategy::setSource(const std::string& source)
{
inline void ArchiveStrategy::setSource(const std::string & source)
{
_source = source;
}
}
inline void ArchiveStrategy::setDestination(const std::string& destination)
{
inline void ArchiveStrategy::setDestination(const std::string & destination)
{
_destination = destination;
}
}
inline const std::string& ArchiveStrategy::getDestination() const
{
inline const std::string & ArchiveStrategy::getDestination() const
{
return _destination;
}
}
inline Session& ArchiveStrategy::session()
{
inline Session & ArchiveStrategy::session()
{
return *_pSession;
}
}
inline void ArchiveStrategy::setCopyStatement()
{
inline void ArchiveStrategy::setCopyStatement()
{
_pCopyStatement = new Statement(*_pSession);
}
}
inline void ArchiveStrategy::setDeleteStatement()
{
inline void ArchiveStrategy::setDeleteStatement()
{
_pDeleteStatement = new Statement(*_pSession);
}
}
inline void ArchiveStrategy::setCountStatement()
{
inline void ArchiveStrategy::setCountStatement()
{
_pCountStatement = new Statement(*_pSession);
}
}
inline Statement& ArchiveStrategy::getCopyStatement()
{
inline Statement & ArchiveStrategy::getCopyStatement()
{
return *_pCopyStatement;
}
}
inline Statement& ArchiveStrategy::getDeleteStatement()
{
inline Statement & ArchiveStrategy::getDeleteStatement()
{
return *_pDeleteStatement;
}
}
inline Statement& ArchiveStrategy::getCountStatement()
{
inline Statement & ArchiveStrategy::getCountStatement()
{
return *_pCountStatement;
}
}
//
// ArchiveByAgeStrategy
//
class Data_API ArchiveByAgeStrategy: public ArchiveStrategy
//
// ArchiveByAgeStrategy
//
class Data_API ArchiveByAgeStrategy : public ArchiveStrategy
/// Archives rows scheduled for archiving.
{
public:
ArchiveByAgeStrategy(const std::string& connector,
const std::string& connect,
const std::string& sourceTable,
const std::string& destinationTable = DEFAULT_ARCHIVE_DESTINATION);
{
public:
ArchiveByAgeStrategy(
const std::string & connector,
const std::string & connect,
const std::string & sourceTable,
const std::string & destinationTable = DEFAULT_ARCHIVE_DESTINATION);
~ArchiveByAgeStrategy();
void archive();
const std::string& getThreshold() const;
const std::string & getThreshold() const;
/// Returns the archive threshold.
void setThreshold(const std::string& threshold);
void setThreshold(const std::string & threshold);
/// Sets the archive threshold.
private:
private:
ArchiveByAgeStrategy();
ArchiveByAgeStrategy(const ArchiveByAgeStrategy&);
ArchiveByAgeStrategy& operator = (const ArchiveByAgeStrategy&);
ArchiveByAgeStrategy(const ArchiveByAgeStrategy &);
ArchiveByAgeStrategy & operator=(const ArchiveByAgeStrategy &);
void initStatements();
@ -203,20 +206,21 @@ private:
std::string _ageString;
DateTime _archiveDateTime;
Poco::Dynamic::Var _archiveCount;
};
};
//
// inlines
//
//
// inlines
//
inline const std::string& ArchiveByAgeStrategy::getThreshold() const
{
inline const std::string & ArchiveByAgeStrategy::getThreshold() const
{
return _ageString;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_ArchiveStrategy_INCLUDED

View File

@ -14,7 +14,6 @@
//
#ifndef Data_AutoTransaction_INCLUDED
#define Data_AutoTransaction_INCLUDED
@ -22,14 +21,17 @@
#include "Poco/Data/Transaction.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
typedef Transaction AutoTransaction;
typedef Transaction AutoTransaction;
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_AutoTransaction_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@ -18,18 +18,20 @@
#define Data_Bulk_INCLUDED
#include "Poco/Void.h"
#include "Poco/Data/Limit.h"
#include "Poco/Void.h"
namespace Poco {
namespace Data {
class Data_API Bulk
namespace Poco
{
public:
Bulk(const Limit& limit);
namespace Data
{
class Data_API Bulk
{
public:
Bulk(const Limit & limit);
/// Creates the Bulk.
Bulk(Poco::UInt32 value);
@ -38,59 +40,61 @@ public:
~Bulk();
/// Destroys the bulk.
const Limit& limit() const;
const Limit & limit() const;
/// Returns the limit associated with this bulk object.
Poco::UInt32 size() const;
/// Returns the value of the limit associated with
/// this bulk object.
private:
private:
Bulk();
Limit _limit;
};
};
///
/// inlines
///
inline const Limit& Bulk::limit() const
{
///
/// inlines
///
inline const Limit & Bulk::limit() const
{
return _limit;
}
}
inline Poco::UInt32 Bulk::size() const
{
inline Poco::UInt32 Bulk::size() const
{
return _limit.value();
}
}
namespace Keywords {
namespace Keywords
{
inline Bulk bulk(const Limit& limit = Limit(Limit::LIMIT_UNLIMITED, false, false))
inline Bulk bulk(const Limit & limit = Limit(Limit::LIMIT_UNLIMITED, false, false))
/// Convenience function for creation of bulk.
{
{
return Bulk(limit);
}
}
inline void bulk(Void)
inline void bulk(Void)
/// Dummy bulk function. Used for bulk binding creation
/// (see BulkBinding) and bulk extraction signalling to Statement.
{
{
}
} // namespace Keywords
typedef void (*BulkFnType)(Void);
}
} // namespace Keywords
typedef void (*BulkFnType)(Void);
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_Bulk_INCLUDED

View File

@ -18,31 +18,31 @@
#define Data_BulkBinding_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/AbstractBinding.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/TypeHandler.h"
#include "Poco/Data/Bulk.h"
#include <vector>
#include <cstddef>
#include <deque>
#include <list>
#include <cstddef>
#include <vector>
#include "Poco/Data/AbstractBinding.h"
#include "Poco/Data/Bulk.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/TypeHandler.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
template <class T>
class BulkBinding: public AbstractBinding
template <class T>
class BulkBinding : public AbstractBinding
/// A BulkBinding maps a value to a column.
/// Bulk binding support is provided only for std::vector.
{
public:
BulkBinding(const T& val, Poco::UInt32 bulkSize, const std::string& name = "", Direction direction = PD_IN):
AbstractBinding(name, direction, bulkSize),
_val(val),
_bound(false)
{
public:
BulkBinding(const T & val, Poco::UInt32 bulkSize, const std::string & name = "", Direction direction = PD_IN)
: AbstractBinding(name, direction, bulkSize), _val(val), _bound(false)
/// Creates the BulkBinding.
{
if (0 == _val.size())
@ -54,20 +54,11 @@ public:
{
}
std::size_t numOfColumnsHandled() const
{
return 1;
}
std::size_t numOfColumnsHandled() const { return 1; }
std::size_t numOfRowsHandled() const
{
return _val.size();
}
std::size_t numOfRowsHandled() const { return _val.size(); }
bool canBind() const
{
return !_bound;
}
bool canBind() const { return !_bound; }
void bind(std::size_t pos)
{
@ -76,73 +67,75 @@ public:
_bound = true;
}
void reset ()
void reset()
{
_bound = false;
getBinder()->reset();
}
private:
const T& _val;
private:
const T & _val;
bool _bound;
};
};
namespace Keywords {
namespace Keywords
{
template <typename T>
AbstractBinding::Ptr use(const std::vector<T>& t, BulkFnType, const std::string& name = "")
template <typename T>
AbstractBinding::Ptr use(const std::vector<T> & t, BulkFnType, const std::string & name = "")
/// Convenience function for a more compact BulkBinding creation for std::vector.
{
return new BulkBinding<std::vector<T> >(t, static_cast<Poco::UInt32>(t.size()), name);
}
{
return new BulkBinding<std::vector<T>>(t, static_cast<Poco::UInt32>(t.size()), name);
}
template <typename T>
AbstractBinding::Ptr in(const std::vector<T>& t, BulkFnType, const std::string& name = "")
template <typename T>
AbstractBinding::Ptr in(const std::vector<T> & t, BulkFnType, const std::string & name = "")
/// Convenience function for a more compact BulkBinding creation for std::vector.
{
return new BulkBinding<std::vector<T> >(t, static_cast<Poco::UInt32>(t.size()), name);
}
{
return new BulkBinding<std::vector<T>>(t, static_cast<Poco::UInt32>(t.size()), name);
}
template <typename T>
AbstractBinding::Ptr use(const std::deque<T>& t, BulkFnType, const std::string& name = "")
template <typename T>
AbstractBinding::Ptr use(const std::deque<T> & t, BulkFnType, const std::string & name = "")
/// Convenience function for a more compact BulkBinding creation for std::deque.
{
return new BulkBinding<std::deque<T> >(t, static_cast<Poco::UInt32>(t.size()), name);
}
{
return new BulkBinding<std::deque<T>>(t, static_cast<Poco::UInt32>(t.size()), name);
}
template <typename T>
AbstractBinding::Ptr in(const std::deque<T>& t, BulkFnType, const std::string& name = "")
template <typename T>
AbstractBinding::Ptr in(const std::deque<T> & t, BulkFnType, const std::string & name = "")
/// Convenience function for a more compact BulkBinding creation for std::deque.
{
return new BulkBinding<std::deque<T> >(t, static_cast<Poco::UInt32>(t.size()), name);
}
{
return new BulkBinding<std::deque<T>>(t, static_cast<Poco::UInt32>(t.size()), name);
}
template <typename T>
AbstractBinding::Ptr use(const std::list<T>& t, BulkFnType, const std::string& name = "")
template <typename T>
AbstractBinding::Ptr use(const std::list<T> & t, BulkFnType, const std::string & name = "")
/// Convenience function for a more compact BulkBinding creation for std::list.
{
return new BulkBinding<std::list<T> >(t, static_cast<Poco::UInt32>(t.size()), name);
}
{
return new BulkBinding<std::list<T>>(t, static_cast<Poco::UInt32>(t.size()), name);
}
template <typename T>
AbstractBinding::Ptr in(const std::list<T>& t, BulkFnType, const std::string& name = "")
template <typename T>
AbstractBinding::Ptr in(const std::list<T> & t, BulkFnType, const std::string & name = "")
/// Convenience function for a more compact BulkBinding creation for std::list.
{
return new BulkBinding<std::list<T> >(t, static_cast<Poco::UInt32>(t.size()), name);
{
return new BulkBinding<std::list<T>>(t, static_cast<Poco::UInt32>(t.size()), name);
}
} // namespace Keywords
}
} // namespace Keywords
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_BulkBinding_INCLUDED

View File

@ -18,68 +18,57 @@
#define Data_BulkExtraction_INCLUDED
#include "Poco/Data/Data.h"
#include <vector>
#include "Poco/Data/AbstractExtraction.h"
#include "Poco/Data/Bulk.h"
#include "Poco/Data/Column.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/Position.h"
#include "Poco/Data/Preparation.h"
#include <vector>
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
template <class C>
class BulkExtraction: public AbstractExtraction
template <class C>
class BulkExtraction : public AbstractExtraction
/// Specialization for bulk extraction of values from a query result set.
/// Bulk extraction support is provided only for following STL containers:
/// - std::vector
/// - std::deque
/// - std::list
{
public:
{
public:
typedef C ValType;
typedef typename C::value_type CValType;
typedef SharedPtr<ValType> ValPtr;
typedef BulkExtraction<ValType> Type;
typedef SharedPtr<Type> Ptr;
BulkExtraction(C& result, Poco::UInt32 limit, const Position& pos = Position(0)):
AbstractExtraction(limit, pos.value(), true),
_rResult(result),
_default()
BulkExtraction(C & result, Poco::UInt32 limit, const Position & pos = Position(0))
: AbstractExtraction(limit, pos.value(), true), _rResult(result), _default()
{
if (static_cast<Poco::UInt32>(result.size()) != limit)
result.resize(limit);
}
BulkExtraction(C& result, const CValType& def, Poco::UInt32 limit, const Position& pos = Position(0)):
AbstractExtraction(limit, pos.value(), true),
_rResult(result),
_default(def)
BulkExtraction(C & result, const CValType & def, Poco::UInt32 limit, const Position & pos = Position(0))
: AbstractExtraction(limit, pos.value(), true), _rResult(result), _default(def)
{
if (static_cast<Poco::UInt32>(result.size()) != limit)
result.resize(limit);
}
virtual ~BulkExtraction()
{
}
virtual ~BulkExtraction() { }
std::size_t numOfColumnsHandled() const
{
return TypeHandler<C>::size();
}
std::size_t numOfColumnsHandled() const { return TypeHandler<C>::size(); }
std::size_t numOfRowsHandled() const
{
return _rResult.size();
}
std::size_t numOfRowsHandled() const { return _rResult.size(); }
std::size_t numOfRowsAllowed() const
{
return getLimit();
}
std::size_t numOfRowsAllowed() const { return getLimit(); }
bool isNull(std::size_t row) const
{
@ -87,7 +76,7 @@ public:
{
return _nulls.at(row);
}
catch (std::out_of_range& ex)
catch (std::out_of_range & ex)
{
throw RangeException(ex.what());
}
@ -99,7 +88,7 @@ public:
TypeHandler<C>::extract(col, _rResult, _default, pExt);
typename C::iterator it = _rResult.begin();
typename C::iterator end = _rResult.end();
for (int row = 0; it !=end; ++it, ++row)
for (int row = 0; it != end; ++it, ++row)
{
_nulls.push_back(isValueNull(*it, pExt->isNull(col, row)));
}
@ -107,34 +96,30 @@ public:
return _rResult.size();
}
virtual void reset()
{
}
virtual void reset() { }
AbstractPreparation::Ptr createPreparation(AbstractPreparator::Ptr& pPrep, std::size_t col)
AbstractPreparation::Ptr createPreparation(AbstractPreparator::Ptr & pPrep, std::size_t col)
{
Poco::UInt32 limit = getLimit();
if (limit != _rResult.size()) _rResult.resize(limit);
if (limit != _rResult.size())
_rResult.resize(limit);
pPrep->setLength(limit);
pPrep->setBulk(true);
return new Preparation<C>(pPrep, col, _rResult);
}
protected:
const C& result() const
{
return _rResult;
}
protected:
const C & result() const { return _rResult; }
private:
C& _rResult;
private:
C & _rResult;
CValType _default;
std::deque<bool> _nulls;
};
};
template <class C>
class InternalBulkExtraction: public BulkExtraction<C>
template <class C>
class InternalBulkExtraction : public BulkExtraction<C>
/// Container Data Type specialization extension for extraction of values from a query result set.
///
/// This class is intended for PocoData internal use - it is used by StatementImpl
@ -144,20 +129,16 @@ class InternalBulkExtraction: public BulkExtraction<C>
/// owns the data container pointer.
///
/// InternalBulkExtraction objects can not be copied or assigned.
{
public:
{
public:
typedef C ValType;
typedef typename C::value_type CValType;
typedef SharedPtr<ValType> ValPtr;
typedef InternalBulkExtraction<ValType> Type;
typedef SharedPtr<Type> Ptr;
InternalBulkExtraction(C& result,
Column<C>* pColumn,
Poco::UInt32 limit,
const Position& pos = Position(0)):
BulkExtraction<C>(result, CValType(), limit, pos),
_pColumn(pColumn)
InternalBulkExtraction(C & result, Column<C> * pColumn, Poco::UInt32 limit, const Position & pos = Position(0))
: BulkExtraction<C>(result, CValType(), limit, pos), _pColumn(pColumn)
/// Creates InternalBulkExtraction.
{
}
@ -168,109 +149,105 @@ public:
delete _pColumn;
}
void reset()
{
_pColumn->reset();
}
void reset() { _pColumn->reset(); }
const CValType& value(int index) const
const CValType & value(int index) const
{
try
{
return BulkExtraction<C>::result().at(index);
}
catch (std::out_of_range& ex)
catch (std::out_of_range & ex)
{
throw RangeException(ex.what());
}
}
bool isNull(std::size_t row) const
{
return BulkExtraction<C>::isNull(row);
}
bool isNull(std::size_t row) const { return BulkExtraction<C>::isNull(row); }
const Column<C>& column() const
{
return *_pColumn;
}
const Column<C> & column() const { return *_pColumn; }
private:
private:
InternalBulkExtraction();
InternalBulkExtraction(const InternalBulkExtraction&);
InternalBulkExtraction& operator = (const InternalBulkExtraction&);
InternalBulkExtraction(const InternalBulkExtraction &);
InternalBulkExtraction & operator=(const InternalBulkExtraction &);
Column<C>* _pColumn;
};
Column<C> * _pColumn;
};
namespace Keywords {
namespace Keywords
{
template <typename T>
AbstractExtraction::Ptr into(std::vector<T>& t, const Bulk& bulk, const Position& pos = Position(0))
template <typename T>
AbstractExtraction::Ptr into(std::vector<T> & t, const Bulk & bulk, const Position & pos = Position(0))
/// Convenience function to allow for a more compact creation of an extraction object
/// with std::vector bulk extraction support.
{
return new BulkExtraction<std::vector<T> >(t, bulk.size(), pos);
}
{
return new BulkExtraction<std::vector<T>>(t, bulk.size(), pos);
}
template <typename T>
AbstractExtraction::Ptr into(std::vector<T>& t, BulkFnType, const Position& pos = Position(0))
template <typename T>
AbstractExtraction::Ptr into(std::vector<T> & t, BulkFnType, const Position & pos = Position(0))
/// Convenience function to allow for a more compact creation of an extraction object
/// with std::vector bulk extraction support.
{
{
Poco::UInt32 size = static_cast<Poco::UInt32>(t.size());
if (0 == size) throw InvalidArgumentException("Zero length not allowed.");
return new BulkExtraction<std::vector<T> >(t, size, pos);
}
if (0 == size)
throw InvalidArgumentException("Zero length not allowed.");
return new BulkExtraction<std::vector<T>>(t, size, pos);
}
template <typename T>
AbstractExtraction::Ptr into(std::deque<T>& t, const Bulk& bulk, const Position& pos = Position(0))
template <typename T>
AbstractExtraction::Ptr into(std::deque<T> & t, const Bulk & bulk, const Position & pos = Position(0))
/// Convenience function to allow for a more compact creation of an extraction object
/// with std::deque bulk extraction support.
{
return new BulkExtraction<std::deque<T> >(t, bulk.size(), pos);
}
{
return new BulkExtraction<std::deque<T>>(t, bulk.size(), pos);
}
template <typename T>
AbstractExtraction::Ptr into(std::deque<T>& t, BulkFnType, const Position& pos = Position(0))
template <typename T>
AbstractExtraction::Ptr into(std::deque<T> & t, BulkFnType, const Position & pos = Position(0))
/// Convenience function to allow for a more compact creation of an extraction object
/// with std::deque bulk extraction support.
{
{
Poco::UInt32 size = static_cast<Poco::UInt32>(t.size());
if (0 == size) throw InvalidArgumentException("Zero length not allowed.");
return new BulkExtraction<std::deque<T> >(t, size, pos);
}
if (0 == size)
throw InvalidArgumentException("Zero length not allowed.");
return new BulkExtraction<std::deque<T>>(t, size, pos);
}
template <typename T>
AbstractExtraction::Ptr into(std::list<T>& t, const Bulk& bulk, const Position& pos = Position(0))
template <typename T>
AbstractExtraction::Ptr into(std::list<T> & t, const Bulk & bulk, const Position & pos = Position(0))
/// Convenience function to allow for a more compact creation of an extraction object
/// with std::list bulk extraction support.
{
return new BulkExtraction<std::list<T> >(t, bulk.size(), pos);
}
{
return new BulkExtraction<std::list<T>>(t, bulk.size(), pos);
}
template <typename T>
AbstractExtraction::Ptr into(std::list<T>& t, BulkFnType, const Position& pos = Position(0))
template <typename T>
AbstractExtraction::Ptr into(std::list<T> & t, BulkFnType, const Position & pos = Position(0))
/// Convenience function to allow for a more compact creation of an extraction object
/// with std::list bulk extraction support.
{
{
Poco::UInt32 size = static_cast<Poco::UInt32>(t.size());
if (0 == size) throw InvalidArgumentException("Zero length not allowed.");
return new BulkExtraction<std::list<T> >(t, size, pos);
if (0 == size)
throw InvalidArgumentException("Zero length not allowed.");
return new BulkExtraction<std::list<T>>(t, size, pos);
}
} // namespace Keywords
}
} // namespace Keywords
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_BulkExtraction_INCLUDED

View File

@ -18,27 +18,29 @@
#define Data_Column_INCLUDED
#include <deque>
#include <list>
#include <vector>
#include "Poco/Data/Data.h"
#include "Poco/Data/MetaColumn.h"
#include "Poco/SharedPtr.h"
#include "Poco/RefCountedObject.h"
#include <vector>
#include <list>
#include <deque>
#include "Poco/SharedPtr.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
template <class C>
class Column
template <class C>
class Column
/// Column class is column data container.
/// Data (a pointer to underlying STL container) is assigned to the class
/// at construction time. Construction with null pointer is not allowed.
/// This class owns the data assigned to it and deletes the storage on destruction.
{
public:
{
public:
typedef C Container;
typedef Poco::SharedPtr<C> ContainerPtr;
typedef typename C::const_iterator Iterator;
@ -46,18 +48,14 @@ public:
typedef typename C::size_type Size;
typedef typename C::value_type Type;
Column(const MetaColumn& metaColumn, Container* pData):
_metaColumn(metaColumn),
_pData(pData)
Column(const MetaColumn & metaColumn, Container * pData) : _metaColumn(metaColumn), _pData(pData)
/// Creates the Column.
{
if (!_pData)
throw NullPointerException("Container pointer must point to valid storage.");
}
Column(const Column& col):
_metaColumn(col._metaColumn),
_pData(col._pData)
Column(const Column & col) : _metaColumn(col._metaColumn), _pData(col._pData)
/// Creates the Column.
{
}
@ -67,7 +65,7 @@ public:
{
}
Column& operator = (const Column& col)
Column & operator=(const Column & col)
/// Assignment operator.
{
Column tmp(col);
@ -75,7 +73,7 @@ public:
return *this;
}
void swap(Column& other)
void swap(Column & other)
/// Swaps the column with another one.
{
using std::swap;
@ -83,26 +81,26 @@ public:
swap(_pData, other._pData);
}
Container& data()
Container & data()
/// Returns reference to contained data.
{
return *_pData;
}
const Type& value(std::size_t row) const
const Type & value(std::size_t row) const
/// Returns the field value in specified row.
{
try
{
return _pData->at(row);
}
catch (std::out_of_range& ex)
catch (std::out_of_range & ex)
{
throw RangeException(ex.what());
}
}
const Type& operator [] (std::size_t row) const
const Type & operator[](std::size_t row) const
/// Returns the field value in specified row.
{
return value(row);
@ -120,7 +118,7 @@ public:
Container().swap(*_pData);
}
const std::string& name() const
const std::string & name() const
/// Returns column name.
{
return _metaColumn.name();
@ -163,16 +161,16 @@ public:
return _pData->end();
}
private:
private:
Column();
MetaColumn _metaColumn;
ContainerPtr _pData;
};
};
template <>
class Column<std::vector<bool> >
template <>
class Column<std::vector<bool>>
/// The std::vector<bool> specialization for the Column class.
///
/// This specialization is necessary due to the nature of std::vector<bool>.
@ -184,26 +182,22 @@ class Column<std::vector<bool> >
/// The workaround employed here is using deque<bool> as an
/// internal "companion" container kept in sync with the vector<bool>
/// column data.
{
public:
{
public:
typedef std::vector<bool> Container;
typedef Poco::SharedPtr<Container> ContainerPtr;
typedef Container::const_iterator Iterator;
typedef Container::const_reverse_iterator RIterator;
typedef Container::size_type Size;
Column(const MetaColumn& metaColumn, Container* pData):
_metaColumn(metaColumn),
_pData(pData)
Column(const MetaColumn & metaColumn, Container * pData) : _metaColumn(metaColumn), _pData(pData)
/// Creates the Column.
{
poco_check_ptr (_pData);
poco_check_ptr(_pData);
_deque.assign(_pData->begin(), _pData->end());
}
Column(const Column& col):
_metaColumn(col._metaColumn),
_pData(col._pData)
Column(const Column & col) : _metaColumn(col._metaColumn), _pData(col._pData)
/// Creates the Column.
{
_deque.assign(_pData->begin(), _pData->end());
@ -214,7 +208,7 @@ public:
{
}
Column& operator = (const Column& col)
Column & operator=(const Column & col)
/// Assignment operator.
{
Column tmp(col);
@ -222,7 +216,7 @@ public:
return *this;
}
void swap(Column& other)
void swap(Column & other)
/// Swaps the column with another one.
{
using std::swap;
@ -231,13 +225,13 @@ public:
swap(_deque, other._deque);
}
Container& data()
Container & data()
/// Returns reference to contained data.
{
return *_pData;
}
const bool& value(std::size_t row) const
const bool & value(std::size_t row) const
/// Returns the field value in specified row.
{
if (_deque.size() < _pData->size())
@ -247,13 +241,13 @@ public:
{
return _deque.at(row) = _pData->at(row);
}
catch (std::out_of_range& ex)
catch (std::out_of_range & ex)
{
throw RangeException(ex.what());
}
}
const bool& operator [] (std::size_t row) const
const bool & operator[](std::size_t row) const
/// Returns the field value in specified row.
{
return value(row);
@ -272,7 +266,7 @@ public:
_deque.clear();
}
const std::string& name() const
const std::string & name() const
/// Returns column name.
{
return _metaColumn.name();
@ -315,37 +309,33 @@ public:
return _pData->end();
}
private:
private:
Column();
MetaColumn _metaColumn;
ContainerPtr _pData;
mutable std::deque<bool> _deque;
};
};
template <class T>
class Column<std::list<T> >
template <class T>
class Column<std::list<T>>
/// Column specialization for std::list
{
public:
{
public:
typedef std::list<T> Container;
typedef Poco::SharedPtr<Container> ContainerPtr;
typedef typename Container::const_iterator Iterator;
typedef typename Container::const_reverse_iterator RIterator;
typedef typename Container::size_type Size;
Column(const MetaColumn& metaColumn, std::list<T>* pData):
_metaColumn(metaColumn),
_pData(pData)
Column(const MetaColumn & metaColumn, std::list<T> * pData) : _metaColumn(metaColumn), _pData(pData)
/// Creates the Column.
{
poco_check_ptr (_pData);
poco_check_ptr(_pData);
}
Column(const Column& col):
_metaColumn(col._metaColumn),
_pData(col._pData)
Column(const Column & col) : _metaColumn(col._metaColumn), _pData(col._pData)
/// Creates the Column.
{
}
@ -355,7 +345,7 @@ public:
{
}
Column& operator = (const Column& col)
Column & operator=(const Column & col)
/// Assignment operator.
{
Column tmp(col);
@ -363,7 +353,7 @@ public:
return *this;
}
void swap(Column& other)
void swap(Column & other)
/// Swaps the column with another one.
{
using std::swap;
@ -371,13 +361,13 @@ public:
swap(_pData, other._pData);
}
Container& data()
Container & data()
/// Returns reference to contained data.
{
return *_pData;
}
const T& value(std::size_t row) const
const T & value(std::size_t row) const
/// Returns the field value in specified row.
/// This is the std::list specialization and std::list
/// is not the optimal solution for cases where random
@ -388,12 +378,13 @@ public:
/// to start iteration from beginning or end,
/// depending on the position requested.
{
if (row <= (std::size_t) (_pData->size() / 2))
if (row <= (std::size_t)(_pData->size() / 2))
{
Iterator it = _pData->begin();
Iterator end = _pData->end();
for (int i = 0; it != end; ++it, ++i)
if (i == row) return *it;
if (i == row)
return *it;
}
else
{
@ -401,13 +392,14 @@ public:
RIterator it = _pData->rbegin();
RIterator end = _pData->rend();
for (int i = 1; it != end; ++it, ++i)
if (i == row) return *it;
if (i == row)
return *it;
}
throw RangeException("Invalid row number.");
}
const T& operator [] (std::size_t row) const
const T & operator[](std::size_t row) const
/// Returns the field value in specified row.
{
return value(row);
@ -425,7 +417,7 @@ public:
_pData->clear();
}
const std::string& name() const
const std::string & name() const
/// Returns column name.
{
return _metaColumn.name();
@ -468,23 +460,23 @@ public:
return _pData->end();
}
private:
private:
Column();
MetaColumn _metaColumn;
ContainerPtr _pData;
};
};
template <typename C>
inline void swap(Column<C>& c1, Column<C>& c2)
{
template <typename C>
inline void swap(Column<C> & c1, Column<C> & c2)
{
c1.swap(c2);
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_Column_INCLUDED

View File

@ -18,39 +18,42 @@
#define Data_Connector_INCLUDED
#include "Poco/AutoPtr.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/SessionImpl.h"
#include "Poco/AutoPtr.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Data_API Connector
class Data_API Connector
/// A Connector creates SessionImpl objects.
///
/// Every connector library (like the SQLite or the ODBC connector)
/// provides a subclass of this class, an instance of which is
/// registered with the SessionFactory.
{
public:
{
public:
Connector();
/// Creates the Connector.
virtual ~Connector();
/// Destroys the Connector.
virtual const std::string& name() const = 0;
virtual const std::string & name() const = 0;
/// Returns the name associated with this connector.
virtual Poco::AutoPtr<SessionImpl> createSession(const std::string& connectionString,
std::size_t timeout = SessionImpl::LOGIN_TIMEOUT_DEFAULT) = 0;
virtual Poco::AutoPtr<SessionImpl>
createSession(const std::string & connectionString, std::size_t timeout = SessionImpl::LOGIN_TIMEOUT_DEFAULT) = 0;
/// Create a SessionImpl object and initialize it with the given connectionString.
};
};
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_Connector_INCLUDED

View File

@ -19,18 +19,21 @@
#undef max
#include <limits>
#include <cstddef>
#include <limits>
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
static const std::size_t POCO_DATA_INVALID_ROW = std::numeric_limits<std::size_t>::max();
static const std::size_t POCO_DATA_INVALID_ROW = std::numeric_limits<std::size_t>::max();
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_Constants_INCLUDED

View File

@ -32,20 +32,20 @@
// defined with this macro as being exported.
//
#if defined(_WIN32) && defined(POCO_DLL)
#if defined(Data_EXPORTS)
#define Data_API __declspec(dllexport)
#else
#define Data_API __declspec(dllimport)
#endif
# if defined(Data_EXPORTS)
# define Data_API __declspec(dllexport)
# else
# define Data_API __declspec(dllimport)
# endif
#endif
#if !defined(Data_API)
#if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4)
#define Data_API __attribute__ ((visibility ("default")))
#else
#define Data_API
#endif
# if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined(__GNUC__) && (__GNUC__ >= 4)
# define Data_API __attribute__((visibility("default")))
# else
# define Data_API
# endif
#endif
@ -53,9 +53,9 @@
// Automatically link Data library.
//
#if defined(_MSC_VER)
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Data_EXPORTS)
#pragma comment(lib, "PocoData" POCO_LIB_SUFFIX)
#endif
# if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Data_EXPORTS)
# pragma comment(lib, "PocoData" POCO_LIB_SUFFIX)
# endif
#endif

View File

@ -22,29 +22,32 @@
#include "Poco/Exception.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
POCO_DECLARE_EXCEPTION(Data_API, DataException, Poco::IOException)
POCO_DECLARE_EXCEPTION(Data_API, RowDataMissingException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, UnknownDataBaseException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, UnknownTypeException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, ExecutionException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, BindingException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, ExtractException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, LimitException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, NotSupportedException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, SessionUnavailableException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, SessionPoolExhaustedException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, SessionPoolExistsException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, NoDataException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, LengthExceededException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, ConnectionFailedException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, NotConnectedException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, DataException, Poco::IOException)
POCO_DECLARE_EXCEPTION(Data_API, RowDataMissingException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, UnknownDataBaseException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, UnknownTypeException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, ExecutionException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, BindingException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, ExtractException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, LimitException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, NotSupportedException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, SessionUnavailableException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, SessionPoolExhaustedException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, SessionPoolExistsException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, NoDataException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, LengthExceededException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, ConnectionFailedException, DataException)
POCO_DECLARE_EXCEPTION(Data_API, NotConnectedException, DataException)
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_DataException_INCLUDED

View File

@ -23,34 +23,37 @@
#include "Poco/Exception.h"
namespace Poco {
namespace Poco
{
class DateTime;
namespace Dynamic {
namespace Dynamic
{
class Var;
class Var;
}
namespace Data {
namespace Data
{
class Time;
class Time;
class Data_API Date
class Data_API Date
/// Date class wraps a DateTime and exposes date related interface.
/// The purpose of this class is binding/extraction support for date fields.
{
public:
{
public:
Date();
/// Creates the Date
Date(int year, int month, int day);
/// Creates the Date
Date(const DateTime& dt);
Date(const DateTime & dt);
/// Creates the Date from DateTime
~Date();
@ -68,90 +71,89 @@ public:
void assign(int year, int month, int day);
/// Assigns date.
Date& operator = (const Date& d);
Date & operator=(const Date & d);
/// Assignment operator for Date.
Date& operator = (const DateTime& dt);
Date & operator=(const DateTime & dt);
/// Assignment operator for DateTime.
Date& operator = (const Poco::Dynamic::Var& var);
Date & operator=(const Poco::Dynamic::Var & var);
/// Assignment operator for Var.
bool operator == (const Date& date) const;
bool operator==(const Date & date) const;
/// Equality operator.
bool operator != (const Date& date) const;
bool operator!=(const Date & date) const;
/// Inequality operator.
bool operator < (const Date& date) const;
bool operator<(const Date & date) const;
/// Less then operator.
bool operator > (const Date& date) const;
bool operator>(const Date & date) const;
/// Greater then operator.
private:
private:
int _year;
int _month;
int _day;
};
};
//
// inlines
//
inline int Date::year() const
{
//
// inlines
//
inline int Date::year() const
{
return _year;
}
}
inline int Date::month() const
{
inline int Date::month() const
{
return _month;
}
}
inline int Date::day() const
{
inline int Date::day() const
{
return _day;
}
}
inline Date& Date::operator = (const Date& d)
{
inline Date & Date::operator=(const Date & d)
{
assign(d.year(), d.month(), d.day());
return *this;
}
}
inline Date& Date::operator = (const DateTime& dt)
{
inline Date & Date::operator=(const DateTime & dt)
{
assign(dt.year(), dt.month(), dt.day());
return *this;
}
}
inline bool Date::operator == (const Date& date) const
{
return _year == date.year() &&
_month == date.month() &&
_day == date.day();
}
inline bool Date::operator==(const Date & date) const
{
return _year == date.year() && _month == date.month() && _day == date.day();
}
inline bool Date::operator != (const Date& date) const
{
inline bool Date::operator!=(const Date & date) const
{
return !(*this == date);
}
}
inline bool Date::operator > (const Date& date) const
{
inline bool Date::operator>(const Date & date) const
{
return !(*this == date) && !(*this < date);
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
//
@ -159,67 +161,51 @@ inline bool Date::operator > (const Date& date) const
//
namespace Poco {
namespace Dynamic {
template <>
class VarHolderImpl<Poco::Data::Date>: public VarHolder
namespace Poco
{
namespace Dynamic
{
public:
VarHolderImpl(const Poco::Data::Date& val): _val(val)
{
}
~VarHolderImpl()
{
}
const std::type_info& type() const
template <>
class VarHolderImpl<Poco::Data::Date> : public VarHolder
{
return typeid(Poco::Data::Date);
}
public:
VarHolderImpl(const Poco::Data::Date & val) : _val(val) { }
void convert(Poco::Timestamp& val) const
~VarHolderImpl() { }
const std::type_info & type() const { return typeid(Poco::Data::Date); }
void convert(Poco::Timestamp & val) const
{
DateTime dt;
dt.assign(_val.year(), _val.month(), _val.day());
val = dt.timestamp();
}
void convert(Poco::DateTime& val) const
{
val.assign(_val.year(), _val.month(), _val.day());
}
void convert(Poco::DateTime & val) const { val.assign(_val.year(), _val.month(), _val.day()); }
void convert(Poco::LocalDateTime& val) const
{
val.assign(_val.year(), _val.month(), _val.day());
}
void convert(Poco::LocalDateTime & val) const { val.assign(_val.year(), _val.month(), _val.day()); }
void convert(std::string& val) const
void convert(std::string & val) const
{
DateTime dt(_val.year(), _val.month(), _val.day());
val = DateTimeFormatter::format(dt, "%Y/%m/%d");
}
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
{
return cloneHolder(pVarHolder, _val);
}
VarHolder * clone(Placeholder<VarHolder> * pVarHolder = 0) const { return cloneHolder(pVarHolder, _val); }
const Poco::Data::Date& value() const
{
return _val;
}
const Poco::Data::Date & value() const { return _val; }
private:
private:
VarHolderImpl();
Poco::Data::Date _val;
};
};
} } // namespace Poco::Dynamic
}
} // namespace Poco::Dynamic
#endif // Data_Date_INCLUDED

View File

@ -24,24 +24,32 @@
#include "Poco/Dynamic/Var.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Date;
class Time;
class Date;
class Time;
} } // namespace Poco::Data
}
} // namespace Poco::Data
namespace Poco {
namespace Dynamic {
namespace Poco
{
namespace Dynamic
{
template <> Data_API Var::operator Poco::Data::Date () const;
template <> Data_API Var::operator Poco::Data::Time () const;
template <>
Data_API Var::operator Poco::Data::Date() const;
template <>
Data_API Var::operator Poco::Data::Time() const;
} } // namespace Poco::Dynamic
}
} // namespace Poco::Dynamic
#endif // Data_DynamicDateTime_INCLUDED

View File

@ -23,23 +23,32 @@
#include "Poco/Dynamic/Var.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
template <typename T> class LOB;
typedef LOB<unsigned char> BLOB;
typedef LOB<char> CLOB;
template <typename T>
class LOB;
typedef LOB<unsigned char> BLOB;
typedef LOB<char> CLOB;
} } // namespace Poco::Data
}
} // namespace Poco::Data
namespace Poco {
namespace Dynamic {
namespace Poco
{
namespace Dynamic
{
template <> Data_API Var::operator Poco::Data::CLOB () const;
template <> Data_API Var::operator Poco::Data::BLOB () const;
template <>
Data_API Var::operator Poco::Data::CLOB() const;
template <>
Data_API Var::operator Poco::Data::BLOB() const;
} } // namespace Poco::Dynamic
}
} // namespace Poco::Dynamic
#endif // Data_DynamicLOB_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@ -18,20 +18,22 @@
#define Data_LOB_INCLUDED
#include <algorithm>
#include <vector>
#include "Poco/Data/Data.h"
#include "Poco/SharedPtr.h"
#include "Poco/Dynamic/VarHolder.h"
#include "Poco/Exception.h"
#include <vector>
#include <algorithm>
#include "Poco/SharedPtr.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
template <typename T>
class LOB
template <typename T>
class LOB
/// Representation of a Large OBject.
///
/// A LOB can hold arbitrary data.
@ -39,37 +41,34 @@ class LOB
///
/// The LOBInputStream and LOBOutputStream classes provide
/// a convenient way to access the data in a LOB.
{
public:
{
public:
typedef typename std::vector<T>::const_iterator Iterator;
typedef T ValueType;
typedef typename std::vector<T> Container;
typedef Poco::SharedPtr<Container> ContentPtr;
LOB(): _pContent(new std::vector<T>())
LOB() : _pContent(new std::vector<T>())
/// Creates an empty LOB.
{
}
LOB(const std::vector<T>& content):
_pContent(new std::vector<T>(content))
LOB(const std::vector<T> & content) : _pContent(new std::vector<T>(content))
/// Creates the LOB, content is deep-copied.
{
}
LOB(const T* const pContent, std::size_t size):
_pContent(new std::vector<T>(pContent, pContent + size))
LOB(const T * const pContent, std::size_t size) : _pContent(new std::vector<T>(pContent, pContent + size))
/// Creates the LOB by deep-copying pContent.
{
}
LOB(const std::basic_string<T>& content):
_pContent(new std::vector<T>(content.begin(), content.end()))
LOB(const std::basic_string<T> & content) : _pContent(new std::vector<T>(content.begin(), content.end()))
/// Creates a LOB from a string.
{
}
LOB(const LOB& other): _pContent(other._pContent)
LOB(const LOB & other) : _pContent(other._pContent)
/// Creates a LOB by copying another one.
{
}
@ -79,7 +78,7 @@ public:
{
}
LOB& operator = (const LOB& other)
LOB & operator=(const LOB & other)
/// Assignment operator.
{
LOB tmp(other);
@ -87,32 +86,32 @@ public:
return *this;
}
bool operator == (const LOB& other) const
bool operator==(const LOB & other) const
/// Compares for equality LOB by value.
{
return *_pContent == *other._pContent;
}
bool operator != (const LOB& other) const
bool operator!=(const LOB & other) const
/// Compares for inequality LOB by value.
{
return *_pContent != *other._pContent;
}
void swap(LOB& other)
void swap(LOB & other)
/// Swaps the LOB with another one.
{
using std::swap;
swap(_pContent, other._pContent);
}
const std::vector<T>& content() const
const std::vector<T> & content() const
/// Returns the content.
{
return *_pContent;
}
const T* rawContent() const
const T * rawContent() const
/// Returns the raw content.
///
/// If the LOB is empty, returns NULL.
@ -123,26 +122,26 @@ public:
return &(*_pContent)[0];
}
void assignVal(std::size_t count, const T& val)
void assignVal(std::size_t count, const T & val)
/// Assigns raw content to internal storage.
{
ContentPtr tmp = new Container(count, val);
_pContent.swap(tmp);
}
void assignRaw(const T* ptr, std::size_t count)
void assignRaw(const T * ptr, std::size_t count)
/// Assigns raw content to internal storage.
{
poco_assert_dbg (ptr);
poco_assert_dbg(ptr);
LOB tmp(ptr, count);
swap(tmp);
}
void appendRaw(const T* pChar, std::size_t count)
void appendRaw(const T * pChar, std::size_t count)
/// Assigns raw content to internal storage.
{
poco_assert_dbg (pChar);
_pContent->insert(_pContent->end(), pChar, pChar+count);
poco_assert_dbg(pChar);
_pContent->insert(_pContent->end(), pChar, pChar + count);
}
void clear(bool doCompact = false)
@ -150,7 +149,8 @@ public:
/// If doCompact is true, trims the excess capacity.
{
_pContent->clear();
if (doCompact) compact();
if (doCompact)
compact();
}
void compact()
@ -159,15 +159,9 @@ public:
std::vector<T>(*_pContent).swap(*_pContent);
}
Iterator begin() const
{
return _pContent->begin();
}
Iterator begin() const { return _pContent->begin(); }
Iterator end() const
{
return _pContent->end();
}
Iterator end() const { return _pContent->end(); }
std::size_t size() const
/// Returns the size of the LOB in bytes.
@ -175,46 +169,45 @@ public:
return static_cast<std::size_t>(_pContent->size());
}
private:
private:
ContentPtr _pContent;
};
};
typedef LOB<unsigned char> BLOB;
typedef LOB<char> CLOB;
typedef LOB<unsigned char> BLOB;
typedef LOB<char> CLOB;
//
// inlines
//
//
// inlines
//
template <typename T>
inline void swap(LOB<T>& b1, LOB<T>& b2)
{
template <typename T>
inline void swap(LOB<T> & b1, LOB<T> & b2)
{
b1.swap(b2);
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
namespace std
{
template<>
inline void swap<Poco::Data::BLOB>(Poco::Data::BLOB& b1,
Poco::Data::BLOB& b2)
/// Full template specalization of std:::swap for BLOB
{
template <>
inline void swap<Poco::Data::BLOB>(Poco::Data::BLOB & b1, Poco::Data::BLOB & b2)
/// Full template specalization of std:::swap for BLOB
{
b1.swap(b2);
}
}
template<>
inline void swap<Poco::Data::CLOB>(Poco::Data::CLOB& c1,
Poco::Data::CLOB& c2)
/// Full template specalization of std:::swap for CLOB
{
template <>
inline void swap<Poco::Data::CLOB>(Poco::Data::CLOB & c1, Poco::Data::CLOB & c2)
/// Full template specalization of std:::swap for CLOB
{
c1.swap(c2);
}
}
}
@ -223,87 +216,58 @@ namespace std
//
namespace Poco {
namespace Dynamic {
template <>
class VarHolderImpl<Poco::Data::BLOB>: public VarHolder
namespace Poco
{
namespace Dynamic
{
public:
VarHolderImpl(const Poco::Data::BLOB& val): _val(val)
{
}
~VarHolderImpl()
{
}
const std::type_info& type() const
template <>
class VarHolderImpl<Poco::Data::BLOB> : public VarHolder
{
return typeid(Poco::Data::BLOB);
}
public:
VarHolderImpl(const Poco::Data::BLOB & val) : _val(val) { }
void convert(std::string& val) const
{
val.assign(_val.begin(), _val.end());
}
~VarHolderImpl() { }
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
{
return cloneHolder(pVarHolder, _val);
}
const std::type_info & type() const { return typeid(Poco::Data::BLOB); }
const Poco::Data::BLOB& value() const
{
return _val;
}
void convert(std::string & val) const { val.assign(_val.begin(), _val.end()); }
private:
VarHolder * clone(Placeholder<VarHolder> * pVarHolder = 0) const { return cloneHolder(pVarHolder, _val); }
const Poco::Data::BLOB & value() const { return _val; }
private:
VarHolderImpl();
Poco::Data::BLOB _val;
};
};
template <>
class VarHolderImpl<Poco::Data::CLOB>: public VarHolder
{
public:
VarHolderImpl(const Poco::Data::CLOB& val): _val(val)
template <>
class VarHolderImpl<Poco::Data::CLOB> : public VarHolder
{
}
public:
VarHolderImpl(const Poco::Data::CLOB & val) : _val(val) { }
~VarHolderImpl()
{
}
~VarHolderImpl() { }
const std::type_info& type() const
{
return typeid(Poco::Data::CLOB);
}
const std::type_info & type() const { return typeid(Poco::Data::CLOB); }
void convert(std::string& val) const
{
val.assign(_val.begin(), _val.end());
}
void convert(std::string & val) const { val.assign(_val.begin(), _val.end()); }
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
{
return cloneHolder(pVarHolder, _val);
}
VarHolder * clone(Placeholder<VarHolder> * pVarHolder = 0) const { return cloneHolder(pVarHolder, _val); }
const Poco::Data::CLOB& value() const
{
return _val;
}
const Poco::Data::CLOB & value() const { return _val; }
private:
private:
VarHolderImpl();
Poco::Data::CLOB _val;
};
};
} } // namespace Poco::Dynamic
}
} // namespace Poco::Dynamic
#endif // Data_LOB_INCLUDED

View File

@ -18,23 +18,25 @@
#define Data_LOBStream_INCLUDED
#include "Poco/Foundation.h"
#include "Poco/UnbufferedStreamBuf.h"
#include "Poco/Data/LOB.h"
#include <istream>
#include <ostream>
#include "Poco/Data/LOB.h"
#include "Poco/Foundation.h"
#include "Poco/UnbufferedStreamBuf.h"
namespace Poco {
namespace Data {
template <typename T>
class LOBStreamBuf: public BasicUnbufferedStreamBuf<T, std::char_traits<T> >
/// This is the streambuf class used for reading from and writing to a LOB.
namespace Poco
{
public:
LOBStreamBuf(LOB<T>& lob): _lob(lob), _it(_lob.begin())
namespace Data
{
template <typename T>
class LOBStreamBuf : public BasicUnbufferedStreamBuf<T, std::char_traits<T>>
/// This is the streambuf class used for reading from and writing to a LOB.
{
public:
LOBStreamBuf(LOB<T> & lob) : _lob(lob), _it(_lob.begin())
/// Creates LOBStreamBuf.
{
}
@ -45,7 +47,7 @@ public:
{
}
protected:
protected:
typedef std::char_traits<T> TraitsType;
typedef BasicUnbufferedStreamBuf<T, TraitsType> BaseType;
@ -63,22 +65,22 @@ protected:
return 1;
}
private:
LOB<T>& _lob;
private:
LOB<T> & _lob;
typename LOB<T>::Iterator _it;
};
};
template <typename T>
class LOBIOS: public virtual std::ios
template <typename T>
class LOBIOS : public virtual std::ios
/// The base class for LOBInputStream and
/// LOBOutputStream.
///
/// This class is needed to ensure the correct initialization
/// order of the stream buffer and base classes.
{
public:
LOBIOS(LOB<T>& lob, openmode mode): _buf(lob)
{
public:
LOBIOS(LOB<T> & lob, openmode mode) : _buf(lob)
/// Creates the LOBIOS with the given LOB.
{
poco_ios_init(&_buf);
@ -89,25 +91,23 @@ public:
{
}
LOBStreamBuf<T>* rdbuf()
LOBStreamBuf<T> * rdbuf()
/// Returns a pointer to the internal LOBStreamBuf.
{
return &_buf;
}
protected:
protected:
LOBStreamBuf<T> _buf;
};
};
template <typename T>
class LOBOutputStream: public LOBIOS<T>, public std::basic_ostream<T, std::char_traits<T> >
template <typename T>
class LOBOutputStream : public LOBIOS<T>, public std::basic_ostream<T, std::char_traits<T>>
/// An output stream for writing to a LOB.
{
public:
LOBOutputStream(LOB<T>& lob):
LOBIOS<T>(lob, std::ios::out),
std::ostream(LOBIOS<T>::rdbuf())
{
public:
LOBOutputStream(LOB<T> & lob) : LOBIOS<T>(lob, std::ios::out), std::ostream(LOBIOS<T>::rdbuf())
/// Creates the LOBOutputStream with the given LOB.
{
}
@ -116,17 +116,15 @@ public:
/// Destroys the LOBOutputStream.
{
}
};
};
template <typename T>
class LOBInputStream: public LOBIOS<T>, public std::basic_istream<T, std::char_traits<T> >
template <typename T>
class LOBInputStream : public LOBIOS<T>, public std::basic_istream<T, std::char_traits<T>>
/// An input stream for reading from a LOB.
{
public:
LOBInputStream(LOB<T>& lob):
LOBIOS<T>(lob, std::ios::in),
std::istream(LOBIOS<T>::rdbuf())
{
public:
LOBInputStream(LOB<T> & lob) : LOBIOS<T>(lob, std::ios::in), std::istream(LOBIOS<T>::rdbuf())
/// Creates the LOBInputStream with the given LOB.
{
}
@ -135,16 +133,17 @@ public:
/// Destroys the LOBInputStream.
{
}
};
};
typedef LOBOutputStream<unsigned char> BLOBOutputStream;
typedef LOBOutputStream<char> CLOBOutputStream;
typedef LOBOutputStream<unsigned char> BLOBOutputStream;
typedef LOBOutputStream<char> CLOBOutputStream;
typedef LOBInputStream<unsigned char> BLOBInputStream;
typedef LOBInputStream<char> CLOBInputStream;
typedef LOBInputStream<unsigned char> BLOBInputStream;
typedef LOBInputStream<char> CLOBInputStream;
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_LOBStream_INCLUDED

View File

@ -21,19 +21,21 @@
#include "Poco/Data/Data.h"
namespace Poco {
namespace Data {
class Data_API Limit
/// Limit stores information how many rows a query should return.
namespace Poco
{
public:
namespace Data
{
class Data_API Limit
/// Limit stores information how many rows a query should return.
{
public:
typedef Poco::UInt32 SizeT;
enum Type
{
LIMIT_UNLIMITED = ~((SizeT) 0)
LIMIT_UNLIMITED = ~((SizeT)0)
};
Limit(SizeT value, bool hardLimit = false, bool isLowerLimit = false);
@ -57,57 +59,54 @@ public:
bool isLowerLimit() const;
/// Returns true if the limit is a lower limit, otherwise it is an upperLimit
bool operator == (const Limit& other) const;
bool operator==(const Limit & other) const;
/// Equality operator.
bool operator != (const Limit& other) const;
bool operator!=(const Limit & other) const;
/// Inequality operator.
private:
private:
SizeT _value;
bool _hardLimit;
bool _isLowerLimit;
};
};
//
// inlines
//
inline Poco::UInt32 Limit::value() const
{
//
// inlines
//
inline Poco::UInt32 Limit::value() const
{
return _value;
}
}
inline bool Limit::isHardLimit() const
{
inline bool Limit::isHardLimit() const
{
return _hardLimit;
}
}
inline bool Limit::isLowerLimit() const
{
inline bool Limit::isLowerLimit() const
{
return _isLowerLimit;
}
inline bool Limit::operator==(const Limit & other) const
{
return other._value == _value && other._hardLimit == _hardLimit && other._isLowerLimit == _isLowerLimit;
}
inline bool Limit::operator!=(const Limit & other) const
{
return other._value != _value || other._hardLimit != _hardLimit || other._isLowerLimit != _isLowerLimit;
}
}
inline bool Limit::operator == (const Limit& other) const
{
return other._value == _value &&
other._hardLimit == _hardLimit &&
other._isLowerLimit == _isLowerLimit;
}
inline bool Limit::operator != (const Limit& other) const
{
return other._value != _value ||
other._hardLimit != _hardLimit ||
other._isLowerLimit != _isLowerLimit;
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_Limit_INCLUDED

View File

@ -18,18 +18,20 @@
#define Data_MetaColumn_INCLUDED
#include "Poco/Data/Data.h"
#include <cstddef>
#include "Poco/Data/Data.h"
namespace Poco {
namespace Data {
class Data_API MetaColumn
/// MetaColumn class contains column metadata information.
namespace Poco
{
public:
namespace Data
{
class Data_API MetaColumn
/// MetaColumn class contains column metadata information.
{
public:
enum ColumnDataType
{
FDT_BOOL,
@ -56,8 +58,9 @@ public:
MetaColumn();
/// Creates the MetaColumn.
explicit MetaColumn(std::size_t position,
const std::string& name = "",
explicit MetaColumn(
std::size_t position,
const std::string & name = "",
ColumnDataType type = FDT_UNKNOWN,
std::size_t length = 0,
std::size_t precision = 0,
@ -67,7 +70,7 @@ public:
virtual ~MetaColumn();
/// Destroys the MetaColumn.
const std::string& name() const;
const std::string & name() const;
/// Returns column name.
std::size_t length() const;
@ -87,8 +90,8 @@ public:
bool isNullable() const;
/// Returns true if column allows null values, false otherwise.
protected:
void setName(const std::string& name);
protected:
void setName(const std::string & name);
/// Sets the column name.
void setLength(std::size_t length);
@ -103,86 +106,87 @@ protected:
void setNullable(bool nullable);
/// Sets the column nullability.
private:
private:
std::string _name;
std::size_t _length;
std::size_t _precision;
std::size_t _position;
ColumnDataType _type;
bool _nullable;
};
};
///
/// inlines
///
inline const std::string& MetaColumn::name() const
{
///
/// inlines
///
inline const std::string & MetaColumn::name() const
{
return _name;
}
}
inline std::size_t MetaColumn::length() const
{
inline std::size_t MetaColumn::length() const
{
return _length;
}
}
inline std::size_t MetaColumn::precision() const
{
inline std::size_t MetaColumn::precision() const
{
return _precision;
}
}
inline std::size_t MetaColumn::position() const
{
inline std::size_t MetaColumn::position() const
{
return _position;
}
}
inline MetaColumn::ColumnDataType MetaColumn::type() const
{
inline MetaColumn::ColumnDataType MetaColumn::type() const
{
return _type;
}
}
inline bool MetaColumn::isNullable() const
{
inline bool MetaColumn::isNullable() const
{
return _nullable;
}
}
inline void MetaColumn::setName(const std::string& name)
{
inline void MetaColumn::setName(const std::string & name)
{
_name = name;
}
}
inline void MetaColumn::setLength(std::size_t length)
{
inline void MetaColumn::setLength(std::size_t length)
{
_length = length;
}
}
inline void MetaColumn::setPrecision(std::size_t precision)
{
inline void MetaColumn::setPrecision(std::size_t precision)
{
_precision = precision;
}
}
inline void MetaColumn::setType(ColumnDataType type)
{
inline void MetaColumn::setType(ColumnDataType type)
{
_type = type;
}
}
inline void MetaColumn::setNullable(bool nullable)
{
inline void MetaColumn::setNullable(bool nullable)
{
_nullable = nullable;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_MetaColumn_INCLUDED

View File

@ -18,34 +18,36 @@
#define Data_PooledSessionHolder_INCLUDED
#include "Poco/AutoPtr.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/SessionImpl.h"
#include "Poco/AutoPtr.h"
#include "Poco/Timestamp.h"
#include "Poco/Mutex.h"
#include "Poco/Timestamp.h"
namespace Poco {
namespace Data {
class SessionPool;
class Data_API PooledSessionHolder: public Poco::RefCountedObject
/// This class is used by SessionPool to manage SessionImpl objects.
namespace Poco
{
public:
PooledSessionHolder(SessionPool& owner, SessionImpl* pSessionImpl);
namespace Data
{
class SessionPool;
class Data_API PooledSessionHolder : public Poco::RefCountedObject
/// This class is used by SessionPool to manage SessionImpl objects.
{
public:
PooledSessionHolder(SessionPool & owner, SessionImpl * pSessionImpl);
/// Creates the PooledSessionHolder.
~PooledSessionHolder();
/// Destroys the PooledSessionHolder.
SessionImpl* session();
SessionImpl * session();
/// Returns a pointer to the SessionImpl.
SessionPool& owner();
SessionPool & owner();
/// Returns a reference to the SessionHolder's owner.
void access();
@ -54,46 +56,47 @@ public:
int idle() const;
/// Returns the number of seconds the session has not been used.
private:
SessionPool& _owner;
private:
SessionPool & _owner;
Poco::AutoPtr<SessionImpl> _pImpl;
Poco::Timestamp _lastUsed;
mutable Poco::FastMutex _mutex;
};
};
//
// inlines
//
inline SessionImpl* PooledSessionHolder::session()
{
//
// inlines
//
inline SessionImpl * PooledSessionHolder::session()
{
return _pImpl;
}
}
inline SessionPool& PooledSessionHolder::owner()
{
inline SessionPool & PooledSessionHolder::owner()
{
return _owner;
}
}
inline void PooledSessionHolder::access()
{
inline void PooledSessionHolder::access()
{
Poco::FastMutex::ScopedLock lock(_mutex);
_lastUsed.update();
}
}
inline int PooledSessionHolder::idle() const
{
inline int PooledSessionHolder::idle() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return (int) (_lastUsed.elapsed()/Poco::Timestamp::resolution());
return (int)(_lastUsed.elapsed() / Poco::Timestamp::resolution());
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_PooledSessionHolder_INCLUDED

View File

@ -18,37 +18,39 @@
#define Data_PooledSessionImpl_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/SessionImpl.h"
#include "Poco/Data/PooledSessionHolder.h"
#include "Poco/AutoPtr.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/PooledSessionHolder.h"
#include "Poco/Data/SessionImpl.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class SessionPool;
class SessionPool;
class Data_API PooledSessionImpl: public SessionImpl
class Data_API PooledSessionImpl : public SessionImpl
/// PooledSessionImpl is a decorator created by
/// SessionPool that adds session pool
/// management to SessionImpl objects.
{
public:
PooledSessionImpl(PooledSessionHolder* pHolder);
{
public:
PooledSessionImpl(PooledSessionHolder * pHolder);
/// Creates the PooledSessionImpl.
~PooledSessionImpl();
/// Destroys the PooledSessionImpl.
// SessionImpl
StatementImpl* createStatementImpl();
StatementImpl * createStatementImpl();
void begin();
void commit();
void rollback();
void open(const std::string& connect = "");
void open(const std::string & connect = "");
void close();
bool isConnected();
void setConnectionTimeout(std::size_t timeout);
@ -59,14 +61,14 @@ public:
Poco::UInt32 getTransactionIsolation();
bool hasTransactionIsolation(Poco::UInt32);
bool isTransactionIsolation(Poco::UInt32);
const std::string& connectorName() const;
void setFeature(const std::string& name, bool state);
bool getFeature(const std::string& name);
void setProperty(const std::string& name, const Poco::Any& value);
Poco::Any getProperty(const std::string& name);
const std::string & connectorName() const;
void setFeature(const std::string & name, bool state);
bool getFeature(const std::string & name);
void setProperty(const std::string & name, const Poco::Any & value);
Poco::Any getProperty(const std::string & name);
protected:
SessionImpl* access() const;
protected:
SessionImpl * access() const;
/// Updates the last access timestamp,
/// verifies validity of the session
/// and returns the session if it is valid.
@ -74,24 +76,25 @@ protected:
/// Throws an SessionUnavailableException if the
/// session is no longer valid.
SessionImpl* impl() const;
SessionImpl * impl() const;
/// Returns a pointer to the SessionImpl.
private:
private:
mutable Poco::AutoPtr<PooledSessionHolder> _pHolder;
};
};
//
// inlines
//
inline SessionImpl* PooledSessionImpl::impl() const
{
//
// inlines
//
inline SessionImpl * PooledSessionImpl::impl() const
{
return _pHolder->session();
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_PooledSessionImpl_INCLUDED

View File

@ -21,15 +21,17 @@
#include "Poco/Data/Limit.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Data_API Position
class Data_API Position
/// Utility class wrapping unsigned integer. Used to
/// indicate the recordset position in batch SQL statements.
{
public:
{
public:
Position(Poco::UInt32 value);
/// Creates the Position.
@ -39,37 +41,39 @@ public:
Poco::UInt32 value() const;
/// Returns the position value.
private:
private:
Position();
Poco::UInt32 _value;
};
};
///
/// inlines
///
inline Poco::UInt32 Position::value() const
{
///
/// inlines
///
inline Poco::UInt32 Position::value() const
{
return _value;
}
}
namespace Keywords {
namespace Keywords
{
template <typename T>
inline Position from(const T& value)
template <typename T>
inline Position from(const T & value)
/// Convenience function for creation of position.
{
{
return Position(value);
}
} // namespace Keywords
}
} // namespace Keywords
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_Position_INCLUDED

View File

@ -18,26 +18,26 @@
#define Data_Preparation_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/AbstractPreparation.h"
#include "Poco/Data/TypeHandler.h"
#include <cstddef>
#include <vector>
#include "Poco/Data/AbstractPreparation.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/TypeHandler.h"
namespace Poco {
namespace Data {
template<typename T>
class Preparation: public AbstractPreparation
/// Class for calling the appropriate AbstractPreparator method.
namespace Poco
{
public:
Preparation(AbstractPreparator::Ptr& pPreparator, std::size_t pos, T& val):
AbstractPreparation(pPreparator),
_pos(pos),
_val(val)
namespace Data
{
template <typename T>
class Preparation : public AbstractPreparation
/// Class for calling the appropriate AbstractPreparator method.
{
public:
Preparation(AbstractPreparator::Ptr & pPreparator, std::size_t pos, T & val)
: AbstractPreparation(pPreparator), _pos(pos), _val(val)
/// Creates the Preparation.
{
}
@ -53,23 +53,21 @@ public:
TypeHandler<T>::prepare(_pos, _val, preparation());
}
private:
private:
std::size_t _pos;
T& _val;
};
T & _val;
};
template<typename T>
class Preparation<std::vector<T> >: public AbstractPreparation
template <typename T>
class Preparation<std::vector<T>> : public AbstractPreparation
/// Preparation specialization for std::vector.
/// This specialization is needed for bulk operations to enforce
/// the whole vector preparation, rather than only individual contained values.
{
public:
Preparation(AbstractPreparator::Ptr pPreparator, std::size_t pos, std::vector<T>& val = std::vector<T>()):
AbstractPreparation(pPreparator),
_pos(pos),
_val(val)
{
public:
Preparation(AbstractPreparator::Ptr pPreparator, std::size_t pos, std::vector<T> & val = std::vector<T>())
: AbstractPreparation(pPreparator), _pos(pos), _val(val)
/// Creates the Preparation.
{
}
@ -82,26 +80,24 @@ public:
void prepare()
/// Prepares data.
{
TypeHandler<std::vector<T> >::prepare(_pos, _val, preparation());
TypeHandler<std::vector<T>>::prepare(_pos, _val, preparation());
}
private:
private:
std::size_t _pos;
std::vector<T>& _val;
};
std::vector<T> & _val;
};
template<typename T>
class Preparation<std::deque<T> >: public AbstractPreparation
template <typename T>
class Preparation<std::deque<T>> : public AbstractPreparation
/// Preparation specialization for std::deque.
/// This specialization is needed for bulk operations to enforce
/// the whole deque preparation, rather than only individual contained values.
{
public:
Preparation(AbstractPreparator::Ptr pPreparator, std::size_t pos, std::deque<T>& val = std::deque<T>()):
AbstractPreparation(pPreparator),
_pos(pos),
_val(val)
{
public:
Preparation(AbstractPreparator::Ptr pPreparator, std::size_t pos, std::deque<T> & val = std::deque<T>())
: AbstractPreparation(pPreparator), _pos(pos), _val(val)
/// Creates the Preparation.
{
}
@ -114,26 +110,24 @@ public:
void prepare()
/// Prepares data.
{
TypeHandler<std::deque<T> >::prepare(_pos, _val, preparation());
TypeHandler<std::deque<T>>::prepare(_pos, _val, preparation());
}
private:
private:
std::size_t _pos;
std::deque<T>& _val;
};
std::deque<T> & _val;
};
template<typename T>
class Preparation<std::list<T> >: public AbstractPreparation
template <typename T>
class Preparation<std::list<T>> : public AbstractPreparation
/// Preparation specialization for std::list.
/// This specialization is needed for bulk operations to enforce
/// the whole list preparation, rather than only individual contained values.
{
public:
Preparation(AbstractPreparator::Ptr pPreparator, std::size_t pos, std::list<T>& val = std::list<T>()):
AbstractPreparation(pPreparator),
_pos(pos),
_val(val)
{
public:
Preparation(AbstractPreparator::Ptr pPreparator, std::size_t pos, std::list<T> & val = std::list<T>())
: AbstractPreparation(pPreparator), _pos(pos), _val(val)
/// Creates the Preparation.
{
}
@ -146,16 +140,17 @@ public:
void prepare()
/// Prepares data.
{
TypeHandler<std::list<T> >::prepare(_pos, _val, preparation());
TypeHandler<std::list<T>>::prepare(_pos, _val, preparation());
}
private:
private:
std::size_t _pos;
std::list<T>& _val;
};
std::list<T> & _val;
};
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_Preparation_INCLUDED

View File

@ -22,83 +22,87 @@
#include "Poco/Data/Limit.h"
namespace Poco {
namespace Data {
class Data_API Range
/// Range stores information how many rows a query should return.
namespace Poco
{
public:
namespace Data
{
class Data_API Range
/// Range stores information how many rows a query should return.
{
public:
Range(Limit::SizeT lowValue, Limit::SizeT upValue, bool hardLimit);
/// Creates the Range. lowValue must be smaller equal than upValue
~Range();
/// Destroys the Limit.
const Limit& lower() const;
const Limit & lower() const;
/// Returns the lower limit
const Limit& upper() const;
const Limit & upper() const;
/// Returns the upper limit
private:
private:
Limit _lower;
Limit _upper;
};
};
//
// inlines
//
inline const Limit& Range::lower() const
{
//
// inlines
//
inline const Limit & Range::lower() const
{
return _lower;
}
}
inline const Limit& Range::upper() const
{
inline const Limit & Range::upper() const
{
return _upper;
}
}
namespace Keywords {
namespace Keywords
{
template <typename T>
Limit limit(T lim, bool hard = false)
template <typename T>
Limit limit(T lim, bool hard = false)
/// Creates an upperLimit
{
{
return Limit(static_cast<Limit::SizeT>(lim), hard, false);
}
}
template <typename T>
Limit upperLimit(T lim, bool hard = false)
{
template <typename T>
Limit upperLimit(T lim, bool hard = false)
{
return limit(lim, hard);
}
}
template <typename T>
Limit lowerLimit(T lim)
{
template <typename T>
Limit lowerLimit(T lim)
{
return Limit(static_cast<Limit::SizeT>(lim), true, true);
}
}
template <typename T>
Range range(T low, T upp, bool hard = false)
{
template <typename T>
Range range(T low, T upp, bool hard = false)
{
return Range(static_cast<Limit::SizeT>(low), static_cast<Limit::SizeT>(upp), hard);
}
} // namespace Keywords
}
} // namespace Keywords
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_Range_INCLUDED

View File

@ -18,30 +18,32 @@
#define Data_RecordSet_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/Extraction.h"
#include <limits>
#include <ostream>
#include "Poco/AutoPtr.h"
#include "Poco/Data/BulkExtraction.h"
#include "Poco/Data/Statement.h"
#include "Poco/Data/RowIterator.h"
#include "Poco/Data/RowFilter.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/Extraction.h"
#include "Poco/Data/LOB.h"
#include "Poco/String.h"
#include "Poco/Data/RowFilter.h"
#include "Poco/Data/RowIterator.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/Statement.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/Exception.h"
#include "Poco/AutoPtr.h"
#include <ostream>
#include <limits>
#include "Poco/String.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class RowFilter;
class RowFilter;
class Data_API RecordSet: private Statement
class Data_API RecordSet : private Statement
/// RecordSet provides access to data returned from a query.
/// Data access indices (row and column) are 0-based, as usual in C++.
///
@ -67,9 +69,9 @@ class Data_API RecordSet: private Statement
///
/// The number of rows in the RecordSet can be limited by specifying
/// a limit for the Statement.
{
public:
typedef std::map<std::size_t, Row*> RowMap;
{
public:
typedef std::map<std::size_t, Row *> RowMap;
typedef const RowIterator ConstIterator;
typedef RowIterator Iterator;
@ -78,33 +80,28 @@ public:
static const std::size_t UNKNOWN_TOTAL_ROW_COUNT;
explicit RecordSet(const Statement& rStatement,
RowFormatter::Ptr pRowFormatter = 0);
explicit RecordSet(const Statement & rStatement, RowFormatter::Ptr pRowFormatter = 0);
/// Creates the RecordSet.
RecordSet(Session& rSession,
const std::string& query,
RowFormatter::Ptr pRowFormatter = 0);
RecordSet(Session & rSession, const std::string & query, RowFormatter::Ptr pRowFormatter = 0);
/// Creates the RecordSet.
RecordSet(Session& rSession,
const std::string& query,
const RowFormatter& rowFormatter);
RecordSet(Session & rSession, const std::string & query, const RowFormatter & rowFormatter);
/// Creates the RecordSet.
template <class RF>
RecordSet(Session& rSession, const std::string& query, const RF& rowFormatter):
Statement((rSession << query, Keywords::now)),
_currentRow(0),
_pBegin(new RowIterator(this, 0 == rowsExtracted())),
_pEnd(new RowIterator(this, true)),
_totalRowCount(UNKNOWN_TOTAL_ROW_COUNT)
RecordSet(Session & rSession, const std::string & query, const RF & rowFormatter)
: Statement((rSession << query, Keywords::now))
, _currentRow(0)
, _pBegin(new RowIterator(this, 0 == rowsExtracted()))
, _pEnd(new RowIterator(this, true))
, _totalRowCount(UNKNOWN_TOTAL_ROW_COUNT)
/// Creates the RecordSet.
{
setRowFormatter(Keywords::format(rowFormatter));
}
RecordSet(const RecordSet& other);
RecordSet(const RecordSet & other);
/// Copy-creates the recordset.
~RecordSet();
@ -113,7 +110,7 @@ public:
void setRowFormatter(RowFormatter::Ptr pRowFormatter);
/// Assigns the row formatter to the statement and all recordset rows.
Statement& operator = (const Statement& stmt);
Statement & operator=(const Statement & stmt);
/// Assignment operator.
std::size_t rowCount() const;
@ -144,7 +141,7 @@ public:
void setTotalRowCount(std::size_t totalRowCount);
/// Explicitly sets the total row count.
void setTotalRowCount(const std::string& sql);
void setTotalRowCount(const std::string & sql);
/// Implicitly sets the total row count.
/// The supplied sql must return exactly one column
/// and one row. The returned value must be an unsigned
@ -154,43 +151,43 @@ public:
/// Returns the number of columns in the recordset.
template <class C>
const Column<C>& column(const std::string& name) const
const Column<C> & column(const std::string & name) const
/// Returns the reference to the first Column with the specified name.
{
if (isBulkExtraction())
{
typedef InternalBulkExtraction<C> E;
return columnImpl<C,E>(name);
return columnImpl<C, E>(name);
}
else
{
typedef InternalExtraction<C> E;
return columnImpl<C,E>(name);
return columnImpl<C, E>(name);
}
}
template <class C>
const Column<C>& column(std::size_t pos) const
const Column<C> & column(std::size_t pos) const
/// Returns the reference to column at specified position.
{
if (isBulkExtraction())
{
typedef InternalBulkExtraction<C> E;
return columnImpl<C,E>(pos);
return columnImpl<C, E>(pos);
}
else
{
typedef InternalExtraction<C> E;
return columnImpl<C,E>(pos);
return columnImpl<C, E>(pos);
}
}
Row& row(std::size_t pos);
Row & row(std::size_t pos);
/// Returns reference to row at position pos.
/// Rows are lazy-created and cached.
template <class T>
const T& value(std::size_t col, std::size_t row, bool useFilter = true) const
const T & value(std::size_t col, std::size_t row, bool useFilter = true) const
/// Returns the reference to data value at [col, row] location.
{
if (useFilter && isFiltered() && !isAllowed(row))
@ -198,19 +195,16 @@ public:
switch (storage())
{
case STORAGE_VECTOR:
{
case STORAGE_VECTOR: {
typedef typename std::vector<T> C;
return column<C>(col).value(row);
}
case STORAGE_LIST:
{
case STORAGE_LIST: {
typedef typename std::list<T> C;
return column<C>(col).value(row);
}
case STORAGE_DEQUE:
case STORAGE_UNKNOWN:
{
case STORAGE_UNKNOWN: {
typedef typename std::deque<T> C;
return column<C>(col).value(row);
}
@ -220,7 +214,7 @@ public:
}
template <class T>
const T& value(const std::string& name, std::size_t row, bool useFilter = true) const
const T & value(const std::string & name, std::size_t row, bool useFilter = true) const
/// Returns the reference to data value at named column, row location.
{
if (useFilter && isFiltered() && !isAllowed(row))
@ -228,19 +222,16 @@ public:
switch (storage())
{
case STORAGE_VECTOR:
{
case STORAGE_VECTOR: {
typedef typename std::vector<T> C;
return column<C>(name).value(row);
}
case STORAGE_LIST:
{
case STORAGE_LIST: {
typedef typename std::list<T> C;
return column<C>(name).value(row);
}
case STORAGE_DEQUE:
case STORAGE_UNKNOWN:
{
case STORAGE_UNKNOWN: {
typedef typename std::deque<T> C;
return column<C>(name).value(row);
}
@ -252,11 +243,11 @@ public:
Poco::Dynamic::Var value(std::size_t col, std::size_t row, bool checkFiltering = true) const;
/// Returns the data value at column, row location.
Poco::Dynamic::Var value(const std::string& name, std::size_t row, bool checkFiltering = true) const;
Poco::Dynamic::Var value(const std::string & name, std::size_t row, bool checkFiltering = true) const;
/// Returns the data value at named column, row location.
template <typename T>
Poco::Dynamic::Var nvl(const std::string& name, const T& deflt = T()) const
Poco::Dynamic::Var nvl(const std::string & name, const T & deflt = T()) const
/// Returns the value in the named column of the current row
/// if the value is not NULL, or deflt otherwise.
{
@ -267,7 +258,7 @@ public:
}
template <typename T>
Poco::Dynamic::Var nvl(std::size_t index, const T& deflt = T()) const
Poco::Dynamic::Var nvl(std::size_t index, const T & deflt = T()) const
/// Returns the value in the given column of the current row
/// if the value is not NULL, or deflt otherwise.
{
@ -277,10 +268,10 @@ public:
return value(index, _currentRow);
}
ConstIterator& begin() const;
ConstIterator & begin() const;
/// Returns the const row iterator.
ConstIterator& end() const;
ConstIterator & end() const;
/// Returns the const row iterator.
Iterator begin();
@ -317,61 +308,59 @@ public:
using Statement::reset;
/// Don't hide base class method.
void reset(const Statement& stmt);
void reset(const Statement & stmt);
/// Resets the RecordSet and assigns a new statement.
/// Should be called after the given statement has been reset,
/// assigned a new SQL statement, and executed.
///
/// Does not remove the associated RowFilter or RowFormatter.
Poco::Dynamic::Var value(const std::string& name);
Poco::Dynamic::Var value(const std::string & name);
/// Returns the value in the named column of the current row.
Poco::Dynamic::Var value(std::size_t index);
/// Returns the value in the given column of the current row.
Poco::Dynamic::Var operator [] (const std::string& name);
Poco::Dynamic::Var operator[](const std::string & name);
/// Returns the value in the named column of the current row.
Poco::Dynamic::Var operator [] (std::size_t index);
Poco::Dynamic::Var operator[](std::size_t index);
/// Returns the value in the named column of the current row.
MetaColumn::ColumnDataType columnType(std::size_t pos) const;
/// Returns the type for the column at specified position.
MetaColumn::ColumnDataType columnType(const std::string& name) const;
MetaColumn::ColumnDataType columnType(const std::string & name) const;
/// Returns the type for the column with specified name.
const std::string& columnName(std::size_t pos) const;
const std::string & columnName(std::size_t pos) const;
/// Returns column name for the column at specified position.
std::size_t columnLength(std::size_t pos) const;
/// Returns column maximum length for the column at specified position.
std::size_t columnLength(const std::string& name) const;
std::size_t columnLength(const std::string & name) const;
/// Returns column maximum length for the column with specified name.
std::size_t columnPrecision(std::size_t pos) const;
/// Returns column precision for the column at specified position.
/// Valid for floating point fields only (zero for other data types).
std::size_t columnPrecision(const std::string& name) const;
std::size_t columnPrecision(const std::string & name) const;
/// Returns column precision for the column with specified name.
/// Valid for floating point fields only (zero for other data types).
bool isNull(const std::string& name) const;
bool isNull(const std::string & name) const;
/// Returns true if column value of the current row is null.
std::ostream& copyNames(std::ostream& os) const;
std::ostream & copyNames(std::ostream & os) const;
/// Copies the column names to the target output stream.
/// Copied string is formatted by the current RowFormatter.
void formatNames() const;
/// Formats names using the current RowFormatter.
std::ostream& copyValues(std::ostream& os,
std::size_t offset = 0,
std::size_t length = RowIterator::POSITION_END) const;
std::ostream & copyValues(std::ostream & os, std::size_t offset = 0, std::size_t length = RowIterator::POSITION_END) const;
/// Copies the data values to the supplied output stream.
/// The data set to be copied is starting at the specified offset
/// from the recordset beginning. The number of rows to be copied
@ -388,28 +377,26 @@ public:
/// An invalid combination of offset/length arguments shall
/// cause RangeException to be thrown.
std::ostream& copy(std::ostream& os,
std::size_t offset = 0,
std::size_t length = RowIterator::POSITION_END) const;
std::ostream & copy(std::ostream & os, std::size_t offset = 0, std::size_t length = RowIterator::POSITION_END) const;
/// Copies the column names and values to the target output stream.
/// Copied strings are formatted by the current RowFormatter.
bool isFiltered() const;
/// Returns true if recordset is filtered.
private:
private:
RecordSet();
template<class C, class E>
std::size_t columnPosition(const std::string& name) const
template <class C, class E>
std::size_t columnPosition(const std::string & name) const
/// Returns the position of the column with specified name.
{
typedef typename C::value_type T;
typedef const E* ExtractionVecPtr;
typedef const E * ExtractionVecPtr;
bool typeFound = false;
const AbstractExtractionVec& rExtractions = extractions();
const AbstractExtractionVec & rExtractions = extractions();
AbstractExtractionVec::const_iterator it = rExtractions.begin();
AbstractExtractionVec::const_iterator end = rExtractions.end();
@ -420,7 +407,7 @@ private:
if (pExtraction)
{
typeFound = true;
const Column<C>& col = pExtraction->column();
const Column<C> & col = pExtraction->column();
if (0 == Poco::icompare(name, col.name()))
return col.position();
}
@ -433,20 +420,20 @@ private:
}
template <class C, class E>
const Column<C>& columnImpl(const std::string& name) const
const Column<C> & columnImpl(const std::string & name) const
/// Returns the reference to the first Column with the specified name.
{
return columnImpl<C,E>(columnPosition<C,E>(name));
return columnImpl<C, E>(columnPosition<C, E>(name));
}
template <class C, class E>
const Column<C>& columnImpl(std::size_t pos) const
const Column<C> & columnImpl(std::size_t pos) const
/// Returns the reference to column at specified position.
{
typedef typename C::value_type T;
typedef const E* ExtractionVecPtr;
typedef const E * ExtractionVecPtr;
const AbstractExtractionVec& rExtractions = extractions();
const AbstractExtractionVec & rExtractions = extractions();
std::size_t s = rExtractions.size();
if (0 == s || pos >= s)
@ -460,9 +447,8 @@ private:
}
else
{
throw Poco::BadCastException(Poco::format("Type cast failed!\nColumn: %z\nTarget type:\t%s",
pos,
std::string(typeid(T).name())));
throw Poco::BadCastException(
Poco::format("Type cast failed!\nColumn: %z\nTarget type:\t%s", pos, std::string(typeid(T).name())));
}
}
@ -470,184 +456,185 @@ private:
/// Returns true if the specified row is allowed by the
/// currently active filter.
void filter(const Poco::AutoPtr<RowFilter>& pFilter);
void filter(const Poco::AutoPtr<RowFilter> & pFilter);
/// Sets the filter for the RecordSet.
const Poco::AutoPtr<RowFilter>& getFilter() const;
const Poco::AutoPtr<RowFilter> & getFilter() const;
/// Returns the filter associated with the RecordSet.
std::size_t _currentRow;
RowIterator* _pBegin;
RowIterator* _pEnd;
RowIterator * _pBegin;
RowIterator * _pEnd;
RowMap _rowMap;
Poco::AutoPtr<RowFilter> _pFilter;
std::size_t _totalRowCount;
friend class RowIterator;
friend class RowFilter;
};
};
///
/// inlines
///
///
/// inlines
///
inline Data_API std::ostream& operator << (std::ostream &os, const RecordSet& rs)
{
inline Data_API std::ostream & operator<<(std::ostream & os, const RecordSet & rs)
{
return rs.copy(os);
}
}
inline std::size_t RecordSet::getTotalRowCount() const
{
inline std::size_t RecordSet::getTotalRowCount() const
{
if (UNKNOWN_TOTAL_ROW_COUNT == _totalRowCount)
return subTotalRowCount();
else
return _totalRowCount;
}
}
inline std::size_t RecordSet::totalRowCount() const
{
inline std::size_t RecordSet::totalRowCount() const
{
return getTotalRowCount();
}
}
inline void RecordSet::setTotalRowCount(std::size_t totalRowCount)
{
inline void RecordSet::setTotalRowCount(std::size_t totalRowCount)
{
_totalRowCount = totalRowCount;
}
}
inline std::size_t RecordSet::extractedRowCount() const
{
inline std::size_t RecordSet::extractedRowCount() const
{
return rowsExtracted();
}
}
inline std::size_t RecordSet::columnCount() const
{
inline std::size_t RecordSet::columnCount() const
{
return static_cast<std::size_t>(extractions().size());
}
}
inline Statement& RecordSet::operator = (const Statement& stmt)
{
inline Statement & RecordSet::operator=(const Statement & stmt)
{
reset(stmt);
return *this;
}
}
inline Poco::Dynamic::Var RecordSet::value(const std::string& name)
{
inline Poco::Dynamic::Var RecordSet::value(const std::string & name)
{
return value(name, _currentRow);
}
}
inline Poco::Dynamic::Var RecordSet::value(std::size_t index)
{
inline Poco::Dynamic::Var RecordSet::value(std::size_t index)
{
return value(index, _currentRow);
}
}
inline Poco::Dynamic::Var RecordSet::operator [] (const std::string& name)
{
inline Poco::Dynamic::Var RecordSet::operator[](const std::string & name)
{
return value(name, _currentRow);
}
}
inline Poco::Dynamic::Var RecordSet::operator [] (std::size_t index)
{
inline Poco::Dynamic::Var RecordSet::operator[](std::size_t index)
{
return value(index, _currentRow);
}
}
inline MetaColumn::ColumnDataType RecordSet::columnType(std::size_t pos)const
{
inline MetaColumn::ColumnDataType RecordSet::columnType(std::size_t pos) const
{
return metaColumn(static_cast<UInt32>(pos)).type();
}
}
inline MetaColumn::ColumnDataType RecordSet::columnType(const std::string& name)const
{
inline MetaColumn::ColumnDataType RecordSet::columnType(const std::string & name) const
{
return metaColumn(name).type();
}
}
inline const std::string& RecordSet::columnName(std::size_t pos) const
{
inline const std::string & RecordSet::columnName(std::size_t pos) const
{
return metaColumn(static_cast<UInt32>(pos)).name();
}
}
inline std::size_t RecordSet::columnLength(std::size_t pos) const
{
inline std::size_t RecordSet::columnLength(std::size_t pos) const
{
return metaColumn(static_cast<UInt32>(pos)).length();
}
}
inline std::size_t RecordSet::columnLength(const std::string& name)const
{
inline std::size_t RecordSet::columnLength(const std::string & name) const
{
return metaColumn(name).length();
}
}
inline std::size_t RecordSet::columnPrecision(std::size_t pos) const
{
inline std::size_t RecordSet::columnPrecision(std::size_t pos) const
{
return metaColumn(static_cast<UInt32>(pos)).precision();
}
}
inline std::size_t RecordSet::columnPrecision(const std::string& name)const
{
inline std::size_t RecordSet::columnPrecision(const std::string & name) const
{
return metaColumn(name).precision();
}
}
inline bool RecordSet::isNull(const std::string& name) const
{
inline bool RecordSet::isNull(const std::string & name) const
{
return isNull(metaColumn(name).position(), _currentRow);
}
}
inline RecordSet::ConstIterator& RecordSet::begin() const
{
inline RecordSet::ConstIterator & RecordSet::begin() const
{
return *_pBegin;
}
}
inline RecordSet::ConstIterator& RecordSet::end() const
{
inline RecordSet::ConstIterator & RecordSet::end() const
{
return *_pEnd;
}
}
inline RecordSet::Iterator RecordSet::begin()
{
inline RecordSet::Iterator RecordSet::begin()
{
return *_pBegin;
}
}
inline RecordSet::Iterator RecordSet::end()
{
inline RecordSet::Iterator RecordSet::end()
{
return *_pEnd;
}
}
inline const Poco::AutoPtr<RowFilter>& RecordSet::getFilter() const
{
inline const Poco::AutoPtr<RowFilter> & RecordSet::getFilter() const
{
return _pFilter;
}
}
inline void RecordSet::formatNames() const
{
inline void RecordSet::formatNames() const
{
(*_pBegin)->formatNames();
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_RecordSet_INCLUDED

View File

@ -18,24 +18,26 @@
#define Data_Row_INCLUDED
#include <ostream>
#include <string>
#include <vector>
#include "Poco/Data/Data.h"
#include "Poco/Data/RowFormatter.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/Tuple.h"
#include "Poco/SharedPtr.h"
#include <vector>
#include <string>
#include <ostream>
#include "Poco/Tuple.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class RecordSet;
class RecordSet;
class Data_API Row
class Data_API Row
/// Row class provides a data type for RecordSet iteration purposes.
/// Dereferencing a RowIterator returns Row.
/// Rows are sortable. The sortability is maintained at all times (i.e. there
@ -55,8 +57,8 @@ class Data_API Row
/// Field names are a shared pointer to a vector of strings. For efficiency sake,
/// a constructor taking a shared pointer to names vector argument is provided.
/// The stream operator is provided for Row data type as a free-standing function.
{
public:
{
public:
typedef RowFormatter::NameVec NameVec;
typedef RowFormatter::NameVecPtr NameVecPtr;
typedef RowFormatter::ValueVec ValueVec;
@ -81,53 +83,52 @@ public:
Row();
/// Creates the Row.
Row(NameVecPtr pNames,
const RowFormatter::Ptr& pFormatter = 0);
Row(NameVecPtr pNames, const RowFormatter::Ptr & pFormatter = 0);
/// Creates the Row.
Row(NameVecPtr pNames,
const SortMapPtr& pSortMap,
const RowFormatter::Ptr& pFormatter = 0);
Row(NameVecPtr pNames, const SortMapPtr & pSortMap, const RowFormatter::Ptr & pFormatter = 0);
/// Creates the Row.
~Row();
/// Destroys the Row.
Poco::Dynamic::Var& get(std::size_t col);
Poco::Dynamic::Var & get(std::size_t col);
/// Returns the reference to data value at column location.
Poco::Dynamic::Var& operator [] (std::size_t col);
Poco::Dynamic::Var & operator[](std::size_t col);
/// Returns the reference to data value at column location.
Poco::Dynamic::Var& operator [] (const std::string& name);
Poco::Dynamic::Var & operator[](const std::string & name);
/// Returns the reference to data value at named column location.
template <typename T>
void append(const std::string& name, const T& val)
void append(const std::string & name, const T & val)
/// Appends the value to the row.
{
if (!_pNames) _pNames = new NameVec;
if (!_pNames)
_pNames = new NameVec;
_values.push_back(val);
_pNames->push_back(name);
if (1 == _values.size()) addSortField(0);
if (1 == _values.size())
addSortField(0);
}
template <typename T>
void set(std::size_t pos, const T& val)
void set(std::size_t pos, const T & val)
/// Assigns the value to the row.
{
try
{
_values.at(pos) = val;
}
catch (std::out_of_range&)
catch (std::out_of_range &)
{
throw RangeException("Invalid column number.");
}
}
template <typename T>
void set(const std::string& name, const T& val)
void set(const std::string & name, const T & val)
/// Assigns the value to the row.
{
NameVec::iterator it = _pNames->begin();
@ -149,80 +150,80 @@ public:
void reset();
/// Resets the row by clearing all field names and values.
void separator(const std::string& sep);
void separator(const std::string & sep);
/// Sets the separator.
void addSortField(std::size_t pos);
/// Adds the field used for sorting.
void addSortField(const std::string& name);
void addSortField(const std::string & name);
/// Adds the field used for sorting.
void removeSortField(std::size_t pos);
/// Removes the field used for sorting.
void removeSortField(const std::string& name);
void removeSortField(const std::string & name);
/// Removes the field used for sorting.
void replaceSortField(std::size_t oldPos, std::size_t newPos);
/// Replaces the field used for sorting.
void replaceSortField(const std::string& oldName, const std::string& newName);
void replaceSortField(const std::string & oldName, const std::string & newName);
/// Replaces the field used for sorting.
void resetSort();
/// Resets the sorting criteria to field 0 only.
const std::string& namesToString() const;
const std::string & namesToString() const;
/// Converts the column names to string.
void formatNames() const;
/// Formats the column names.
const std::string& valuesToString() const;
const std::string & valuesToString() const;
/// Converts the row values to string and returns the formatted string.
void formatValues() const;
/// Formats the row values.
bool operator == (const Row& other) const;
bool operator==(const Row & other) const;
/// Equality operator.
bool operator != (const Row& other) const;
bool operator!=(const Row & other) const;
/// Inequality operator.
bool operator < (const Row& other) const;
bool operator<(const Row & other) const;
/// Less-than operator.
const NameVecPtr names() const;
/// Returns the shared pointer to names vector.
const ValueVec& values() const;
const ValueVec & values() const;
/// Returns the const reference to values vector.
void setFormatter(const RowFormatter::Ptr& pFormatter = 0);
void setFormatter(const RowFormatter::Ptr & pFormatter = 0);
/// Sets the formatter for this row and takes the
/// shared ownership of it.
const RowFormatter& getFormatter() const;
const RowFormatter & getFormatter() const;
/// Returns the reference to the formatter.
void setSortMap(const SortMapPtr& pSortMap = 0);
void setSortMap(const SortMapPtr & pSortMap = 0);
/// Adds the sorting fields entry and takes the
/// shared ownership of it.
const SortMapPtr& getSortMap() const;
const SortMapPtr & getSortMap() const;
/// Returns the reference to the sorting fields.
private:
void init(const SortMapPtr& pSortMap, const RowFormatter::Ptr& pFormatter);
private:
void init(const SortMapPtr & pSortMap, const RowFormatter::Ptr & pFormatter);
ValueVec& values();
ValueVec & values();
/// Returns the reference to values vector.
std::size_t getPosition(const std::string& name);
bool isEqualSize(const Row& other) const;
bool isEqualType(const Row& other) const;
std::size_t getPosition(const std::string & name);
bool isEqualSize(const Row & other) const;
bool isEqualType(const Row & other) const;
NameVecPtr _pNames;
ValueVec _values;
@ -230,83 +231,84 @@ private:
mutable RowFormatter::Ptr _pFormatter;
mutable std::string _nameStr;
mutable std::string _valueStr;
};
};
Data_API std::ostream& operator << (std::ostream &os, const Row& row);
Data_API std::ostream & operator<<(std::ostream & os, const Row & row);
///
/// inlines
///
inline std::size_t Row::fieldCount() const
{
///
/// inlines
///
inline std::size_t Row::fieldCount() const
{
return static_cast<std::size_t>(_values.size());
}
}
inline void Row::reset()
{
inline void Row::reset()
{
_pNames->clear();
_values.clear();
}
}
inline const Row::NameVecPtr Row::names() const
{
inline const Row::NameVecPtr Row::names() const
{
return _pNames;
}
}
inline const Row::ValueVec& Row::values() const
{
inline const Row::ValueVec & Row::values() const
{
return _values;
}
}
inline Row::ValueVec& Row::values()
{
inline Row::ValueVec & Row::values()
{
return _values;
}
}
inline Poco::Dynamic::Var& Row::operator [] (std::size_t col)
{
inline Poco::Dynamic::Var & Row::operator[](std::size_t col)
{
return get(col);
}
}
inline Poco::Dynamic::Var& Row::operator [] (const std::string& name)
{
inline Poco::Dynamic::Var & Row::operator[](const std::string & name)
{
return get(getPosition(name));
}
}
inline const RowFormatter& Row::getFormatter() const
{
inline const RowFormatter & Row::getFormatter() const
{
return *_pFormatter;
}
}
inline const Row::SortMapPtr& Row::getSortMap() const
{
inline const Row::SortMapPtr & Row::getSortMap() const
{
return _pSortMap;
}
}
inline const std::string& Row::valuesToString() const
{
inline const std::string & Row::valuesToString() const
{
return _pFormatter->formatValues(values(), _valueStr);
}
}
inline void Row::formatValues() const
{
inline void Row::formatValues() const
{
return _pFormatter->formatValues(values());
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_Row_INCLUDED

View File

@ -18,25 +18,27 @@
#define Data_RowFilter_INCLUDED
#include <list>
#include <map>
#include <utility>
#include "Poco/AutoPtr.h"
#include "Poco/Data/Data.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/Tuple.h"
#include "Poco/String.h"
#include "Poco/RefCountedObject.h"
#include "Poco/AutoPtr.h"
#include <map>
#include <list>
#include <utility>
#include "Poco/String.h"
#include "Poco/Tuple.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class RecordSet;
class RecordSet;
class Data_API RowFilter: public RefCountedObject
class Data_API RowFilter : public RefCountedObject
/// RowFilter class provides row filtering functionality.
/// A filter contains a set of criteria (field name, value and
/// logical operation) for row filtering.
@ -47,8 +49,8 @@ class Data_API RowFilter: public RefCountedObject
/// filtering, whenever the filtering criteria is changed,
/// the filter automatically notifies all associated recordsets
/// by rewinding them to the first position.
{
public:
{
public:
enum Comparison
{
VALUE_LESS_THAN,
@ -67,14 +69,14 @@ public:
OP_NOT
};
typedef bool (*CompT)(const Poco::Dynamic::Var&, const Poco::Dynamic::Var&);
typedef bool (*CompT)(const Poco::Dynamic::Var &, const Poco::Dynamic::Var &);
typedef AutoPtr<RowFilter> Ptr;
typedef std::map<std::string, Comparison> Comparisons;
typedef Tuple<Poco::Dynamic::Var, Comparison, LogicOperator> ComparisonEntry;
typedef std::multimap<std::string, ComparisonEntry> ComparisonMap;
typedef std::map<AutoPtr<RowFilter>, LogicOperator> FilterMap;
RowFilter(RecordSet* pRecordSet);
RowFilter(RecordSet * pRecordSet);
/// Creates the top-level RowFilter and associates it with the recordset.
RowFilter(Ptr pParent, LogicOperator op = OP_OR);
@ -93,36 +95,35 @@ public:
/// Returns true if this filter is parent of pFilter;
template <typename T>
void add(const std::string& name, Comparison comparison, const T& value, LogicOperator op = OP_OR)
void add(const std::string & name, Comparison comparison, const T & value, LogicOperator op = OP_OR)
/// Adds value to the filter.
{
rewindRecordSet();
_comparisonMap.insert(ComparisonMap::value_type(toUpper(name),
ComparisonEntry(value, comparison, op)));
_comparisonMap.insert(ComparisonMap::value_type(toUpper(name), ComparisonEntry(value, comparison, op)));
}
template <typename T>
void add(const std::string& name, const std::string& comp, const T& value, LogicOperator op = OP_OR)
void add(const std::string & name, const std::string & comp, const T & value, LogicOperator op = OP_OR)
/// Adds value to the filter.
{
add(name, getComparison(comp), value, op);
}
template <typename T>
void addAnd(const std::string& name, const std::string& comp, const T& value)
void addAnd(const std::string & name, const std::string & comp, const T & value)
/// Adds logically AND-ed value to the filter.
{
add(name, getComparison(comp), value, OP_AND);
}
template <typename T>
void addOr(const std::string& name, const std::string& comp, const T& value)
void addOr(const std::string & name, const std::string & comp, const T & value)
/// Adds logically OR-ed value to the filter.
{
add(name, getComparison(comp), value, OP_OR);
}
int remove(const std::string& name);
int remove(const std::string & name);
/// Removes named comparisons from the filter.
/// All comparisons with specified name are removed.
/// Returns the number of comparisons removed.
@ -139,138 +140,136 @@ public:
bool isAllowed(std::size_t row) const;
/// Returns true if name and value are allowed.
bool exists(const std::string& name) const;
bool exists(const std::string & name) const;
/// Returns true if name is known to this row filter.
private:
private:
RowFilter();
RowFilter(const RowFilter&);
RowFilter& operator=(const RowFilter&);
RowFilter(const RowFilter &);
RowFilter & operator=(const RowFilter &);
void init();
static bool equal(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2);
static bool notEqual(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2);
static bool less(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2);
static bool greater(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2);
static bool lessOrEqual(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2);
static bool greaterOrEqual(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2);
static bool logicalAnd(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2);
static bool logicalOr(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2);
static bool isNull(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var&);
static bool equal(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2);
static bool notEqual(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2);
static bool less(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2);
static bool greater(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2);
static bool lessOrEqual(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2);
static bool greaterOrEqual(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2);
static bool logicalAnd(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2);
static bool logicalOr(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2);
static bool isNull(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var &);
static void doCompare(Poco::Dynamic::Var& ret,
Poco::Dynamic::Var& val,
CompT comp,
const ComparisonEntry& ce);
static void doCompare(Poco::Dynamic::Var & ret, Poco::Dynamic::Var & val, CompT comp, const ComparisonEntry & ce);
RecordSet& recordSet() const;
RecordSet & recordSet() const;
Comparison getComparison(const std::string& comp) const;
Comparison getComparison(const std::string & comp) const;
void rewindRecordSet();
Comparisons _comparisons;
ComparisonMap _comparisonMap;
mutable RecordSet* _pRecordSet;
mutable RecordSet * _pRecordSet;
Ptr _pParent;
FilterMap _filterMap;
bool _not;
friend class RecordSet;
};
};
///
/// inlines
///
///
/// inlines
///
inline bool RowFilter::has(Ptr pFilter) const
{
inline bool RowFilter::has(Ptr pFilter) const
{
return _filterMap.find(pFilter) != _filterMap.end();
}
}
inline bool RowFilter::isEmpty() const
{
inline bool RowFilter::isEmpty() const
{
return _comparisonMap.size() == 0;
}
}
inline bool RowFilter::exists(const std::string& name) const
{
inline bool RowFilter::exists(const std::string & name) const
{
return _comparisonMap.find(name) != _comparisonMap.end();
}
}
inline void RowFilter::toggleNot()
{
inline void RowFilter::toggleNot()
{
_not = !_not;
}
}
inline bool RowFilter::isNot() const
{
inline bool RowFilter::isNot() const
{
return _not;
}
}
inline bool RowFilter::equal(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2)
{
inline bool RowFilter::equal(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2)
{
return p1 == p2;
}
}
inline bool RowFilter::notEqual(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2)
{
inline bool RowFilter::notEqual(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2)
{
return p1 != p2;
}
}
inline bool RowFilter::less(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2)
{
inline bool RowFilter::less(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2)
{
return p1 < p2;
}
}
inline bool RowFilter::greater(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2)
{
inline bool RowFilter::greater(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2)
{
return p1 > p2;
}
}
inline bool RowFilter::lessOrEqual(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2)
{
inline bool RowFilter::lessOrEqual(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2)
{
return p1 <= p2;
}
}
inline bool RowFilter::greaterOrEqual(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2)
{
inline bool RowFilter::greaterOrEqual(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2)
{
return p1 >= p2;
}
}
inline bool RowFilter::logicalAnd(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2)
{
inline bool RowFilter::logicalAnd(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2)
{
return p1 && p2;
}
}
inline bool RowFilter::logicalOr(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var& p2)
{
inline bool RowFilter::logicalOr(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var & p2)
{
return p1 || p2;
}
}
inline bool RowFilter::isNull(const Poco::Dynamic::Var& p1, const Poco::Dynamic::Var&)
{
inline bool RowFilter::isNull(const Poco::Dynamic::Var & p1, const Poco::Dynamic::Var &)
{
return p1.isEmpty();
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_RowFilter_INCLUDED

View File

@ -18,19 +18,21 @@
#define Data_RowFormatter_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/SharedPtr.h"
#include "Poco/RefCountedObject.h"
#include "Poco/Dynamic/Var.h"
#include <sstream>
#include <vector>
#include "Poco/Data/Data.h"
#include "Poco/Dynamic/Var.h"
#include "Poco/RefCountedObject.h"
#include "Poco/SharedPtr.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Data_API RowFormatter
class Data_API RowFormatter
/// Row formatter is an abstract class providing definition for row formatting functionality.
/// For custom formatting strategies, inherit from this class and override formatNames()
/// and formatValues() member functions.
@ -66,11 +68,11 @@ class Data_API RowFormatter
/// to the formatter mode are expected to be implemented. If a call is propagated to this parent
/// class, the functions do nothing or silently return empty string respectively.
///
{
public:
{
public:
typedef SharedPtr<RowFormatter> Ptr;
typedef std::vector<std::string> NameVec;
typedef SharedPtr<std::vector<std::string> > NameVecPtr;
typedef SharedPtr<std::vector<std::string>> NameVecPtr;
typedef std::vector<Poco::Dynamic::Var> ValueVec;
static const int INVALID_ROW_COUNT = -1;
@ -81,15 +83,13 @@ public:
FORMAT_BULK
};
RowFormatter(const std::string& prefix = "",
const std::string& postfix = "",
Mode mode = FORMAT_PROGRESSIVE);
RowFormatter(const std::string & prefix = "", const std::string & postfix = "", Mode mode = FORMAT_PROGRESSIVE);
/// Creates the RowFormatter and sets the prefix and postfix to specified values.
virtual ~RowFormatter();
/// Destroys the RowFormatter.
virtual std::string& formatNames(const NameVecPtr pNames, std::string& formattedNames);
virtual std::string & formatNames(const NameVecPtr pNames, std::string & formattedNames);
/// Should be implemented to format the row fields names and return the formatted string.
/// The default implementation clears the names string and returns it.
@ -97,15 +97,15 @@ public:
/// Should be implemented to format the row fields names.
/// The default implementation does nothing.
virtual std::string& formatValues(const ValueVec& vals, std::string& formattedValues);
virtual std::string & formatValues(const ValueVec & vals, std::string & formattedValues);
/// Should be implemented to format the row fields values and return the formatted string.
/// The default implementation clears the values string and returns it.
virtual void formatValues(const ValueVec& vals);
virtual void formatValues(const ValueVec & vals);
/// Should be implemented to format the row fields values.
/// The default implementation does nothing.
virtual const std::string& toString();
virtual const std::string & toString();
/// Throws NotImplementedException. Formatters operating in bulk mode should
/// implement this member function to return valid pointer to the formatted result.
@ -121,10 +121,10 @@ public:
void setTotalRowCount(int count);
/// Sets total row count.
virtual const std::string& prefix() const;
virtual const std::string & prefix() const;
/// Returns prefix string;
virtual const std::string& postfix() const;
virtual const std::string & postfix() const;
/// Returns postfix string;
void reset();
@ -137,95 +137,95 @@ public:
void setMode(Mode mode);
/// Sets the fromatter mode.
protected:
void setPrefix(const std::string& prefix);
protected:
void setPrefix(const std::string & prefix);
/// Sets the prefix for the formatter.
void setPostfix(const std::string& postfix);
void setPostfix(const std::string & postfix);
/// Sets the postfix for the formatter
private:
private:
mutable std::string _prefix;
mutable std::string _postfix;
Mode _mode;
int _totalRowCount;
};
};
///
/// inlines
///
inline int RowFormatter::rowCount() const
{
///
/// inlines
///
inline int RowFormatter::rowCount() const
{
return INVALID_ROW_COUNT;
}
}
inline int RowFormatter::getTotalRowCount() const
{
inline int RowFormatter::getTotalRowCount() const
{
return _totalRowCount;
}
}
inline void RowFormatter::setTotalRowCount(int count)
{
inline void RowFormatter::setTotalRowCount(int count)
{
_totalRowCount = count;
}
}
inline void RowFormatter::setPrefix(const std::string& prefix)
{
inline void RowFormatter::setPrefix(const std::string & prefix)
{
_prefix = prefix;
}
}
inline void RowFormatter::setPostfix(const std::string& postfix)
{
inline void RowFormatter::setPostfix(const std::string & postfix)
{
_postfix = postfix;
}
}
inline const std::string& RowFormatter::prefix() const
{
inline const std::string & RowFormatter::prefix() const
{
return _prefix;
}
}
inline const std::string& RowFormatter::postfix() const
{
inline const std::string & RowFormatter::postfix() const
{
return _postfix;
}
}
inline RowFormatter::Mode RowFormatter::getMode() const
{
inline RowFormatter::Mode RowFormatter::getMode() const
{
return _mode;
}
}
inline void RowFormatter::setMode(Mode mode)
{
inline void RowFormatter::setMode(Mode mode)
{
_mode = mode;
}
}
namespace Keywords {
namespace Keywords
{
template <typename T>
inline RowFormatter::Ptr format(const T& formatter)
template <typename T>
inline RowFormatter::Ptr format(const T & formatter)
/// Utility function used to pass formatter to the statement.
{
{
return new T(formatter);
}
} // namespace Keywords
}
} // namespace Keywords
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_RowFormatter_INCLUDED

View File

@ -18,84 +18,86 @@
#define Data_RowIterator_INCLUDED
#include <algorithm>
#include <iterator>
#include "Poco/Data/Data.h"
#include "Poco/Data/Row.h"
#include "Poco/Dynamic/Var.h"
#include <iterator>
#include <algorithm>
namespace Poco {
namespace Data {
class RecordSet;
class Data_API RowIterator
/// RowIterator class.
namespace Poco
{
public:
namespace Data
{
class RecordSet;
class Data_API RowIterator
/// RowIterator class.
{
public:
typedef std::bidirectional_iterator_tag iterator_category;
typedef Row value_type;
typedef std::ptrdiff_t difference_type;
typedef Row* pointer;
typedef Row& reference;
typedef Row * pointer;
typedef Row & reference;
static const std::size_t POSITION_END;
/// End position indicator.
RowIterator(RecordSet* pRecordSet, bool positionEnd);
RowIterator(RecordSet * pRecordSet, bool positionEnd);
/// Creates the RowIterator and positions it at the end of
/// the recordset if positionEnd is true. Otherwise, it is
/// positioned at the beginning.
RowIterator(const RowIterator& other);
RowIterator(const RowIterator & other);
/// Creates a copy of other RowIterator.
~RowIterator();
/// Destroys the RowIterator.
RowIterator& operator = (const RowIterator& other);
RowIterator & operator=(const RowIterator & other);
/// Assigns the other RowIterator.
bool operator == (const RowIterator& other) const;
bool operator==(const RowIterator & other) const;
/// Equality operator.
bool operator != (const RowIterator& other) const;
bool operator!=(const RowIterator & other) const;
/// Inequality operator.
Row& operator * () const;
Row & operator*() const;
/// Returns reference to the current row.
Row* operator -> () const;
Row * operator->() const;
/// Returns pointer to the current row.
const RowIterator& operator ++ () const;
const RowIterator & operator++() const;
/// Advances by one position and returns current position.
RowIterator operator ++ (int) const;
RowIterator operator++(int) const;
/// Advances by one position and returns copy of the iterator with
/// previous current position.
const RowIterator& operator -- () const;
const RowIterator & operator--() const;
/// Goes back by one position and returns copy of the iterator with
/// previous current position.
RowIterator operator -- (int) const;
RowIterator operator--(int) const;
/// Goes back by one position and returns previous current position.
RowIterator operator + (std::size_t diff) const;
RowIterator operator+(std::size_t diff) const;
/// Returns a copy the RowIterator advanced by diff positions.
RowIterator operator - (std::size_t diff) const;
RowIterator operator-(std::size_t diff) const;
/// Returns a copy the RowIterator backed by diff positions.
/// Throws RangeException if diff is larger than current position.
void swap(RowIterator& other);
void swap(RowIterator & other);
/// Swaps the RowIterator with another one.
private:
private:
RowIterator();
void increment() const;
@ -110,40 +112,40 @@ private:
/// Sets the iterator position.
/// Throws RangeException if position is out of range.
RecordSet* _pRecordSet;
RecordSet * _pRecordSet;
mutable std::size_t _position;
};
};
///
/// inlines
///
///
/// inlines
///
inline bool RowIterator::operator == (const RowIterator& other) const
{
inline bool RowIterator::operator==(const RowIterator & other) const
{
return _pRecordSet == other._pRecordSet && _position == other._position;
}
}
inline bool RowIterator::operator != (const RowIterator& other) const
{
inline bool RowIterator::operator!=(const RowIterator & other) const
{
return _pRecordSet != other._pRecordSet || _position != other._position;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
namespace std
{
template<>
inline void swap<Poco::Data::RowIterator>(Poco::Data::RowIterator& s1,
Poco::Data::RowIterator& s2)
/// Full template specalization of std:::swap for RowIterator
{
template <>
inline void swap<Poco::Data::RowIterator>(Poco::Data::RowIterator & s1, Poco::Data::RowIterator & s2)
/// Full template specalization of std:::swap for RowIterator
{
s1.swap(s2);
}
}
}

View File

@ -18,22 +18,24 @@
#define Data_SQLChannel_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/AutoPtr.h"
#include "Poco/Channel.h"
#include "Poco/Data/ArchiveStrategy.h"
#include "Poco/Data/Connector.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/Statement.h"
#include "Poco/Data/ArchiveStrategy.h"
#include "Poco/Channel.h"
#include "Poco/Message.h"
#include "Poco/AutoPtr.h"
#include "Poco/String.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Data_API SQLChannel: public Poco::Channel
class Data_API SQLChannel : public Poco::Channel
/// This Channel implements logging to a SQL database.
/// The channel is dependent on the schema. The DDL for
/// table creation (subject to target DDL dialect dependent
@ -59,14 +61,12 @@ class Data_API SQLChannel: public Poco::Channel
/// If throw property is false, insertion timeouts are ignored, otherwise a TimeoutException is thrown.
/// To force insertion of every entry, set timeout to 0. This setting, however, introduces
/// a risk of long blocking periods in case of remote server communication delays.
{
public:
{
public:
SQLChannel();
/// Creates SQLChannel.
SQLChannel(const std::string& connector,
const std::string& connect,
const std::string& name = "-");
SQLChannel(const std::string & connector, const std::string & connect, const std::string & name = "-");
/// Creates a SQLChannel with the given connector, connect string, timeout, table and name.
/// The connector must be already registered.
@ -76,10 +76,10 @@ public:
void close();
/// Closes the SQLChannel.
void log(const Message& msg);
void log(const Message & msg);
/// Sends the message's text to the syslog service.
void setProperty(const std::string& name, const std::string& value);
void setProperty(const std::string & name, const std::string & value);
/// Sets the property with the given value.
///
/// The following properties are supported:
@ -118,7 +118,7 @@ public:
/// True values are (case insensitive) "true", "t", "yes", "y".
/// Anything else yields false.
std::string getProperty(const std::string& name) const;
std::string getProperty(const std::string & name) const;
/// Returns the value of the property with the given name.
std::size_t wait();
@ -138,10 +138,10 @@ public:
static const std::string PROP_TIMEOUT;
static const std::string PROP_THROW;
protected:
protected:
~SQLChannel();
private:
private:
typedef Poco::SharedPtr<Session> SessionPtr;
typedef Poco::SharedPtr<Statement> StatementPtr;
typedef Poco::Message::Priority Priority;
@ -153,16 +153,16 @@ private:
void initArchiveStatements();
/// Initiallizes the archive statement.
void logAsync(const Message& msg);
void logAsync(const Message & msg);
/// Waits for previous operation completion and
/// calls logSync(). If the previous operation times out,
/// and _throw is true, TimeoutException is thrown, otherwise
/// the timeout is ignored and log entry is lost.
void logSync(const Message& msg);
void logSync(const Message & msg);
/// Inserts the message in the target database.
bool isTrue(const std::string& value) const;
bool isTrue(const std::string & value) const;
/// Returns true is value is "true", "t", "yes" or "y".
/// Case insensitive.
@ -186,32 +186,31 @@ private:
DateTime _dateTime;
StrategyPtr _pArchiveStrategy;
};
};
//
// inlines
//
//
// inlines
//
inline std::size_t SQLChannel::wait()
{
inline std::size_t SQLChannel::wait()
{
if (_async && _pLogStatement)
return _pLogStatement->wait(_timeout);
return 0;
}
inline bool SQLChannel::isTrue(const std::string & value) const
{
return (
(0 == icompare(value, "true")) || (0 == icompare(value, "t")) || (0 == icompare(value, "yes")) || (0 == icompare(value, "y")));
}
}
inline bool SQLChannel::isTrue(const std::string& value) const
{
return ((0 == icompare(value, "true")) ||
(0 == icompare(value, "t")) ||
(0 == icompare(value, "yes")) ||
(0 == icompare(value, "y")));
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_SQLChannel_INCLUDED

View File

@ -18,24 +18,26 @@
#define Data_Session_INCLUDED
#include <algorithm>
#include "Poco/Any.h"
#include "Poco/AutoPtr.h"
#include "Poco/Data/Binding.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/SessionImpl.h"
#include "Poco/Data/Statement.h"
#include "Poco/Data/StatementCreator.h"
#include "Poco/Data/Binding.h"
#include "Poco/AutoPtr.h"
#include "Poco/Any.h"
#include <algorithm>
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class StatementImpl;
class StatementImpl;
class Data_API Session
class Data_API Session
/// A Session holds a connection to a Database and creates Statement objects.
///
/// Sessions are always created via the SessionFactory:
@ -150,8 +152,8 @@ class Data_API Session
/// If the formatting will occur and the percent sign is part of the query itself, it can be passed to the query by entering it twice (%%).
/// However, if no formatting is used, one percent sign is sufficient as the string will be passed unaltered.
/// For complete list of supported data types with their respective specifications, see the documentation for format in Foundation.
{
public:
{
public:
static const std::size_t LOGIN_TIMEOUT_DEFAULT = SessionImpl::LOGIN_TIMEOUT_DEFAULT;
static const Poco::UInt32 TRANSACTION_READ_UNCOMMITTED = 0x00000001L;
static const Poco::UInt32 TRANSACTION_READ_COMMITTED = 0x00000002L;
@ -161,40 +163,37 @@ public:
Session(Poco::AutoPtr<SessionImpl> ptrImpl);
/// Creates the Session.
Session(const std::string& connector,
const std::string& connectionString,
std::size_t timeout = LOGIN_TIMEOUT_DEFAULT);
Session(const std::string & connector, const std::string & connectionString, std::size_t timeout = LOGIN_TIMEOUT_DEFAULT);
/// Creates a new session, using the given connector (which must have
/// been registered), and connectionString.
Session(const std::string& connection,
std::size_t timeout = LOGIN_TIMEOUT_DEFAULT);
Session(const std::string & connection, std::size_t timeout = LOGIN_TIMEOUT_DEFAULT);
/// Creates a new session, using the given connection (must be in
/// "connection:///connectionString" format).
Session(const Session&);
Session(const Session &);
/// Creates a session by copying another one.
Session& operator = (const Session&);
Session & operator=(const Session &);
/// Assignment operator.
~Session();
/// Destroys the Session.
void swap(Session& other);
void swap(Session & other);
/// Swaps the session with another one.
template <typename T>
Statement operator << (const T& t)
Statement operator<<(const T & t)
/// Creates a Statement with the given data as SQLContent
{
return _statementCreator << t;
}
StatementImpl* createStatementImpl();
StatementImpl * createStatementImpl();
/// Creates a StatementImpl.
void open(const std::string& connect = "");
void open(const std::string & connect = "");
/// Opens the session using the supplied string.
/// Can also be used with default empty string to
/// reconnect a disconnected session.
@ -258,12 +257,11 @@ public:
std::string uri() const;
/// Returns the URI for this session.
static std::string uri(const std::string& connector,
const std::string& connectionString);
static std::string uri(const std::string & connector, const std::string & connectionString);
/// Utility function that teturns the URI formatted from supplied
/// arguments as "connector:///connectionString".
void setFeature(const std::string& name, bool state);
void setFeature(const std::string & name, bool state);
/// Set the state of a feature.
///
/// Features are a generic extension mechanism for session implementations.
@ -272,7 +270,7 @@ public:
/// Throws a NotSupportedException if the requested feature is
/// not supported by the underlying implementation.
bool getFeature(const std::string& name) const;
bool getFeature(const std::string & name) const;
/// Look up the state of a feature.
///
/// Features are a generic extension mechanism for session implementations.
@ -281,7 +279,7 @@ public:
/// Throws a NotSupportedException if the requested feature is
/// not supported by the underlying implementation.
void setProperty(const std::string& name, const Poco::Any& value);
void setProperty(const std::string & name, const Poco::Any & value);
/// Set the value of a property.
///
/// Properties are a generic extension mechanism for session implementations.
@ -290,7 +288,7 @@ public:
/// Throws a NotSupportedException if the requested property is
/// not supported by the underlying implementation.
Poco::Any getProperty(const std::string& name) const;
Poco::Any getProperty(const std::string & name) const;
/// Look up the value of a property.
///
/// Properties are a generic extension mechanism for session implementations.
@ -299,195 +297,194 @@ public:
/// Throws a NotSupportedException if the requested property is
/// not supported by the underlying implementation.
SessionImpl* impl();
SessionImpl * impl();
/// Returns a pointer to the underlying SessionImpl.
private:
private:
Session();
Poco::AutoPtr<SessionImpl> _pImpl;
StatementCreator _statementCreator;
};
};
//
// inlines
//
inline StatementImpl* Session::createStatementImpl()
{
//
// inlines
//
inline StatementImpl * Session::createStatementImpl()
{
return _pImpl->createStatementImpl();
}
}
inline void Session::open(const std::string& connect)
{
inline void Session::open(const std::string & connect)
{
_pImpl->open(connect);
}
}
inline void Session::close()
{
inline void Session::close()
{
_pImpl->close();
}
}
inline bool Session::isConnected()
{
inline bool Session::isConnected()
{
return _pImpl->isConnected();
}
}
inline void Session::reconnect()
{
inline void Session::reconnect()
{
_pImpl->reconnect();
}
}
inline void Session::setLoginTimeout(std::size_t timeout)
{
inline void Session::setLoginTimeout(std::size_t timeout)
{
_pImpl->setLoginTimeout(timeout);
}
}
inline std::size_t Session::getLoginTimeout() const
{
inline std::size_t Session::getLoginTimeout() const
{
return _pImpl->getLoginTimeout();
}
}
inline void Session::setConnectionTimeout(std::size_t timeout)
{
inline void Session::setConnectionTimeout(std::size_t timeout)
{
_pImpl->setConnectionTimeout(timeout);
}
}
inline std::size_t Session::getConnectionTimeout()
{
inline std::size_t Session::getConnectionTimeout()
{
return _pImpl->getConnectionTimeout();
}
}
inline void Session::begin()
{
inline void Session::begin()
{
return _pImpl->begin();
}
}
inline void Session::commit()
{
inline void Session::commit()
{
return _pImpl->commit();
}
}
inline void Session::rollback()
{
inline void Session::rollback()
{
return _pImpl->rollback();
}
}
inline bool Session::canTransact()
{
inline bool Session::canTransact()
{
return _pImpl->canTransact();
}
}
inline bool Session::isTransaction()
{
inline bool Session::isTransaction()
{
return _pImpl->isTransaction();
}
}
inline void Session::setTransactionIsolation(Poco::UInt32 ti)
{
inline void Session::setTransactionIsolation(Poco::UInt32 ti)
{
_pImpl->setTransactionIsolation(ti);
}
}
inline Poco::UInt32 Session::getTransactionIsolation()
{
inline Poco::UInt32 Session::getTransactionIsolation()
{
return _pImpl->getTransactionIsolation();
}
}
inline bool Session::hasTransactionIsolation(Poco::UInt32 ti)
{
inline bool Session::hasTransactionIsolation(Poco::UInt32 ti)
{
return _pImpl->hasTransactionIsolation(ti);
}
}
inline bool Session::isTransactionIsolation(Poco::UInt32 ti)
{
inline bool Session::isTransactionIsolation(Poco::UInt32 ti)
{
return _pImpl->isTransactionIsolation(ti);
}
}
inline std::string Session::connector() const
{
inline std::string Session::connector() const
{
return _pImpl->connectorName();
}
}
inline std::string Session::uri(const std::string& connector,
const std::string& connectionString)
{
inline std::string Session::uri(const std::string & connector, const std::string & connectionString)
{
return SessionImpl::uri(connector, connectionString);
}
}
inline std::string Session::uri() const
{
inline std::string Session::uri() const
{
return _pImpl->uri();
}
}
inline void Session::setFeature(const std::string& name, bool state)
{
inline void Session::setFeature(const std::string & name, bool state)
{
_pImpl->setFeature(name, state);
}
}
inline bool Session::getFeature(const std::string& name) const
{
return const_cast<SessionImpl*>(_pImpl.get())->getFeature(name);
}
inline bool Session::getFeature(const std::string & name) const
{
return const_cast<SessionImpl *>(_pImpl.get())->getFeature(name);
}
inline void Session::setProperty(const std::string& name, const Poco::Any& value)
{
inline void Session::setProperty(const std::string & name, const Poco::Any & value)
{
_pImpl->setProperty(name, value);
}
}
inline Poco::Any Session::getProperty(const std::string& name) const
{
return const_cast<SessionImpl*>(_pImpl.get())->getProperty(name);
}
inline Poco::Any Session::getProperty(const std::string & name) const
{
return const_cast<SessionImpl *>(_pImpl.get())->getProperty(name);
}
inline SessionImpl* Session::impl()
{
inline SessionImpl * Session::impl()
{
return _pImpl;
}
}
inline void swap(Session& s1, Session& s2)
{
inline void swap(Session & s1, Session & s2)
{
s1.swap(s2);
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
namespace std
{
template<>
inline void swap<Poco::Data::Session>(Poco::Data::Session& s1,
Poco::Data::Session& s2)
/// Full template specalization of std:::swap for Session
{
template <>
inline void swap<Poco::Data::Session>(Poco::Data::Session & s1, Poco::Data::Session & s2)
/// Full template specalization of std:::swap for Session
{
s1.swap(s2);
}
}
}

View File

@ -18,20 +18,22 @@
#define Data_SessionFactory_INCLUDED
#include "Poco/Data/Data.h"
#include <map>
#include "Poco/Data/Connector.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/Session.h"
#include "Poco/Mutex.h"
#include "Poco/SharedPtr.h"
#include "Poco/String.h"
#include <map>
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Data_API SessionFactory
class Data_API SessionFactory
/// A SessionFactory is a singleton class that stores Connectors and allows to
/// create Sessions of the required type:
///
@ -48,52 +50,49 @@ class Data_API SessionFactory
/// automatically invokes the SessionFactory:
///
/// Session ses("SQLite", "dummy.db");
{
public:
static SessionFactory& instance();
{
public:
static SessionFactory & instance();
/// returns the static instance of the singleton.
void add(Connector* pIn);
void add(Connector * pIn);
/// Registers a Connector under its key at the factory. If a registration for that
/// key is already active, the first registration will be kept, only its reference count will be increased.
/// Always takes ownership of parameter pIn.
void remove(const std::string& key);
void remove(const std::string & key);
/// Lowers the reference count for the Connector registered under that key. If the count reaches zero,
/// the object is removed.
Session create(const std::string& key,
const std::string& connectionString,
std::size_t timeout = Session::LOGIN_TIMEOUT_DEFAULT);
Session create(const std::string & key, const std::string & connectionString, std::size_t timeout = Session::LOGIN_TIMEOUT_DEFAULT);
/// Creates a Session for the given key with the connectionString. Throws an Poco:Data::UnknownDataBaseException
/// if no Connector is registered for that key.
Session create(const std::string& uri,
std::size_t timeout = Session::LOGIN_TIMEOUT_DEFAULT);
Session create(const std::string & uri, std::size_t timeout = Session::LOGIN_TIMEOUT_DEFAULT);
/// Creates a Session for the given URI (must be in key:///connectionString format).
/// Throws a Poco:Data::UnknownDataBaseException if no Connector is registered for the key.
private:
private:
SessionFactory();
~SessionFactory();
SessionFactory(const SessionFactory&);
SessionFactory& operator = (const SessionFactory&);
SessionFactory(const SessionFactory &);
SessionFactory & operator=(const SessionFactory &);
struct SessionInfo
{
int cnt;
Poco::SharedPtr<Connector> ptrSI;
SessionInfo(Connector* pSI);
SessionInfo(Connector * pSI);
};
typedef std::map<std::string, SessionInfo, Poco::CILess> Connectors;
Connectors _connectors;
Poco::FastMutex _mutex;
};
};
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_SessionFactory_INCLUDED

View File

@ -18,25 +18,27 @@
#define Data_SessionImpl_INCLUDED
#include "Poco/Any.h"
#include "Poco/Data/Data.h"
#include "Poco/Format.h"
#include "Poco/RefCountedObject.h"
#include "Poco/String.h"
#include "Poco/Format.h"
#include "Poco/Any.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class StatementImpl;
class StatementImpl;
class Data_API SessionImpl: public Poco::RefCountedObject
class Data_API SessionImpl : public Poco::RefCountedObject
/// Interface for Session functionality that subclasses must extend.
/// SessionImpl objects are noncopyable.
{
public:
{
public:
static const std::size_t LOGIN_TIMEOUT_INFINITE = 0;
/// Infinite connection/login timeout.
@ -49,17 +51,16 @@ public:
static const std::size_t CONNECTION_TIMEOUT_DEFAULT = CONNECTION_TIMEOUT_INFINITE;
/// Default connection/login timeout in seconds.
SessionImpl(const std::string& connectionString,
std::size_t timeout = LOGIN_TIMEOUT_DEFAULT);
SessionImpl(const std::string & connectionString, std::size_t timeout = LOGIN_TIMEOUT_DEFAULT);
/// Creates the SessionImpl.
virtual ~SessionImpl();
/// Destroys the SessionImpl.
virtual StatementImpl* createStatementImpl() = 0;
virtual StatementImpl * createStatementImpl() = 0;
/// Creates a StatementImpl.
virtual void open(const std::string& connectionString = "") = 0;
virtual void open(const std::string & connectionString = "") = 0;
/// Opens the session using the supplied string.
/// Can also be used with default empty string to reconnect
/// a disconnected session.
@ -117,19 +118,19 @@ public:
/// Returns true iff the transaction isolation level corresponds
/// to the supplied bitmask.
virtual const std::string& connectorName() const = 0;
virtual const std::string & connectorName() const = 0;
/// Returns the name of the connector.
const std::string& connectionString() const;
const std::string & connectionString() const;
/// Returns the connection string.
static std::string uri(const std::string& connector, const std::string& connectionString);
static std::string uri(const std::string & connector, const std::string & connectionString);
/// Returns formatted URI.
std::string uri() const;
/// Returns the URI for this session.
virtual void setFeature(const std::string& name, bool state) = 0;
virtual void setFeature(const std::string & name, bool state) = 0;
/// Set the state of a feature.
///
/// Features are a generic extension mechanism for session implementations.
@ -138,7 +139,7 @@ public:
/// Throws a NotSupportedException if the requested feature is
/// not supported by the underlying implementation.
virtual bool getFeature(const std::string& name) = 0;
virtual bool getFeature(const std::string & name) = 0;
/// Look up the state of a feature.
///
/// Features are a generic extension mechanism for session implementations.
@ -147,7 +148,7 @@ public:
/// Throws a NotSupportedException if the requested feature is
/// not supported by the underlying implementation.
virtual void setProperty(const std::string& name, const Poco::Any& value) = 0;
virtual void setProperty(const std::string & name, const Poco::Any & value) = 0;
/// Set the value of a property.
///
/// Properties are a generic extension mechanism for session implementations.
@ -156,7 +157,7 @@ public:
/// Throws a NotSupportedException if the requested property is
/// not supported by the underlying implementation.
virtual Poco::Any getProperty(const std::string& name) = 0;
virtual Poco::Any getProperty(const std::string & name) = 0;
/// Look up the value of a property.
///
/// Properties are a generic extension mechanism for session implementations.
@ -165,57 +166,57 @@ public:
/// Throws a NotSupportedException if the requested property is
/// not supported by the underlying implementation.
protected:
void setConnectionString(const std::string& connectionString);
protected:
void setConnectionString(const std::string & connectionString);
/// Sets the connection string. Should only be called on
/// disconnetced sessions. Throws InvalidAccessException when called on
/// a connected session.
private:
private:
SessionImpl();
SessionImpl(const SessionImpl&);
SessionImpl& operator = (const SessionImpl&);
SessionImpl(const SessionImpl &);
SessionImpl & operator=(const SessionImpl &);
std::string _connectionString;
std::size_t _loginTimeout;
};
};
//
// inlines
//
inline const std::string& SessionImpl::connectionString() const
{
//
// inlines
//
inline const std::string & SessionImpl::connectionString() const
{
return _connectionString;
}
}
inline void SessionImpl::setLoginTimeout(std::size_t timeout)
{
inline void SessionImpl::setLoginTimeout(std::size_t timeout)
{
_loginTimeout = timeout;
}
}
inline std::size_t SessionImpl::getLoginTimeout() const
{
inline std::size_t SessionImpl::getLoginTimeout() const
{
return _loginTimeout;
}
}
inline std::string SessionImpl::uri(const std::string& connector,
const std::string& connectionString)
{
inline std::string SessionImpl::uri(const std::string & connector, const std::string & connectionString)
{
return format("%s:///%s", connector, connectionString);
}
}
inline std::string SessionImpl::uri() const
{
inline std::string SessionImpl::uri() const
{
return uri(connectorName(), connectionString());
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_SessionImpl_INCLUDED

View File

@ -18,22 +18,24 @@
#define Data_SessionPool_INCLUDED
#include <list>
#include "Poco/Any.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/PooledSessionHolder.h"
#include "Poco/Data/PooledSessionImpl.h"
#include "Poco/Data/Session.h"
#include "Poco/HashMap.h"
#include "Poco/Any.h"
#include "Poco/Timer.h"
#include "Poco/Mutex.h"
#include <list>
#include "Poco/Timer.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Data_API SessionPool: public RefCountedObject
class Data_API SessionPool : public RefCountedObject
/// This class implements session pooling for POCO Data.
///
/// Creating a connection to a database is often a time consuming
@ -65,10 +67,11 @@ class Data_API SessionPool: public RefCountedObject
/// ...
/// Session sess(pool.get());
/// ...
{
public:
SessionPool(const std::string& connector,
const std::string& connectionString,
{
public:
SessionPool(
const std::string & connector,
const std::string & connectionString,
int minSessions = 1,
int maxSessions = 32,
int idleTime = 60);
@ -94,21 +97,20 @@ public:
/// is thrown.
template <typename T>
Session get(const std::string& name, const T& value)
Session get(const std::string & name, const T & value)
/// Returns a Session with requested property set.
/// The property can be different from the default pool
/// value, in which case it is reset back to the pool
/// value when the session is reclaimed by the pool.
{
Session s = get();
_addPropertyMap.insert(AddPropertyMap::value_type(s.impl(),
std::make_pair(name, s.getProperty(name))));
_addPropertyMap.insert(AddPropertyMap::value_type(s.impl(), std::make_pair(name, s.getProperty(name))));
s.setProperty(name, value);
return s;
}
Session get(const std::string& name, bool value);
Session get(const std::string & name, bool value);
/// Returns a Session with requested feature set.
/// The feature can be different from the default pool
/// value, in which case it is reset back to the pool
@ -135,20 +137,19 @@ public:
std::string name() const;
/// Returns the name for this pool.
static std::string name(const std::string& connector,
const std::string& connectionString);
static std::string name(const std::string & connector, const std::string & connectionString);
/// Returns the name formatted from supplied arguments as "connector:///connectionString".
void setFeature(const std::string& name, bool state);
void setFeature(const std::string & name, bool state);
/// Sets feature for all the sessions.
bool getFeature(const std::string& name);
bool getFeature(const std::string & name);
/// Returns the requested feature.
void setProperty(const std::string& name, const Poco::Any& value);
void setProperty(const std::string & name, const Poco::Any & value);
/// Sets property for all sessions.
Poco::Any getProperty(const std::string& name);
Poco::Any getProperty(const std::string & name);
/// Returns the requested property.
void shutdown();
@ -157,8 +158,8 @@ public:
bool isActive() const;
/// Returns true if session pool is active (not shut down).
protected:
virtual void customizeSession(Session& session);
protected:
virtual void customizeSession(Session & session);
/// Can be overridden by subclass to perform custom initialization
/// of a newly created database session.
///
@ -171,21 +172,21 @@ protected:
typedef Poco::HashMap<std::string, Poco::Any> PropertyMap;
void purgeDeadSessions();
int deadImpl(SessionList& rSessions);
void applySettings(SessionImpl* pImpl);
int deadImpl(SessionList & rSessions);
void applySettings(SessionImpl * pImpl);
void putBack(PooledSessionHolderPtr pHolder);
void onJanitorTimer(Poco::Timer&);
void onJanitorTimer(Poco::Timer &);
private:
private:
typedef std::pair<std::string, Poco::Any> PropertyPair;
typedef std::pair<std::string, bool> FeaturePair;
typedef std::map<SessionImpl*, PropertyPair> AddPropertyMap;
typedef std::map<SessionImpl*, FeaturePair> AddFeatureMap;
typedef std::map<SessionImpl *, PropertyPair> AddPropertyMap;
typedef std::map<SessionImpl *, FeaturePair> AddFeatureMap;
SessionPool(const SessionPool&);
SessionPool& operator = (const SessionPool&);
SessionPool(const SessionPool &);
SessionPool & operator=(const SessionPool &);
void closeAll(SessionList& sessionList);
void closeAll(SessionList & sessionList);
std::string _connector;
std::string _connectionString;
@ -201,33 +202,32 @@ private:
bool _shutdown;
AddPropertyMap _addPropertyMap;
AddFeatureMap _addFeatureMap;
mutable
Poco::Mutex _mutex;
mutable Poco::Mutex _mutex;
friend class PooledSessionImpl;
};
};
inline std::string SessionPool::name(const std::string& connector,
const std::string& connectionString)
{
inline std::string SessionPool::name(const std::string & connector, const std::string & connectionString)
{
return Session::uri(connector, connectionString);
}
}
inline std::string SessionPool::name() const
{
inline std::string SessionPool::name() const
{
return name(_connector, _connectionString);
}
}
inline bool SessionPool::isActive() const
{
inline bool SessionPool::isActive() const
{
return !_shutdown;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_SessionPool_INCLUDED

View File

@ -21,30 +21,33 @@
#include "Poco/Data/Data.h"
#include "Poco/Data/Session.h"
#include "Poco/Data/SessionPool.h"
#include "Poco/String.h"
#include "Poco/Mutex.h"
#include "Poco/String.h"
namespace Poco {
namespace Data {
class Data_API SessionPoolContainer
/// This class implements container of session pools.
namespace Poco
{
public:
namespace Data
{
class Data_API SessionPoolContainer
/// This class implements container of session pools.
{
public:
SessionPoolContainer();
/// Creates the SessionPoolContainer for sessions with the given session parameters.
~SessionPoolContainer();
/// Destroys the SessionPoolContainer.
void add(SessionPool* pPool);
void add(SessionPool * pPool);
/// Adds existing session pool to the container.
/// Throws SessionPoolExistsException if pool already exists.
Session add(const std::string& sessionKey,
const std::string& connectionString,
Session
add(const std::string & sessionKey,
const std::string & connectionString,
int minSessions = 1,
int maxSessions = 32,
int idleTime = 60);
@ -52,25 +55,24 @@ public:
/// newly created pool. If pool already exists, request to add is silently
/// ignored and session is returned from the existing pool.
bool has(const std::string& name) const;
bool has(const std::string & name) const;
/// Returns true if the requested name exists, false otherwise.
bool isActive(const std::string& sessionKey,
const std::string& connectionString = "") const;
bool isActive(const std::string & sessionKey, const std::string & connectionString = "") const;
/// Returns true if the session is active (i.e. not shut down).
/// If connectionString is empty string, sessionKey must be a
/// fully qualified session name as registered with the pool
/// container.
Session get(const std::string& name);
Session get(const std::string & name);
/// Returns the requested Session.
/// Throws NotFoundException if session is not found.
SessionPool& getPool(const std::string& name);
SessionPool & getPool(const std::string & name);
/// Returns a SessionPool reference.
/// Throws NotFoundException if session is not found.
void remove(const std::string& name);
void remove(const std::string & name);
/// Removes a SessionPool.
int count() const;
@ -79,36 +81,37 @@ public:
void shutdown();
/// Shuts down all the held pools.
private:
private:
typedef std::map<std::string, AutoPtr<SessionPool>, Poco::CILess> SessionPoolMap;
SessionPoolContainer(const SessionPoolContainer&);
SessionPoolContainer& operator = (const SessionPoolContainer&);
SessionPoolContainer(const SessionPoolContainer &);
SessionPoolContainer & operator=(const SessionPoolContainer &);
SessionPoolMap _sessionPools;
Poco::FastMutex _mutex;
};
};
inline bool SessionPoolContainer::has(const std::string& name) const
{
inline bool SessionPoolContainer::has(const std::string & name) const
{
return _sessionPools.find(name) != _sessionPools.end();
}
}
inline void SessionPoolContainer::remove(const std::string& name)
{
inline void SessionPoolContainer::remove(const std::string & name)
{
_sessionPools.erase(name);
}
}
inline int SessionPoolContainer::count() const
{
inline int SessionPoolContainer::count() const
{
return static_cast<int>(_sessionPools.size());
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_SessionPoolContainer_INCLUDED

View File

@ -22,14 +22,16 @@
#include "Poco/Data/RowFormatter.h"
namespace Poco {
namespace Data {
class Data_API SimpleRowFormatter: public RowFormatter
/// A simple row formatting class.
namespace Poco
{
public:
namespace Data
{
class Data_API SimpleRowFormatter : public RowFormatter
/// A simple row formatting class.
{
public:
//typedef RowFormatter::NameVec NameVec;
//typedef RowFormatter::NameVecPtr NameVecPtr;
//typedef RowFormatter::ValueVec ValueVec;
@ -40,22 +42,22 @@ public:
SimpleRowFormatter(std::streamsize columnWidth = DEFAULT_COLUMN_WIDTH, std::streamsize spacing = DEFAULT_SPACING);
/// Creates the SimpleRowFormatter and sets the column width to specified value.
SimpleRowFormatter(const SimpleRowFormatter& other);
SimpleRowFormatter(const SimpleRowFormatter & other);
/// Creates the copy of the supplied SimpleRowFormatter.
SimpleRowFormatter& operator = (const SimpleRowFormatter& row);
SimpleRowFormatter & operator=(const SimpleRowFormatter & row);
/// Assignment operator.
~SimpleRowFormatter();
/// Destroys the SimpleRowFormatter.
void swap(SimpleRowFormatter& other);
void swap(SimpleRowFormatter & other);
/// Swaps the row formatter with another one.
std::string& formatNames(const NameVecPtr pNames, std::string& formattedNames);
std::string & formatNames(const NameVecPtr pNames, std::string & formattedNames);
/// Formats the row field names.
std::string& formatValues(const ValueVec& vals, std::string& formattedValues);
std::string & formatValues(const ValueVec & vals, std::string & formattedValues);
/// Formats the row values.
int rowCount() const;
@ -70,52 +72,52 @@ public:
std::streamsize getSpacing() const;
/// Returns the spacing.
private:
private:
std::streamsize _colWidth;
std::streamsize _spacing;
int _rowCount;
};
};
///
/// inlines
///
inline int SimpleRowFormatter::rowCount() const
{
///
/// inlines
///
inline int SimpleRowFormatter::rowCount() const
{
return _rowCount;
}
}
inline void SimpleRowFormatter::setColumnWidth(std::streamsize columnWidth)
{
inline void SimpleRowFormatter::setColumnWidth(std::streamsize columnWidth)
{
_colWidth = columnWidth;
}
}
inline std::streamsize SimpleRowFormatter::getColumnWidth() const
{
inline std::streamsize SimpleRowFormatter::getColumnWidth() const
{
return _colWidth;
}
}
inline std::streamsize SimpleRowFormatter::getSpacing() const
{
inline std::streamsize SimpleRowFormatter::getSpacing() const
{
return _spacing;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
namespace std
{
template<>
inline void swap<Poco::Data::SimpleRowFormatter>(Poco::Data::SimpleRowFormatter& s1,
Poco::Data::SimpleRowFormatter& s2)
/// Full template specalization of std:::swap for SimpleRowFormatter
{
template <>
inline void swap<Poco::Data::SimpleRowFormatter>(Poco::Data::SimpleRowFormatter & s1, Poco::Data::SimpleRowFormatter & s2)
/// Full template specalization of std:::swap for SimpleRowFormatter
{
s1.swap(s2);
}
}
}

View File

@ -18,32 +18,34 @@
#define Data_Statement_INCLUDED
#include "Poco/Data/Data.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/Binding.h"
#include "Poco/Data/Range.h"
#include "Poco/Data/Bulk.h"
#include "Poco/Data/Row.h"
#include "Poco/Data/SimpleRowFormatter.h"
#include "Poco/SharedPtr.h"
#include "Poco/Mutex.h"
#include <algorithm>
#include "Poco/ActiveMethod.h"
#include "Poco/ActiveResult.h"
#include "Poco/Data/Binding.h"
#include "Poco/Data/Bulk.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/Range.h"
#include "Poco/Data/Row.h"
#include "Poco/Data/SimpleRowFormatter.h"
#include "Poco/Data/StatementImpl.h"
#include "Poco/Format.h"
#include <algorithm>
#include "Poco/Mutex.h"
#include "Poco/SharedPtr.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class AbstractBinding;
class AbstractExtraction;
class Session;
class Limit;
class AbstractBinding;
class AbstractExtraction;
class Session;
class Limit;
class Data_API Statement
class Data_API Statement
/// A Statement is used to execute SQL statements.
/// It does not contain code of its own.
/// Its main purpose is to forward calls to the concrete StatementImpl stored inside.
@ -70,9 +72,9 @@ class Data_API Statement
/// member function.
/// If no formatter is externally supplied to the statement, the SimpleRowFormatter is lazy
/// created and used.
{
public:
typedef void (*Manipulator)(Statement&);
{
public:
typedef void (*Manipulator)(Statement &);
typedef ActiveResult<std::size_t> Result;
typedef SharedPtr<Result> ResultPtr;
@ -92,7 +94,7 @@ public:
Statement(StatementImpl::Ptr pImpl);
/// Creates the Statement.
explicit Statement(Session& session);
explicit Statement(Session & session);
/// Creates the Statement for the given Session.
///
/// The following:
@ -109,107 +111,112 @@ public:
~Statement();
/// Destroys the Statement.
Statement(const Statement& stmt);
Statement(const Statement & stmt);
/// Copy constructor.
/// If the statement has been executed asynchronously and has not been
/// synchronized prior to copy operation (i.e. is copied while executing),
/// this constructor shall synchronize it.
Statement& operator = (const Statement& stmt);
Statement & operator=(const Statement & stmt);
/// Assignment operator.
void swap(Statement& other);
void swap(Statement & other);
/// Swaps the statement with another one.
template <typename T>
Statement& operator << (const T& t)
Statement & operator<<(const T & t)
/// Concatenates data with the SQL statement string.
{
_pImpl->add(t);
return *this;
}
Statement& operator , (Manipulator manip);
Statement & operator,(Manipulator manip);
/// Handles manipulators, such as now, async, etc.
Statement& operator , (AbstractBinding::Ptr pBind);
Statement & operator,(AbstractBinding::Ptr pBind);
/// Registers the Binding with the Statement by calling addBind().
Statement& addBind(AbstractBinding::Ptr pBind);
Statement & addBind(AbstractBinding::Ptr pBind);
/// Registers a single binding with the statement.
void removeBind(const std::string& name);
void removeBind(const std::string & name);
/// Removes the all the bindings with specified name from the statement.
Statement& operator , (AbstractBindingVec& bindVec);
Statement & operator,(AbstractBindingVec & bindVec);
/// Registers the Binding vector with the Statement.
template <typename C>
Statement& addBinding(C& bindingCont, bool reset)
Statement & addBinding(C & bindingCont, bool reset)
/// Registers binding container with the Statement.
{
if (reset) _pImpl->resetBinding();
if (reset)
_pImpl->resetBinding();
typename C::iterator itAB = bindingCont.begin();
typename C::iterator itABEnd = bindingCont.end();
for (; itAB != itABEnd; ++itAB) addBind(*itAB);
for (; itAB != itABEnd; ++itAB)
addBind(*itAB);
return *this;
}
template <typename C>
Statement& bind(const C& value)
Statement & bind(const C & value)
/// Adds a binding to the Statement. This can be used to implement
/// generic binding mechanisms and is a nicer syntax for:
///
/// statement , bind(value);
{
(*this) , Keywords::bind(value);
(*this), Keywords::bind(value);
return *this;
}
Statement& operator , (AbstractExtraction::Ptr extract);
Statement & operator,(AbstractExtraction::Ptr extract);
/// Registers objects used for extracting data with the Statement by
/// calling addExtract().
Statement& operator , (AbstractExtractionVec& extVec);
Statement & operator,(AbstractExtractionVec & extVec);
/// Registers the extraction vector with the Statement.
/// The vector is registered at position 0 (i.e. for the first returned data set).
Statement& operator , (AbstractExtractionVecVec& extVecVec);
Statement & operator,(AbstractExtractionVecVec & extVecVec);
/// Registers the vector of extraction vectors with the Statement.
template <typename C>
Statement& addExtraction(C& val, bool reset)
Statement & addExtraction(C & val, bool reset)
/// Registers extraction container with the Statement.
{
if (reset) _pImpl->resetExtraction();
if (reset)
_pImpl->resetExtraction();
typename C::iterator itAE = val.begin();
typename C::iterator itAEEnd = val.end();
for (; itAE != itAEEnd; ++itAE) addExtract(*itAE);
for (; itAE != itAEEnd; ++itAE)
addExtract(*itAE);
return *this;
}
template <typename C>
Statement& addExtractions(C& val)
Statement & addExtractions(C & val)
/// Registers container of extraction containers with the Statement.
{
_pImpl->resetExtraction();
typename C::iterator itAEV = val.begin();
typename C::iterator itAEVEnd = val.end();
for (; itAEV != itAEVEnd; ++itAEV) addExtraction(*itAEV, false);
for (; itAEV != itAEVEnd; ++itAEV)
addExtraction(*itAEV, false);
return *this;
}
Statement& addExtract(AbstractExtraction::Ptr pExtract);
Statement & addExtract(AbstractExtraction::Ptr pExtract);
/// Registers a single extraction with the statement.
Statement& operator , (const Bulk& bulk);
Statement & operator,(const Bulk & bulk);
/// Sets the bulk execution mode (both binding and extraction) for this
/// statement.Statement must not have any extractors or binders set at the
/// time when this operator is applied.
/// Failure to adhere to the above constraint shall result in
/// InvalidAccessException.
Statement& operator , (BulkFnType);
Statement & operator,(BulkFnType);
/// Sets the bulk execution mode (both binding and extraction) for this
/// statement.Statement must not have any extractors or binders set at the
/// time when this operator is applied.
@ -218,69 +225,69 @@ public:
/// Failure to adhere to the above constraints shall result in
/// InvalidAccessException.
Statement& operator , (const Limit& extrLimit);
Statement & operator,(const Limit & extrLimit);
/// Sets a limit on the maximum number of rows a select is allowed to return.
///
/// Set per default to zero to Limit::LIMIT_UNLIMITED, which disables the limit.
Statement& operator , (RowFormatter::Ptr pRowFformatter);
Statement & operator,(RowFormatter::Ptr pRowFformatter);
/// Sets the row formatter for the statement.
Statement& operator , (const Range& extrRange);
Statement & operator,(const Range & extrRange);
/// Sets a an extraction range for the maximum number of rows a select is allowed to return.
///
/// Set per default to Limit::LIMIT_UNLIMITED which disables the range.
Statement& operator , (char value);
Statement & operator,(char value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (Poco::UInt8 value);
Statement & operator,(Poco::UInt8 value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (Poco::Int8 value);
Statement & operator,(Poco::Int8 value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (Poco::UInt16 value);
Statement & operator,(Poco::UInt16 value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (Poco::Int16 value);
Statement & operator,(Poco::Int16 value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (Poco::UInt32 value);
Statement & operator,(Poco::UInt32 value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (Poco::Int32 value);
Statement & operator,(Poco::Int32 value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
#ifndef POCO_LONG_IS_64_BIT
Statement& operator , (long value);
Statement & operator,(long value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (unsigned long value);
Statement & operator,(unsigned long value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
#endif
Statement& operator , (Poco::UInt64 value);
Statement & operator,(Poco::UInt64 value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (Poco::Int64 value);
Statement & operator,(Poco::Int64 value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (double value);
Statement & operator,(double value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (float value);
Statement & operator,(float value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (bool value);
Statement & operator,(bool value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (const std::string& value);
Statement & operator,(const std::string & value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
Statement& operator , (const char* value);
Statement & operator,(const char * value);
/// Adds the value to the list of values to be supplied to the SQL string formatting function.
const std::string& toString() const;
const std::string & toString() const;
/// Creates a string from the accumulated SQL statement.
std::size_t execute(bool reset = true);
@ -296,7 +303,7 @@ public:
/// The result of execution (i.e. number of returned or affected rows) can be
/// obtained by calling wait() on the statement at a later point in time.
const Result& executeAsync(bool reset = true);
const Result & executeAsync(bool reset = true);
/// Executes the statement asynchronously.
/// Stops when either a limit is hit or the whole statement was executed.
/// Returns immediately. Calling wait() (on either the result returned from this
@ -330,7 +337,7 @@ public:
/// Returns true if the statement was completely executed or false if a range limit stopped it
/// and there is more work to do. When no limit is set, it will always return true after calling execute().
Statement& reset(Session& session);
Statement & reset(Session & session);
/// Resets the Statement so that it can be filled with a new SQL command.
bool canModifyStorage();
@ -339,10 +346,10 @@ public:
Storage storage() const;
/// Returns the internal storage type for the statement.
void setStorage(const std::string& storage);
void setStorage(const std::string & storage);
/// Sets the internal storage type for the statement.
const std::string& getStorage() const;
const std::string & getStorage() const;
/// Returns the internal storage type for the statement.
std::size_t columnsExtracted(int dataSet = StatementImpl::USE_CURRENT_DATA_SET) const;
@ -378,16 +385,16 @@ public:
/// Sets the row formatter for this statement.
/// Statement takes the ownership of the formatter.
protected:
protected:
typedef StatementImpl::Ptr ImplPtr;
const AbstractExtractionVec& extractions() const;
const AbstractExtractionVec & extractions() const;
/// Returns the extractions vector.
const MetaColumn& metaColumn(std::size_t pos) const;
const MetaColumn & metaColumn(std::size_t pos) const;
/// Returns the type for the column at specified position.
const MetaColumn& metaColumn(const std::string& name) const;
const MetaColumn & metaColumn(const std::string & name) const;
/// Returns the type for the column with specified name.
bool isNull(std::size_t col, std::size_t row) const;
@ -399,19 +406,18 @@ protected:
ImplPtr impl() const;
/// Returns pointer to statement implementation.
const RowFormatter::Ptr& getRowFormatter();
const RowFormatter::Ptr & getRowFormatter();
/// Returns the row formatter for this statement.
Session session();
/// Returns the underlying session.
private:
const Result& doAsyncExec(bool reset = true);
private:
const Result & doAsyncExec(bool reset = true);
/// Asynchronously executes the statement.
template <typename T>
Statement& commaPODImpl(const T& val)
Statement & commaPODImpl(const T & val)
{
_arguments.push_back(val);
return *this;
@ -427,395 +433,397 @@ private:
std::vector<Any> _arguments;
RowFormatter::Ptr _pRowFormatter;
mutable std::string _stmtString;
};
};
//
// inlines
//
// inlines
inline std::size_t Statement::subTotalRowCount(int dataSet) const
{
inline std::size_t Statement::subTotalRowCount(int dataSet) const
{
return _pImpl->subTotalRowCount(dataSet);
}
}
namespace Keywords {
namespace Keywords
{
//
// Manipulators
//
//
// Manipulators
//
inline void Data_API now(Statement& statement)
inline void Data_API now(Statement & statement)
/// Enforces immediate execution of the statement.
/// If _isAsync flag has been set, execution is invoked asynchronously.
{
{
statement.execute();
}
}
inline void Data_API sync(Statement& statement)
inline void Data_API sync(Statement & statement)
/// Sets the _isAsync flag to false, signalling synchronous execution.
/// Synchronous execution is default, so specifying this manipulator
/// only makes sense if async() was called for the statement before.
{
{
statement.setAsync(false);
}
}
inline void Data_API async(Statement& statement)
inline void Data_API async(Statement & statement)
/// Sets the _async flag to true, signalling asynchronous execution.
{
{
statement.setAsync(true);
}
}
inline void Data_API deque(Statement& statement)
inline void Data_API deque(Statement & statement)
/// Sets the internal storage to std::deque.
/// std::deque is default storage, so specifying this manipulator
/// only makes sense if list() or deque() were called for the statement before.
{
{
if (!statement.canModifyStorage())
throw InvalidAccessException("Storage not modifiable.");
statement.setStorage("deque");
}
}
inline void Data_API vector(Statement& statement)
inline void Data_API vector(Statement & statement)
/// Sets the internal storage to std::vector.
{
{
if (!statement.canModifyStorage())
throw InvalidAccessException("Storage not modifiable.");
statement.setStorage("vector");
}
}
inline void Data_API list(Statement& statement)
inline void Data_API list(Statement & statement)
/// Sets the internal storage to std::list.
{
{
if (!statement.canModifyStorage())
throw InvalidAccessException("Storage not modifiable.");
statement.setStorage("list");
}
}
inline void Data_API reset(Statement& statement)
inline void Data_API reset(Statement & statement)
/// Sets all internal settings to their respective default values.
{
{
if (!statement.canModifyStorage())
throw InvalidAccessException("Storage not modifiable.");
statement.setStorage("deque");
statement.setAsync(false);
}
}
} // namespace Keywords
} // namespace Keywords
//
// inlines
//
//
// inlines
//
inline Statement& Statement::operator , (RowFormatter::Ptr pRowFformatter)
{
inline Statement &Statement::operator,(RowFormatter::Ptr pRowFformatter)
{
_pRowFormatter = pRowFformatter;
return *this;
}
}
inline Statement& Statement::operator , (char value)
{
inline Statement &Statement::operator,(char value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (Poco::UInt8 value)
{
inline Statement &Statement::operator,(Poco::UInt8 value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (Poco::Int8 value)
{
inline Statement &Statement::operator,(Poco::Int8 value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (Poco::UInt16 value)
{
inline Statement &Statement::operator,(Poco::UInt16 value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (Poco::Int16 value)
{
inline Statement &Statement::operator,(Poco::Int16 value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (Poco::UInt32 value)
{
inline Statement &Statement::operator,(Poco::UInt32 value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (Poco::Int32 value)
{
inline Statement &Statement::operator,(Poco::Int32 value)
{
return commaPODImpl(value);
}
}
#ifndef POCO_LONG_IS_64_BIT
inline Statement& Statement::operator , (long value)
{
inline Statement &Statement::operator,(long value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (unsigned long value)
{
inline Statement &Statement::operator,(unsigned long value)
{
return commaPODImpl(value);
}
}
#endif
inline Statement& Statement::operator , (Poco::UInt64 value)
{
inline Statement &Statement::operator,(Poco::UInt64 value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (Poco::Int64 value)
{
inline Statement &Statement::operator,(Poco::Int64 value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (double value)
{
inline Statement &Statement::operator,(double value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (float value)
{
inline Statement &Statement::operator,(float value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (bool value)
{
inline Statement &Statement::operator,(bool value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (const std::string& value)
{
inline Statement &Statement::operator,(const std::string &value)
{
return commaPODImpl(value);
}
}
inline Statement& Statement::operator , (const char* value)
{
inline Statement &Statement::operator,(const char *value)
{
return commaPODImpl(std::string(value));
}
}
inline void Statement::removeBind(const std::string& name)
{
inline void Statement::removeBind(const std::string & name)
{
_pImpl->removeBind(name);
}
}
inline Statement& Statement::operator , (AbstractBinding::Ptr pBind)
{
inline Statement &Statement::operator,(AbstractBinding::Ptr pBind)
{
return addBind(pBind);
}
}
inline Statement& Statement::operator , (AbstractBindingVec& bindVec)
{
inline Statement &Statement::operator,(AbstractBindingVec &bindVec)
{
return addBinding(bindVec, false);
}
}
inline Statement& Statement::operator , (AbstractExtraction::Ptr pExtract)
{
inline Statement &Statement::operator,(AbstractExtraction::Ptr pExtract)
{
return addExtract(pExtract);
}
}
inline Statement& Statement::operator , (AbstractExtractionVec& extVec)
{
inline Statement &Statement::operator,(AbstractExtractionVec &extVec)
{
return addExtraction(extVec, false);
}
}
inline Statement& Statement::operator , (AbstractExtractionVecVec& extVecVec)
{
inline Statement &Statement::operator,(AbstractExtractionVecVec &extVecVec)
{
return addExtractions(extVecVec);
}
}
inline Statement::ImplPtr Statement::impl() const
{
inline Statement::ImplPtr Statement::impl() const
{
return _pImpl;
}
}
inline const std::string& Statement::toString() const
{
inline const std::string & Statement::toString() const
{
return _stmtString = _pImpl->toString();
}
}
inline const AbstractExtractionVec& Statement::extractions() const
{
inline const AbstractExtractionVec & Statement::extractions() const
{
return _pImpl->extractions();
}
}
inline const MetaColumn& Statement::metaColumn(std::size_t pos) const
{
inline const MetaColumn & Statement::metaColumn(std::size_t pos) const
{
return _pImpl->metaColumn(pos);
}
}
inline const MetaColumn& Statement::metaColumn(const std::string& name) const
{
inline const MetaColumn & Statement::metaColumn(const std::string & name) const
{
return _pImpl->metaColumn(name);
}
}
inline void Statement::setStorage(const std::string& storage)
{
inline void Statement::setStorage(const std::string & storage)
{
_pImpl->setStorage(storage);
}
}
inline std::size_t Statement::extractionCount() const
{
inline std::size_t Statement::extractionCount() const
{
return _pImpl->extractionCount();
}
}
inline std::size_t Statement::columnsExtracted(int dataSet) const
{
inline std::size_t Statement::columnsExtracted(int dataSet) const
{
return _pImpl->columnsExtracted(dataSet);
}
}
inline std::size_t Statement::rowsExtracted(int dataSet) const
{
inline std::size_t Statement::rowsExtracted(int dataSet) const
{
return _pImpl->rowsExtracted(dataSet);
}
}
inline std::size_t Statement::dataSetCount() const
{
inline std::size_t Statement::dataSetCount() const
{
return _pImpl->dataSetCount();
}
}
inline std::size_t Statement::nextDataSet()
{
inline std::size_t Statement::nextDataSet()
{
return _pImpl->activateNextDataSet();
}
}
inline std::size_t Statement::previousDataSet()
{
inline std::size_t Statement::previousDataSet()
{
return _pImpl->activatePreviousDataSet();
}
}
inline bool Statement::hasMoreDataSets() const
{
inline bool Statement::hasMoreDataSets() const
{
return _pImpl->hasMoreDataSets();
}
}
inline Statement::Storage Statement::storage() const
{
inline Statement::Storage Statement::storage() const
{
return static_cast<Storage>(_pImpl->getStorage());
}
}
inline bool Statement::canModifyStorage()
{
inline bool Statement::canModifyStorage()
{
return (0 == extractionCount()) && (initialized() || done());
}
}
inline bool Statement::initialized()
{
inline bool Statement::initialized()
{
return _pImpl->getState() == StatementImpl::ST_INITIALIZED;
}
}
inline bool Statement::paused()
{
inline bool Statement::paused()
{
return _pImpl->getState() == StatementImpl::ST_PAUSED;
}
}
inline bool Statement::done()
{
inline bool Statement::done()
{
return _pImpl->getState() == StatementImpl::ST_DONE;
}
}
inline bool Statement::isNull(std::size_t col, std::size_t row) const
{
inline bool Statement::isNull(std::size_t col, std::size_t row) const
{
return _pImpl->isNull(col, row);
}
}
inline bool Statement::isBulkExtraction() const
{
inline bool Statement::isBulkExtraction() const
{
return _pImpl->isBulkExtraction();
}
}
inline bool Statement::isAsync() const
{
inline bool Statement::isAsync() const
{
return _async;
}
}
inline void Statement::setRowFormatter(RowFormatter::Ptr pRowFormatter)
{
inline void Statement::setRowFormatter(RowFormatter::Ptr pRowFormatter)
{
_pRowFormatter = pRowFormatter;
}
}
inline const RowFormatter::Ptr& Statement::getRowFormatter()
{
if (!_pRowFormatter) _pRowFormatter = new SimpleRowFormatter;
inline const RowFormatter::Ptr & Statement::getRowFormatter()
{
if (!_pRowFormatter)
_pRowFormatter = new SimpleRowFormatter;
return _pRowFormatter;
}
}
inline void swap(Statement& s1, Statement& s2)
{
inline void swap(Statement & s1, Statement & s2)
{
s1.swap(s2);
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
namespace std
{
template<>
inline void swap<Poco::Data::Statement>(Poco::Data::Statement& s1,
Poco::Data::Statement& s2)
/// Full template specalization of std:::swap for Statement
{
template <>
inline void swap<Poco::Data::Statement>(Poco::Data::Statement & s1, Poco::Data::Statement & s2)
/// Full template specalization of std:::swap for Statement
{
s1.swap(s2);
}
}
}

View File

@ -18,40 +18,42 @@
#define Data_StatementCreator_INCLUDED
#include "Poco/AutoPtr.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/SessionImpl.h"
#include "Poco/Data/Statement.h"
#include "Poco/AutoPtr.h"
namespace Poco {
namespace Data {
class Data_API StatementCreator
/// A StatementCreator creates Statements.
namespace Poco
{
public:
namespace Data
{
class Data_API StatementCreator
/// A StatementCreator creates Statements.
{
public:
StatementCreator();
/// Creates an uninitialized StatementCreator.
StatementCreator(Poco::AutoPtr<SessionImpl> ptrImpl);
/// Creates a StatementCreator.
StatementCreator(const StatementCreator& other);
StatementCreator(const StatementCreator & other);
/// Creates a StatementCreator by copying another one.
~StatementCreator();
/// Destroys the StatementCreator.
StatementCreator& operator = (const StatementCreator& other);
StatementCreator & operator=(const StatementCreator & other);
/// Assignment operator.
void swap(StatementCreator& other);
void swap(StatementCreator & other);
/// Swaps the StatementCreator with another one.
template <typename T>
Statement operator << (const T& t)
Statement operator<<(const T & t)
/// Creates a Statement.
{
if (!_ptrImpl->isConnected())
@ -62,12 +64,13 @@ public:
return stmt;
}
private:
private:
Poco::AutoPtr<SessionImpl> _ptrImpl;
};
};
} } // namespace Poco::Data
}
} // namespace Poco::Data
#endif // Data_StatementCreator_INCLUDED

View File

@ -18,36 +18,38 @@
#define Data_StatementImpl_INCLUDED
#include "Poco/Data/Data.h"
#include <deque>
#include <list>
#include <sstream>
#include <string>
#include <vector>
#include "Poco/Data/AbstractBinding.h"
#include "Poco/Data/AbstractExtraction.h"
#include "Poco/Data/Range.h"
#include "Poco/Data/Bulk.h"
#include "Poco/Data/Column.h"
#include "Poco/Data/Extraction.h"
#include "Poco/Data/BulkExtraction.h"
#include "Poco/Data/Column.h"
#include "Poco/Data/Data.h"
#include "Poco/Data/Extraction.h"
#include "Poco/Data/Range.h"
#include "Poco/Data/SessionImpl.h"
#include "Poco/Exception.h"
#include "Poco/Format.h"
#include "Poco/RefCountedObject.h"
#include "Poco/String.h"
#include "Poco/Format.h"
#include "Poco/Exception.h"
#include <vector>
#include <list>
#include <deque>
#include <string>
#include <sstream>
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Data_API StatementImpl
class Data_API StatementImpl
/// StatementImpl interface that subclasses must implement to define database dependent query execution.
///
/// StatementImpl's are noncopyable.
{
public:
{
public:
typedef Poco::SharedPtr<StatementImpl> Ptr;
enum State
@ -93,14 +95,14 @@ public:
static const int USE_CURRENT_DATA_SET = -1;
StatementImpl(SessionImpl& rSession);
StatementImpl(SessionImpl & rSession);
/// Creates the StatementImpl.
virtual ~StatementImpl();
/// Destroys the StatementImpl.
template <typename T>
void add(const T& t)
void add(const T & t)
/// Appends SQL statement (fragments).
{
_ostr << t;
@ -109,21 +111,21 @@ public:
void addBind(AbstractBinding::Ptr pBinding);
/// Registers the Binding with the StatementImpl.
void removeBind(const std::string& name);
void removeBind(const std::string & name);
/// Unregisters all the bindings having specified name with the StatementImpl.
/// Bindings are released and, if this class was the sole owner, deleted.
void addExtract(AbstractExtraction::Ptr pExtraction);
/// Registers objects used for extracting data with the StatementImpl.
void setExtractionLimit(const Limit& extrLimit);
void setExtractionLimit(const Limit & extrLimit);
/// Changes the extractionLimit to extrLimit.
/// Per default no limit (EXTRACT_UNLIMITED) is set.
std::string toString() const;
/// Create a string version of the SQL statement.
std::size_t execute(const bool& reset = true);
std::size_t execute(const bool & reset = true);
/// Executes a statement. Returns the number of rows
/// extracted for statements returning data or number of rows
/// affected for all other statements (insert, update, delete).
@ -142,7 +144,7 @@ public:
void setStorage(Storage storage);
/// Sets the storage type for this statement;
void setStorage(const std::string& storage);
void setStorage(const std::string & storage);
/// Sets the storage type for this statement;
Storage getStorage() const;
@ -155,7 +157,7 @@ public:
std::size_t dataSetCount() const;
/// Returns the number of data sets associated with the statement.
protected:
protected:
virtual std::size_t columnsReturned() const = 0;
/// Returns number of columns returned by query.
@ -167,10 +169,10 @@ protected:
/// some ODBC drivers when this function is called after a select statement
/// execution).
virtual const MetaColumn& metaColumn(std::size_t pos) const = 0;
virtual const MetaColumn & metaColumn(std::size_t pos) const = 0;
/// Returns column meta data.
const MetaColumn& metaColumn(const std::string& name) const;
const MetaColumn & metaColumn(const std::string & name) const;
/// Returns column meta data.
virtual bool hasNext() = 0;
@ -202,10 +204,10 @@ protected:
virtual AbstractExtraction::ExtractorPtr extractor() = 0;
/// Returns the concrete extractor used by the statement.
const AbstractExtractionVec& extractions() const;
const AbstractExtractionVec & extractions() const;
/// Returns the const reference to extractions vector.
AbstractExtractionVec& extractions();
AbstractExtractionVec & extractions();
/// Returns the reference to extractions vector.
void fixupExtraction();
@ -214,7 +216,7 @@ protected:
Limit::SizeT getExtractionLimit();
/// Returns the extraction limit value.
const Limit& extractionLimit() const;
const Limit & extractionLimit() const;
/// Returns the extraction limit.
std::size_t columnsExtracted(int dataSet = USE_CURRENT_DATA_SET) const;
@ -250,16 +252,16 @@ protected:
/// - std::vector
/// - std::list
SessionImpl& session();
SessionImpl & session();
/// Rteurns session associated with this statement.
virtual AbstractBinding::BinderPtr binder() = 0;
/// Returns the concrete binder used by the statement.
const AbstractBindingVec& bindings() const;
const AbstractBindingVec & bindings() const;
/// Returns the const reference to bindings vector.
AbstractBindingVec& bindings();
AbstractBindingVec & bindings();
/// Returns the reference to bindings.
void fixupBinding();
@ -296,7 +298,7 @@ protected:
bool hasMoreDataSets() const;
/// Returns true if there are data sets not activated yet.
private:
private:
void compile();
/// Compiles the statement.
@ -317,26 +319,24 @@ private:
/// Resets extraction so it can be reused again.
template <class C>
SharedPtr<InternalExtraction<C> > createExtract(const MetaColumn& mc)
SharedPtr<InternalExtraction<C>> createExtract(const MetaColumn & mc)
{
C* pData = new C;
Column<C>* pCol = new Column<C>(mc, pData);
C * pData = new C;
Column<C> * pCol = new Column<C>(mc, pData);
return new InternalExtraction<C>(*pData, pCol, Poco::UInt32(currentDataSet()));
}
template <class C>
SharedPtr<InternalBulkExtraction<C> > createBulkExtract(const MetaColumn& mc)
SharedPtr<InternalBulkExtraction<C>> createBulkExtract(const MetaColumn & mc)
{
C* pData = new C;
Column<C>* pCol = new Column<C>(mc, pData);
return new InternalBulkExtraction<C>(*pData,
pCol,
static_cast<Poco::UInt32>(getExtractionLimit()),
Position(static_cast<Poco::UInt32>(currentDataSet())));
C * pData = new C;
Column<C> * pCol = new Column<C>(mc, pData);
return new InternalBulkExtraction<C>(
*pData, pCol, static_cast<Poco::UInt32>(getExtractionLimit()), Position(static_cast<Poco::UInt32>(currentDataSet())));
}
template <class T>
void addInternalExtract(const MetaColumn& mc)
void addInternalExtract(const MetaColumn & mc)
/// Creates and adds the internal extraction.
///
/// The decision about internal extraction container is done
@ -353,38 +353,42 @@ private:
switch (_storage)
{
case STORAGE_DEQUE_IMPL:
storage = DEQUE; break;
storage = DEQUE;
break;
case STORAGE_VECTOR_IMPL:
storage = VECTOR; break;
storage = VECTOR;
break;
case STORAGE_LIST_IMPL:
storage = LIST; break;
storage = LIST;
break;
case STORAGE_UNKNOWN_IMPL:
storage = AnyCast<std::string>(session().getProperty("storage"));
break;
}
if (storage.empty()) storage = DEQUE;
if (storage.empty())
storage = DEQUE;
if (0 == icompare(DEQUE, storage))
{
if (!isBulkExtraction())
addExtract(createExtract<std::deque<T> >(mc));
addExtract(createExtract<std::deque<T>>(mc));
else
addExtract(createBulkExtract<std::deque<T> >(mc));
addExtract(createBulkExtract<std::deque<T>>(mc));
}
else if (0 == icompare(VECTOR, storage))
{
if (!isBulkExtraction())
addExtract(createExtract<std::vector<T> >(mc));
addExtract(createExtract<std::vector<T>>(mc));
else
addExtract(createBulkExtract<std::vector<T> >(mc));
addExtract(createBulkExtract<std::vector<T>>(mc));
}
else if (0 == icompare(LIST, storage))
{
if (!isBulkExtraction())
addExtract(createExtract<std::list<T> >(mc));
addExtract(createExtract<std::list<T>>(mc));
else
addExtract(createBulkExtract<std::list<T> >(mc));
addExtract(createBulkExtract<std::list<T>>(mc));
}
}
@ -397,7 +401,7 @@ private:
void setBulkBinding();
/// Sets the bulk binding flag.
void setBulkExtraction(const Bulk& l);
void setBulkExtraction(const Bulk & l);
/// Sets the bulk extraction flag and extraction limit.
void resetBulk();
@ -422,13 +426,13 @@ private:
bool isBulkSupported() const;
/// Returns true if connector and session support bulk operation.
void formatSQL(std::vector<Any>& arguments);
void formatSQL(std::vector<Any> & arguments);
/// Formats the SQL string by filling in placeholders with values from supplied vector.
void assignSubTotal(bool reset);
StatementImpl(const StatementImpl& stmt);
StatementImpl& operator = (const StatementImpl& stmt);
StatementImpl(const StatementImpl & stmt);
StatementImpl & operator=(const StatementImpl & stmt);
typedef std::vector<std::size_t> CountVec;
@ -436,7 +440,7 @@ private:
Limit _extrLimit;
std::size_t _lowerLimit;
std::vector<int> _columnsExtracted;
SessionImpl& _rSession;
SessionImpl & _rSession;
Storage _storage;
std::ostringstream _ostr;
AbstractBindingVec _bindings;
@ -447,186 +451,185 @@ private:
CountVec _subTotalRowCount;
friend class Statement;
};
};
//
// inlines
//
//
// inlines
//
inline void StatementImpl::addBind(AbstractBinding::Ptr pBinding)
{
poco_check_ptr (pBinding);
inline void StatementImpl::addBind(AbstractBinding::Ptr pBinding)
{
poco_check_ptr(pBinding);
_bindings.push_back(pBinding);
}
}
inline std::string StatementImpl::toString() const
{
inline std::string StatementImpl::toString() const
{
return _ostr.str();
}
}
inline const AbstractBindingVec& StatementImpl::bindings() const
{
inline const AbstractBindingVec & StatementImpl::bindings() const
{
return _bindings;
}
}
inline AbstractBindingVec& StatementImpl::bindings()
{
inline AbstractBindingVec & StatementImpl::bindings()
{
return _bindings;
}
}
inline const AbstractExtractionVec& StatementImpl::extractions() const
{
poco_assert (_curDataSet < _extractors.size());
inline const AbstractExtractionVec & StatementImpl::extractions() const
{
poco_assert(_curDataSet < _extractors.size());
return _extractors[_curDataSet];
}
}
inline AbstractExtractionVec& StatementImpl::extractions()
{
poco_assert (_curDataSet < _extractors.size());
inline AbstractExtractionVec & StatementImpl::extractions()
{
poco_assert(_curDataSet < _extractors.size());
return _extractors[_curDataSet];
}
}
inline StatementImpl::State StatementImpl::getState() const
{
inline StatementImpl::State StatementImpl::getState() const
{
return _state;
}
}
inline SessionImpl& StatementImpl::session()
{
inline SessionImpl & StatementImpl::session()
{
return _rSession;
}
}
inline void StatementImpl::setStorage(Storage storage)
{
inline void StatementImpl::setStorage(Storage storage)
{
_storage = storage;
}
}
inline StatementImpl::Storage StatementImpl::getStorage() const
{
inline StatementImpl::Storage StatementImpl::getStorage() const
{
return _storage;
}
}
inline std::size_t StatementImpl::extractionCount() const
{
inline std::size_t StatementImpl::extractionCount() const
{
return static_cast<std::size_t>(extractions().size());
}
}
inline std::size_t StatementImpl::dataSetCount() const
{
inline std::size_t StatementImpl::dataSetCount() const
{
return static_cast<std::size_t>(_extractors.size());
}
}
inline bool StatementImpl::isStoredProcedure() const
{
inline bool StatementImpl::isStoredProcedure() const
{
return false;
}
}
inline bool StatementImpl::isNull(std::size_t col, std::size_t row) const
{
inline bool StatementImpl::isNull(std::size_t col, std::size_t row) const
{
try
{
return extractions().at(col)->isNull(row);
}
catch (std::out_of_range& ex)
catch (std::out_of_range & ex)
{
throw RangeException(ex.what());
}
}
}
inline std::size_t StatementImpl::currentDataSet() const
{
inline std::size_t StatementImpl::currentDataSet() const
{
return _curDataSet;
}
}
inline Limit::SizeT StatementImpl::getExtractionLimit()
{
inline Limit::SizeT StatementImpl::getExtractionLimit()
{
return _extrLimit.value();
}
}
inline const Limit& StatementImpl::extractionLimit() const
{
inline const Limit & StatementImpl::extractionLimit() const
{
return _extrLimit;
}
}
inline void StatementImpl::forbidBulk()
{
inline void StatementImpl::forbidBulk()
{
_bulkBinding = BULK_FORBIDDEN;
_bulkExtraction = BULK_FORBIDDEN;
}
}
inline void StatementImpl::setBulkBinding()
{
inline void StatementImpl::setBulkBinding()
{
_bulkBinding = BULK_BINDING;
}
}
inline bool StatementImpl::bulkBindingAllowed() const
{
return BULK_UNDEFINED == _bulkBinding ||
BULK_BINDING == _bulkBinding;
}
inline bool StatementImpl::bulkBindingAllowed() const
{
return BULK_UNDEFINED == _bulkBinding || BULK_BINDING == _bulkBinding;
}
inline bool StatementImpl::bulkExtractionAllowed() const
{
return BULK_UNDEFINED == _bulkExtraction ||
BULK_EXTRACTION == _bulkExtraction;
}
inline bool StatementImpl::bulkExtractionAllowed() const
{
return BULK_UNDEFINED == _bulkExtraction || BULK_EXTRACTION == _bulkExtraction;
}
inline bool StatementImpl::isBulkBinding() const
{
inline bool StatementImpl::isBulkBinding() const
{
return BULK_BINDING == _bulkBinding;
}
}
inline bool StatementImpl::isBulkExtraction() const
{
inline bool StatementImpl::isBulkExtraction() const
{
return BULK_EXTRACTION == _bulkExtraction;
}
}
inline void StatementImpl::resetBulk()
{
inline void StatementImpl::resetBulk()
{
_bulkExtraction = BULK_UNDEFINED;
_bulkBinding = BULK_UNDEFINED;\
_bulkBinding = BULK_UNDEFINED;
setExtractionLimit(Limit(Limit::LIMIT_UNLIMITED, false, false));
}
}
inline bool StatementImpl::isBulkSupported() const
{
inline bool StatementImpl::isBulkSupported() const
{
return _rSession.getFeature("bulk");
}
}
inline bool StatementImpl::hasMoreDataSets() const
{
inline bool StatementImpl::hasMoreDataSets() const
{
return currentDataSet() + 1 < dataSetCount();
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_StatementImpl_INCLUDED

View File

@ -23,34 +23,37 @@
#include "Poco/Exception.h"
namespace Poco {
namespace Poco
{
namespace Dynamic {
namespace Dynamic
{
class Var;
class Var;
}
class DateTime;
namespace Data {
namespace Data
{
class Date;
class Date;
class Data_API Time
class Data_API Time
/// Time class wraps a DateTime and exposes time related interface.
/// The purpose of this class is binding/extraction support for time fields.
{
public:
{
public:
Time();
/// Creates the Time
Time(int hour, int minute, int second);
/// Creates the Time
Time(const DateTime& dt);
Time(const DateTime & dt);
/// Creates the Time from DateTime
~Time();
@ -68,90 +71,89 @@ public:
void assign(int hour, int minute, int second);
/// Assigns time.
Time& operator = (const Time& t);
Time & operator=(const Time & t);
/// Assignment operator for Time.
Time& operator = (const DateTime& dt);
Time & operator=(const DateTime & dt);
/// Assignment operator for DateTime.
Time& operator = (const Poco::Dynamic::Var& var);
Time & operator=(const Poco::Dynamic::Var & var);
/// Assignment operator for Var.
bool operator == (const Time& time) const;
bool operator==(const Time & time) const;
/// Equality operator.
bool operator != (const Time& time) const;
bool operator!=(const Time & time) const;
/// Inequality operator.
bool operator < (const Time& time) const;
bool operator<(const Time & time) const;
/// Less then operator.
bool operator > (const Time& time) const;
bool operator>(const Time & time) const;
/// Greater then operator.
private:
private:
int _hour;
int _minute;
int _second;
};
};
//
// inlines
//
inline int Time::hour() const
{
//
// inlines
//
inline int Time::hour() const
{
return _hour;
}
}
inline int Time::minute() const
{
inline int Time::minute() const
{
return _minute;
}
}
inline int Time::second() const
{
inline int Time::second() const
{
return _second;
}
}
inline Time& Time::operator = (const Time& t)
{
inline Time & Time::operator=(const Time & t)
{
assign(t.hour(), t.minute(), t.second());
return *this;
}
}
inline Time& Time::operator = (const DateTime& dt)
{
inline Time & Time::operator=(const DateTime & dt)
{
assign(dt.hour(), dt.minute(), dt.second());
return *this;
}
}
inline bool Time::operator == (const Time& time) const
{
return _hour == time.hour() &&
_minute == time.minute() &&
_second == time.second();
}
inline bool Time::operator==(const Time & time) const
{
return _hour == time.hour() && _minute == time.minute() && _second == time.second();
}
inline bool Time::operator != (const Time& time) const
{
inline bool Time::operator!=(const Time & time) const
{
return !(*this == time);
}
}
inline bool Time::operator > (const Time& time) const
{
inline bool Time::operator>(const Time & time) const
{
return !(*this == time) && !(*this < time);
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
//
@ -159,71 +161,61 @@ inline bool Time::operator > (const Time& time) const
//
namespace Poco {
namespace Dynamic {
template <>
class VarHolderImpl<Poco::Data::Time>: public VarHolder
namespace Poco
{
namespace Dynamic
{
public:
VarHolderImpl(const Poco::Data::Time& val): _val(val)
{
}
~VarHolderImpl()
{
}
const std::type_info& type() const
template <>
class VarHolderImpl<Poco::Data::Time> : public VarHolder
{
return typeid(Poco::Data::Time);
}
public:
VarHolderImpl(const Poco::Data::Time & val) : _val(val) { }
void convert(Poco::Timestamp& val) const
~VarHolderImpl() { }
const std::type_info & type() const { return typeid(Poco::Data::Time); }
void convert(Poco::Timestamp & val) const
{
Poco::DateTime dt;
dt.assign(dt.year(), dt.month(), dt.day(), _val.hour(), _val.minute(), _val.second());
val = dt.timestamp();
}
void convert(Poco::DateTime& val) const
void convert(Poco::DateTime & val) const
{
Poco::DateTime dt;
dt.assign(dt.year(), dt.month(), dt.day(), _val.hour(), _val.minute(), _val.second());
val = dt;
}
void convert(Poco::LocalDateTime& val) const
void convert(Poco::LocalDateTime & val) const
{
Poco::LocalDateTime ldt;
ldt.assign(ldt.year(), ldt.month(), ldt.day(), _val.hour(), _val.minute(), _val.second());
val = ldt;
}
void convert(std::string& val) const
void convert(std::string & val) const
{
DateTime dt(0, 1, 1, _val.hour(), _val.minute(), _val.second());
val = DateTimeFormatter::format(dt, "%H:%M:%S");
}
VarHolder* clone(Placeholder<VarHolder>* pVarHolder = 0) const
{
return cloneHolder(pVarHolder, _val);
}
VarHolder * clone(Placeholder<VarHolder> * pVarHolder = 0) const { return cloneHolder(pVarHolder, _val); }
const Poco::Data::Time& value() const
{
return _val;
}
const Poco::Data::Time & value() const { return _val; }
private:
private:
VarHolderImpl();
Poco::Data::Time _val;
};
};
} } // namespace Poco::Dynamic
}
} // namespace Poco::Dynamic
#endif // Data_Time_INCLUDED

View File

@ -14,7 +14,6 @@
//
#ifndef Data_Transaction_INCLUDED
#define Data_Transaction_INCLUDED
@ -24,31 +23,31 @@
#include "Poco/Logger.h"
namespace Poco {
namespace Data {
namespace Poco
{
namespace Data
{
class Data_API Transaction
class Data_API Transaction
/// Transaction helps with transactions in domain logic.
/// When an Transaction object is created, it first checks whether a
/// transaction is in progress. If not, a new transaction is created.
/// When the Transaction is destroyed, and commit() has been called,
/// nothing is done. Otherwise, the current transaction is rolled back.
/// See Transaction for more details and purpose of this template.
{
public:
Transaction(Poco::Data::Session& session, Poco::Logger* pLogger = 0);
{
public:
Transaction(Poco::Data::Session & session, Poco::Logger * pLogger = 0);
/// Creates the Transaction and starts it, using the given database session and logger.
Transaction(Poco::Data::Session& session, bool start);
Transaction(Poco::Data::Session & session, bool start);
/// Creates the Transaction, using the given database session.
/// If start is true, transaction is started, otherwise begin() must be called
/// to start the transaction.
template <typename T>
Transaction(Poco::Data::Session& rSession, T& t, Poco::Logger* pLogger = 0):
_rSession(rSession),
_pLogger(pLogger)
Transaction(Poco::Data::Session & rSession, T & t, Poco::Logger * pLogger = 0) : _rSession(rSession), _pLogger(pLogger)
/// Creates the Transaction, using the given database session, transactor and logger.
/// The transactor type must provide operator () overload taking non-const Session
/// reference as an argument.
@ -71,10 +70,14 @@ public:
/// Transactor tr;
/// Transaction tn(session, tr);
{
try { transact(t); }
try
{
transact(t);
}
catch (...)
{
if (_pLogger) _pLogger->error("Error executing transaction.");
if (_pLogger)
_pLogger->error("Error executing transaction.");
rollback();
throw;
}
@ -102,12 +105,12 @@ public:
/// Returns true iff the transaction isolation level corresponds
/// to the supplied bitmask.
void execute(const std::string& sql, bool doCommit = true);
void execute(const std::string & sql, bool doCommit = true);
/// Executes and, if doCommit is true, commits the transaction.
/// Passing true value for commit disables rollback during destruction
/// of this Transaction object.
void execute(const std::vector<std::string>& sql);
void execute(const std::vector<std::string> & sql);
/// Executes all the SQL statements supplied in the vector and, after the last
/// one is successfully executed, commits the transaction.
/// If an error occurs during execution, transaction is rolled back.
@ -115,11 +118,12 @@ public:
/// of this Transaction object.
template <typename T>
void transact(T& t)
void transact(T & t)
/// Executes the transactor and, unless transactor throws an exception,
/// commits the transaction.
{
if (!isActive()) begin();
if (!isActive())
begin();
t(_rSession);
commit();
}
@ -134,61 +138,62 @@ public:
/// Returns false after the transaction has been committed or rolled back,
/// true if the transaction is ongoing.
void setLogger(Poco::Logger* pLogger);
void setLogger(Poco::Logger * pLogger);
/// Sets the logger for this transaction.
/// Transaction does not take the ownership of the pointer.
private:
private:
Transaction();
Transaction(const Transaction&);
Transaction& operator = (const Transaction&);
Transaction(const Transaction &);
Transaction & operator=(const Transaction &);
void begin();
/// Begins the transaction if the session is already not in transaction.
/// Otherwise does nothing.
Session _rSession;
Logger* _pLogger;
};
Logger * _pLogger;
};
inline bool Transaction::isActive()
{
inline bool Transaction::isActive()
{
return _rSession.isTransaction();
}
}
inline void Transaction::setIsolation(Poco::UInt32 ti)
{
inline void Transaction::setIsolation(Poco::UInt32 ti)
{
_rSession.setTransactionIsolation(ti);
}
}
inline Poco::UInt32 Transaction::getIsolation()
{
inline Poco::UInt32 Transaction::getIsolation()
{
return _rSession.getTransactionIsolation();
}
}
inline bool Transaction::hasIsolation(Poco::UInt32 ti)
{
inline bool Transaction::hasIsolation(Poco::UInt32 ti)
{
return _rSession.isTransactionIsolation(ti);
}
}
inline bool Transaction::isIsolation(Poco::UInt32 ti)
{
inline bool Transaction::isIsolation(Poco::UInt32 ti)
{
return _rSession.isTransactionIsolation(ti);
}
}
inline void Transaction::setLogger(Poco::Logger* pLogger)
{
inline void Transaction::setLogger(Poco::Logger * pLogger)
{
_pLogger = pLogger;
}
}
} } // namespace Poco::Data
} // namespace Poco::Data
#endif // Data_Transaction_INCLUDED

File diff suppressed because it is too large Load Diff

View File

@ -22,25 +22,26 @@
#include "Poco/TextEncoding.h"
namespace Poco {
namespace Poco
{
class Foundation_API ASCIIEncoding: public TextEncoding
/// 7-bit ASCII text encoding.
class Foundation_API ASCIIEncoding : public TextEncoding
/// 7-bit ASCII text encoding.
{
public:
ASCIIEncoding();
~ASCIIEncoding();
const char* canonicalName() const;
bool isA(const std::string& encodingName) const;
const CharacterMap& characterMap() const;
int convert(const unsigned char* bytes) const;
int convert(int ch, unsigned char* bytes, int length) const;
int queryConvert(const unsigned char* bytes, int length) const;
int sequenceLength(const unsigned char* bytes, int length) const;
const char * canonicalName() const;
bool isA(const std::string & encodingName) const;
const CharacterMap & characterMap() const;
int convert(const unsigned char * bytes) const;
int convert(int ch, unsigned char * bytes, int length) const;
int queryConvert(const unsigned char * bytes, int length) const;
int sequenceLength(const unsigned char * bytes, int length) const;
private:
static const char* _names[];
static const char * _names[];
static const CharacterMap _charMap;
};

View File

@ -18,48 +18,42 @@
#define Foundation_AbstractCache_INCLUDED
#include "Poco/KeyValueArgs.h"
#include "Poco/ValidArgs.h"
#include "Poco/Mutex.h"
#include "Poco/Exception.h"
#include "Poco/FIFOEvent.h"
#include "Poco/EventArgs.h"
#include "Poco/Delegate.h"
#include "Poco/SharedPtr.h"
#include <cstddef>
#include <map>
#include <set>
#include <cstddef>
#include "Poco/Delegate.h"
#include "Poco/EventArgs.h"
#include "Poco/Exception.h"
#include "Poco/FIFOEvent.h"
#include "Poco/KeyValueArgs.h"
#include "Poco/Mutex.h"
#include "Poco/SharedPtr.h"
#include "Poco/ValidArgs.h"
namespace Poco {
namespace Poco
{
template <class TKey, class TValue, class TStrategy, class TMutex = FastMutex, class TEventMutex = FastMutex>
class AbstractCache
/// An AbstractCache is the interface of all caches.
/// An AbstractCache is the interface of all caches.
{
public:
FIFOEvent<const KeyValueArgs<TKey, TValue >, TEventMutex > Add;
FIFOEvent<const KeyValueArgs<TKey, TValue >, TEventMutex > Update;
FIFOEvent<const KeyValueArgs<TKey, TValue>, TEventMutex> Add;
FIFOEvent<const KeyValueArgs<TKey, TValue>, TEventMutex> Update;
FIFOEvent<const TKey, TEventMutex> Remove;
FIFOEvent<const TKey, TEventMutex> Get;
FIFOEvent<const EventArgs, TEventMutex> Clear;
typedef std::map<TKey, SharedPtr<TValue > > DataHolder;
typedef std::map<TKey, SharedPtr<TValue>> DataHolder;
typedef typename DataHolder::iterator Iterator;
typedef typename DataHolder::const_iterator ConstIterator;
typedef std::set<TKey> KeySet;
AbstractCache()
{
initialize();
}
AbstractCache() { initialize(); }
AbstractCache(const TStrategy & strategy)
: _strategy(strategy)
{
initialize();
}
AbstractCache(const TStrategy & strategy) : _strategy(strategy) { initialize(); }
virtual ~AbstractCache()
{
@ -73,7 +67,7 @@ public:
}
}
void add(const TKey& key, const TValue& val)
void add(const TKey & key, const TValue & val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
@ -81,7 +75,7 @@ public:
doAdd(key, val);
}
void update(const TKey& key, const TValue& val)
void update(const TKey & key, const TValue & val)
/// Adds the key value pair to the cache. Note that adding a NULL SharedPtr will fail!
/// If for the key already an entry exists, it will be overwritten.
/// The difference to add is that no remove or add events are thrown in this case,
@ -92,7 +86,7 @@ public:
doUpdate(key, val);
}
void add(const TKey& key, SharedPtr<TValue > val)
void add(const TKey & key, SharedPtr<TValue> val)
/// Adds the key value pair to the cache. Note that adding a NULL SharedPtr will fail!
/// If for the key already an entry exists, it will be overwritten, ie. first a remove event
/// is thrown, then a add event
@ -101,7 +95,7 @@ public:
doAdd(key, val);
}
void update(const TKey& key, SharedPtr<TValue > val)
void update(const TKey & key, SharedPtr<TValue> val)
/// Adds the key value pair to the cache. Note that adding a NULL SharedPtr will fail!
/// If for the key already an entry exists, it will be overwritten.
/// The difference to add is that no remove or add events are thrown in this case,
@ -112,7 +106,7 @@ public:
doUpdate(key, val);
}
void remove(const TKey& key)
void remove(const TKey & key)
/// Removes an entry from the cache. If the entry is not found,
/// the remove is ignored.
{
@ -121,20 +115,20 @@ public:
doRemove(it);
}
bool has(const TKey& key) const
bool has(const TKey & key) const
/// Returns true if the cache contains a value for the key.
{
typename TMutex::ScopedLock lock(_mutex);
return doHas(key);
}
SharedPtr<TValue> get(const TKey& key)
SharedPtr<TValue> get(const TKey & key)
/// Returns a SharedPtr of the value. The SharedPointer will remain valid
/// even when cache replacement removes the element.
/// If for the key no value exists, an empty SharedPtr is returned.
{
typename TMutex::ScopedLock lock(_mutex);
return doGet (key);
return doGet(key);
}
void clear()
@ -178,34 +172,34 @@ public:
}
protected:
mutable FIFOEvent<ValidArgs<TKey> > IsValid;
mutable FIFOEvent<ValidArgs<TKey>> IsValid;
mutable FIFOEvent<KeySet> Replace;
void initialize()
/// Sets up event registration.
{
Add += Delegate<TStrategy, const KeyValueArgs<TKey, TValue> >(&_strategy, &TStrategy::onAdd);
Update += Delegate<TStrategy, const KeyValueArgs<TKey, TValue> >(&_strategy, &TStrategy::onUpdate);
Add += Delegate<TStrategy, const KeyValueArgs<TKey, TValue>>(&_strategy, &TStrategy::onAdd);
Update += Delegate<TStrategy, const KeyValueArgs<TKey, TValue>>(&_strategy, &TStrategy::onUpdate);
Remove += Delegate<TStrategy, const TKey>(&_strategy, &TStrategy::onRemove);
Get += Delegate<TStrategy, const TKey>(&_strategy, &TStrategy::onGet);
Clear += Delegate<TStrategy, const EventArgs>(&_strategy, &TStrategy::onClear);
IsValid += Delegate<TStrategy, ValidArgs<TKey> >(&_strategy, &TStrategy::onIsValid);
IsValid += Delegate<TStrategy, ValidArgs<TKey>>(&_strategy, &TStrategy::onIsValid);
Replace += Delegate<TStrategy, KeySet>(&_strategy, &TStrategy::onReplace);
}
void uninitialize()
/// Reverts event registration.
{
Add -= Delegate<TStrategy, const KeyValueArgs<TKey, TValue> >(&_strategy, &TStrategy::onAdd );
Update -= Delegate<TStrategy, const KeyValueArgs<TKey, TValue> >(&_strategy, &TStrategy::onUpdate);
Add -= Delegate<TStrategy, const KeyValueArgs<TKey, TValue>>(&_strategy, &TStrategy::onAdd);
Update -= Delegate<TStrategy, const KeyValueArgs<TKey, TValue>>(&_strategy, &TStrategy::onUpdate);
Remove -= Delegate<TStrategy, const TKey>(&_strategy, &TStrategy::onRemove);
Get -= Delegate<TStrategy, const TKey>(&_strategy, &TStrategy::onGet);
Clear -= Delegate<TStrategy, const EventArgs>(&_strategy, &TStrategy::onClear);
IsValid -= Delegate<TStrategy, ValidArgs<TKey> >(&_strategy, &TStrategy::onIsValid);
IsValid -= Delegate<TStrategy, ValidArgs<TKey>>(&_strategy, &TStrategy::onIsValid);
Replace -= Delegate<TStrategy, KeySet>(&_strategy, &TStrategy::onReplace);
}
void doAdd(const TKey& key, const TValue& val)
void doAdd(const TKey & key, const TValue & val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
@ -219,7 +213,7 @@ protected:
doReplace();
}
void doAdd(const TKey& key, SharedPtr<TValue>& val)
void doAdd(const TKey & key, SharedPtr<TValue> & val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
@ -233,7 +227,7 @@ protected:
doReplace();
}
void doUpdate(const TKey& key, const TValue& val)
void doUpdate(const TKey & key, const TValue & val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
@ -253,7 +247,7 @@ protected:
doReplace();
}
void doUpdate(const TKey& key, SharedPtr<TValue>& val)
void doUpdate(const TKey & key, SharedPtr<TValue> & val)
/// Adds the key value pair to the cache.
/// If for the key already an entry exists, it will be overwritten.
{
@ -284,7 +278,7 @@ protected:
}
}
bool doHas(const TKey& key) const
bool doHas(const TKey & key) const
/// Returns true if the cache contains a value for the key
{
// ask the strategy if the key is valid
@ -301,7 +295,7 @@ protected:
return result;
}
SharedPtr<TValue> doGet(const TKey& key)
SharedPtr<TValue> doGet(const TKey & key)
/// Returns a SharedPtr of the cache entry, returns 0 if for
/// the key no value was found
{
@ -356,8 +350,8 @@ protected:
mutable TMutex _mutex;
private:
AbstractCache(const AbstractCache& aCache);
AbstractCache& operator = (const AbstractCache& aCache);
AbstractCache(const AbstractCache & aCache);
AbstractCache & operator=(const AbstractCache & aCache);
};

Some files were not shown because too many files have changed in this diff Show More