mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 03:03:23 +02:00
=MySQL connector
This commit is contained in:
263
Data/MySQL/include/Poco/Data/MySQL/Binder.h
Normal file
263
Data/MySQL/include/Poco/Data/MySQL/Binder.h
Normal file
@@ -0,0 +1,263 @@
|
||||
//
|
||||
// Binder.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/Binder.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: Binder
|
||||
//
|
||||
// Definition of the Binder class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_Binder_INCLUDED
|
||||
#define Data_MySQL_Binder_INCLUDED
|
||||
|
||||
#include "Poco/Data/MySQL/MySQL.h"
|
||||
#include "Poco/Data/AbstractBinder.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/MySQL/MySQLException.h"
|
||||
#include <mysql.h>
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
|
||||
class MySQL_API Binder: public Poco::Data::AbstractBinder
|
||||
/// Binds placeholders in the sql query to the provided values. Performs data types mapping.
|
||||
{
|
||||
public:
|
||||
|
||||
Binder();
|
||||
/// Creates the Binder.
|
||||
|
||||
virtual ~Binder();
|
||||
/// Destroys the Binder.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int8& val, Direction dir);
|
||||
/// Binds an Int8.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt8& val, Direction dir);
|
||||
/// Binds an UInt8.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int16& val, Direction dir);
|
||||
/// Binds an Int16.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt16& val, Direction dir);
|
||||
/// Binds an UInt16.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int32& val, Direction dir);
|
||||
/// Binds an Int32.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt32& val, Direction dir);
|
||||
/// Binds an UInt32.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int64& val, Direction dir);
|
||||
/// Binds an Int64.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt64& val, Direction dir);
|
||||
/// Binds an UInt64.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
virtual void bind(std::size_t pos, const long& val, Direction dir = PD_IN);
|
||||
/// Binds a long.
|
||||
#endif
|
||||
|
||||
virtual void bind(std::size_t pos, const bool& val, Direction dir);
|
||||
/// Binds a boolean.
|
||||
|
||||
virtual void bind(std::size_t pos, const float& val, Direction dir);
|
||||
/// Binds a float.
|
||||
|
||||
virtual void bind(std::size_t pos, const double& val, Direction dir);
|
||||
/// Binds a double.
|
||||
|
||||
virtual void bind(std::size_t pos, const char& val, Direction dir);
|
||||
/// Binds a single character.
|
||||
|
||||
virtual void bind(std::size_t pos, const std::string& val, Direction dir);
|
||||
/// Binds a string.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir);
|
||||
/// Binds a BLOB.
|
||||
|
||||
virtual void bind(std::size_t pos, const DateTime& val, Direction dir);
|
||||
/// Binds a DateTime.
|
||||
|
||||
virtual void bind(std::size_t pos, const Date& val, Direction dir);
|
||||
/// Binds a Date.
|
||||
|
||||
virtual void bind(std::size_t pos, const Time& val, Direction dir);
|
||||
/// Binds a Time.
|
||||
|
||||
virtual void bind(std::size_t pos, const NullData& val, Direction dir);
|
||||
/// Binds a null.
|
||||
|
||||
|
||||
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::deque<Poco::Int8>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<Poco::UInt8>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<Poco::UInt8>& val, Direction dir = PD_IN);
|
||||
|
||||
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::deque<Poco::Int16>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<Poco::UInt16>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<Poco::UInt16>& val, Direction dir = PD_IN);
|
||||
|
||||
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::deque<Poco::Int32>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<Poco::UInt32>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<Poco::UInt32>& val, Direction dir = PD_IN);
|
||||
|
||||
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::deque<Poco::Int64>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<Poco::UInt64>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<Poco::UInt64>& val, Direction dir = PD_IN);
|
||||
|
||||
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::deque<bool>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<float>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<float>& val, Direction dir = PD_IN);
|
||||
|
||||
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::deque<double>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<char>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<char>& val, Direction dir = PD_IN);
|
||||
|
||||
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::deque<BLOB>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<DateTime>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<DateTime>& val, Direction dir = PD_IN);
|
||||
|
||||
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::deque<Date>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<Time>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<Time>& val, Direction dir = PD_IN);
|
||||
|
||||
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::deque<NullData>& val, Direction dir = PD_IN);
|
||||
|
||||
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::vector<std::string>& val, Direction dir = PD_IN);
|
||||
|
||||
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::list<std::string>& val, Direction dir = PD_IN);
|
||||
|
||||
size_t size() const;
|
||||
/// Return count of binded parameters
|
||||
|
||||
MYSQL_BIND* getBindArray() const;
|
||||
/// Return array
|
||||
|
||||
//void updateDates();
|
||||
/// Update linked times
|
||||
|
||||
private:
|
||||
|
||||
virtual void bind(std::size_t, const char* const&, Direction)
|
||||
/// Binds a const char ptr.
|
||||
/// This is a private no-op in this implementation
|
||||
/// due to security risk.
|
||||
{
|
||||
}
|
||||
|
||||
void realBind(std::size_t pos, enum_field_types type, const void* buffer, int length);
|
||||
/// Common bind implementation
|
||||
|
||||
private:
|
||||
|
||||
std::vector<MYSQL_BIND> _bindArray;
|
||||
std::vector<MYSQL_TIME> _dates;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
|
||||
#endif // Data_MySQL_Binder_INCLUDED
|
79
Data/MySQL/include/Poco/Data/MySQL/Connector.h
Normal file
79
Data/MySQL/include/Poco/Data/MySQL/Connector.h
Normal file
@@ -0,0 +1,79 @@
|
||||
//
|
||||
// Connector.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/Connector.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: Connector
|
||||
//
|
||||
// Definition of the Connector class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_Connector_INCLUDED
|
||||
#define Data_MySQL_Connector_INCLUDED
|
||||
|
||||
#include "MySQL.h"
|
||||
#include "Poco/Data/Connector.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
class MySQL_API Connector: public Poco::Data::Connector
|
||||
/// Connector instantiates MySQL SessionImpl objects.
|
||||
{
|
||||
public:
|
||||
|
||||
static std::string KEY;
|
||||
|
||||
Connector();
|
||||
/// Creates the Connector.
|
||||
|
||||
virtual ~Connector();
|
||||
/// Destroys the Connector.
|
||||
|
||||
virtual const std::string& name() const;
|
||||
/// Returns the name associated with this connector.
|
||||
|
||||
virtual Poco::AutoPtr<Poco::Data::SessionImpl> createSession(const std::string& connectionString);
|
||||
/// Creates a MySQL SessionImpl object and initializes it with the given connectionString.
|
||||
|
||||
static void registerConnector();
|
||||
/// Registers the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory
|
||||
|
||||
static void unregisterConnector();
|
||||
/// Unregisters the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
|
||||
#endif // Data_MySQL_Connector_INCLUDED
|
336
Data/MySQL/include/Poco/Data/MySQL/Extractor.h
Normal file
336
Data/MySQL/include/Poco/Data/MySQL/Extractor.h
Normal file
@@ -0,0 +1,336 @@
|
||||
//
|
||||
// Extractor.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/Extractor.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: Extractor
|
||||
//
|
||||
// Definition of the Extractor class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_Extractor_INCLUDED
|
||||
#define Data_MySQL_Extractor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/MySQL/MySQL.h"
|
||||
#include "Poco/Data/MySQL/StatementExecutor.h"
|
||||
#include "Poco/Data/MySQL/ResultMetadata.h"
|
||||
#include "Poco/Data/AbstractExtractor.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
|
||||
class MySQL_API Extractor: public Poco::Data::AbstractExtractor
|
||||
/// Extracts and converts data values from the result row returned by MySQL.
|
||||
/// If NULL is received, the incoming val value is not changed and false is returned
|
||||
{
|
||||
public:
|
||||
Extractor(StatementExecutor& st, ResultMetadata& md);
|
||||
/// Creates the Extractor.
|
||||
|
||||
virtual ~Extractor();
|
||||
/// Destroys the Extractor.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int8& val);
|
||||
/// Extracts an Int8.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt8& val);
|
||||
/// Extracts an UInt8.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int16& val);
|
||||
/// Extracts an Int16.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt16& val);
|
||||
/// Extracts an UInt16.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int32& val);
|
||||
/// Extracts an Int32.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt32& val);
|
||||
/// Extracts an UInt32.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int64& val);
|
||||
/// Extracts an Int64.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt64& val);
|
||||
/// Extracts an UInt64.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
virtual bool extract(std::size_t pos, long& val);
|
||||
/// Extracts a long. Returns false if null was received.
|
||||
#endif
|
||||
|
||||
virtual bool extract(std::size_t pos, bool& val);
|
||||
/// Extracts a boolean.
|
||||
|
||||
virtual bool extract(std::size_t pos, float& val);
|
||||
/// Extracts a float.
|
||||
|
||||
virtual bool extract(std::size_t pos, double& val);
|
||||
/// Extracts a double.
|
||||
|
||||
virtual bool extract(std::size_t pos, char& val);
|
||||
/// Extracts a single character.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::string& val);
|
||||
/// Extracts a string.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Data::BLOB& val);
|
||||
/// Extracts a BLOB.
|
||||
|
||||
virtual bool extract(std::size_t pos, DateTime& val);
|
||||
/// Extracts a DateTime. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Date& val);
|
||||
/// Extracts a Date. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Time& val);
|
||||
/// Extracts a Time. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Any& val);
|
||||
/// Extracts an Any. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, DynamicAny& val);
|
||||
/// Extracts a DynamicAny. Returns false if null was received.
|
||||
|
||||
virtual bool isNull(std::size_t col, std::size_t row);
|
||||
/// Returns true if the value at [col,row] position is null.
|
||||
|
||||
virtual void reset();
|
||||
/// Resets any information internally cached by the extractor.
|
||||
|
||||
////////////
|
||||
// Not implemented extract functions
|
||||
////////////
|
||||
|
||||
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);
|
||||
/// Extracts an Int8 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::Int8>& val);
|
||||
/// Extracts an Int8 list.
|
||||
|
||||
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);
|
||||
/// Extracts an UInt8 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::UInt8>& val);
|
||||
/// Extracts an UInt8 list.
|
||||
|
||||
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);
|
||||
/// Extracts an Int16 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::Int16>& val);
|
||||
/// Extracts an Int16 list.
|
||||
|
||||
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);
|
||||
/// Extracts an UInt16 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::UInt16>& val);
|
||||
/// Extracts an UInt16 list.
|
||||
|
||||
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);
|
||||
/// Extracts an Int32 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::Int32>& val);
|
||||
/// Extracts an Int32 list.
|
||||
|
||||
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);
|
||||
/// Extracts an UInt32 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::UInt32>& val);
|
||||
/// Extracts an UInt32 list.
|
||||
|
||||
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);
|
||||
/// Extracts an Int64 deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Poco::Int64>& val);
|
||||
/// Extracts an Int64 list.
|
||||
|
||||
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);
|
||||
/// Extracts an UInt64 deque.
|
||||
|
||||
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, std::vector<long>& val);
|
||||
/// Extracts a long vector.
|
||||
|
||||
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);
|
||||
/// Extracts a long list.
|
||||
#endif
|
||||
|
||||
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);
|
||||
/// Extracts a boolean deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<bool>& val);
|
||||
/// Extracts a boolean list.
|
||||
|
||||
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);
|
||||
/// Extracts a float deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<float>& val);
|
||||
/// Extracts a float list.
|
||||
|
||||
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);
|
||||
/// Extracts a double deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<double>& val);
|
||||
/// Extracts a double list.
|
||||
|
||||
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);
|
||||
/// Extracts a character deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<char>& val);
|
||||
/// Extracts a character list.
|
||||
|
||||
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);
|
||||
/// Extracts a string deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<std::string>& val);
|
||||
/// Extracts a string list.
|
||||
|
||||
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);
|
||||
/// Extracts a BLOB deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<BLOB>& val);
|
||||
/// Extracts a BLOB list.
|
||||
|
||||
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);
|
||||
/// Extracts a DateTime deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<DateTime>& val);
|
||||
/// Extracts a DateTime list.
|
||||
|
||||
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);
|
||||
/// Extracts a Date deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Date>& val);
|
||||
/// Extracts a Date list.
|
||||
|
||||
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);
|
||||
/// Extracts a Time deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Time>& val);
|
||||
/// Extracts a Time list.
|
||||
|
||||
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);
|
||||
/// Extracts an Any deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<Any>& val);
|
||||
/// Extracts an Any list.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::vector<DynamicAny>& val);
|
||||
/// Extracts a DynamicAny vector.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::deque<DynamicAny>& val);
|
||||
/// Extracts a DynamicAny deque.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::list<DynamicAny>& val);
|
||||
/// Extracts a DynamicAny list.
|
||||
|
||||
private:
|
||||
|
||||
bool realExtractFixed(std::size_t pos, enum_field_types type, void* buffer, size_t length = 0);
|
||||
|
||||
// Prevent VC8 warning "operator= could not be generated"
|
||||
Extractor& operator=(const Extractor&);
|
||||
|
||||
private:
|
||||
|
||||
StatementExecutor& _stmt;
|
||||
ResultMetadata& _metadata;
|
||||
};
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
|
||||
#endif // Data_MySQL_Extractor_INCLUDED
|
90
Data/MySQL/include/Poco/Data/MySQL/MySQL.h
Normal file
90
Data/MySQL/include/Poco/Data/MySQL/MySQL.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// MySQL.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/MySQL.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: MySQL
|
||||
//
|
||||
// Basic definitions for the MySQL library.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef MySQL_MySQL_INCLUDED
|
||||
#define MySQL_MySQL_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the ODBC_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// ODBC_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(MYSQL_EXPORTS)
|
||||
#define MySQL_API __declspec(dllexport)
|
||||
#else
|
||||
#define MySQL_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(MySQL_API)
|
||||
#define MySQL_API
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Data library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(MYSQL_EXPORTS)
|
||||
#if defined(POCO_DLL)
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoMySQLd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoMySQL.lib")
|
||||
#endif
|
||||
#else
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoMySQLmtd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoMySQLmt.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // MySQL_MySQL_INCLUDED
|
178
Data/MySQL/include/Poco/Data/MySQL/MySQLException.h
Normal file
178
Data/MySQL/include/Poco/Data/MySQL/MySQLException.h
Normal file
@@ -0,0 +1,178 @@
|
||||
//
|
||||
// MySQLException.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/MySQLException.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: MySQLException
|
||||
//
|
||||
// Definition of the MySQLException class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_MySQLException_INCLUDED
|
||||
#define Data_MySQL_MySQLException_INCLUDED
|
||||
|
||||
#include "Poco/Data/MySQL/MySQL.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include <typeinfo>
|
||||
#include <string>
|
||||
|
||||
|
||||
typedef struct st_mysql MYSQL;
|
||||
typedef struct st_mysql_stmt MYSQL_STMT;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
// End-user include this file and use in code ConnectionException/StatementException
|
||||
// So it need not know
|
||||
|
||||
class MySQL_API MySQLException: public Poco::Data::DataException
|
||||
/// Base class for all MySQL exceptions
|
||||
{
|
||||
public:
|
||||
|
||||
MySQLException(const std::string& msg);
|
||||
/// Creates MySQLException.
|
||||
|
||||
MySQLException(const MySQLException& exc);
|
||||
/// Creates MySQLException.
|
||||
|
||||
~MySQLException() throw();
|
||||
/// Destroys MySQLexception.
|
||||
|
||||
MySQLException& operator=(const MySQLException& exc);
|
||||
/// Assignment operator.
|
||||
|
||||
const char* name() const throw();
|
||||
/// Returns exception name.
|
||||
|
||||
const char* className() const throw();
|
||||
/// Returns the name of the exception class.
|
||||
|
||||
Poco::Exception* clone() const;
|
||||
/// Creates an exact copy of the exception.
|
||||
///
|
||||
/// The copy can later be thrown again by
|
||||
/// invoking rethrow() on it.
|
||||
|
||||
void rethrow() const;
|
||||
/// (Re)Throws the exception.
|
||||
///
|
||||
/// This is useful for temporarily storing a
|
||||
/// copy of an exception (see clone()), then
|
||||
/// throwing it again.
|
||||
};
|
||||
|
||||
|
||||
class ConnectionException : public MySQLException
|
||||
/// ConnectionException
|
||||
{
|
||||
public:
|
||||
|
||||
ConnectionException(const std::string& msg);
|
||||
/// Creates ConnectionException from string.
|
||||
|
||||
ConnectionException(const std::string& text, MYSQL* h);
|
||||
/// Creates ConnectionException from string and handle.
|
||||
|
||||
private:
|
||||
|
||||
static std::string compose(const std::string& text, MYSQL* h);
|
||||
|
||||
};
|
||||
|
||||
|
||||
class TransactionException : public ConnectionException
|
||||
/// TrabsactionException
|
||||
{
|
||||
public:
|
||||
|
||||
TransactionException(const std::string& msg);
|
||||
/// Creates TransactionException from string.
|
||||
|
||||
TransactionException(const std::string& text, MYSQL* h);
|
||||
/// Creates TransactionException from string and handle.
|
||||
};
|
||||
|
||||
|
||||
class StatementException : public MySQLException
|
||||
/// StatementException
|
||||
{
|
||||
public:
|
||||
|
||||
StatementException(const std::string& msg);
|
||||
/// Creates StatementException from string.
|
||||
|
||||
StatementException(const std::string& text, MYSQL_STMT* h, const std::string& stmt = "");
|
||||
/// Creates StatementException from string and handle.
|
||||
|
||||
private:
|
||||
|
||||
static std::string compose(const std::string& text, MYSQL_STMT* h, const std::string& stmt);
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
inline MySQLException& MySQLException::operator=(const MySQLException& exc)
|
||||
{
|
||||
Poco::Data::DataException::operator=(exc);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const char* MySQLException::name() const throw()
|
||||
{
|
||||
return "MySQL";
|
||||
}
|
||||
|
||||
inline const char* MySQLException::className() const throw()
|
||||
{
|
||||
return typeid(*this).name();
|
||||
}
|
||||
|
||||
inline Poco::Exception* MySQLException::clone() const
|
||||
{
|
||||
return new MySQLException(*this);
|
||||
}
|
||||
|
||||
inline void MySQLException::rethrow() const
|
||||
{
|
||||
throw *this;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
#endif //Data_MySQL_MySQLException_INCLUDED
|
125
Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h
Normal file
125
Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h
Normal file
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// MySQLstatementImpl.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/MySQLStatementImpl.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: MySQLstatementImpl
|
||||
//
|
||||
// Definition of the MySQLStatementImpl class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_MySQLStatementImpl_INCLUDED
|
||||
#define Data_MySQL_MySQLStatementImpl_INCLUDED
|
||||
|
||||
#include "Poco/Data/MySQL/MySQL.h"
|
||||
#include "Poco/Data/MySQL/SessionImpl.h"
|
||||
#include "Poco/Data/MySQL/Binder.h"
|
||||
#include "Poco/Data/MySQL/Extractor.h"
|
||||
#include "Poco/Data/MySQL/StatementExecutor.h"
|
||||
#include "Poco/Data/MySQL/ResultMetadata.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Format.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
|
||||
class MySQL_API MySQLStatementImpl: public Poco::Data::StatementImpl
|
||||
/// Implements statement functionality needed for MySQL
|
||||
{
|
||||
public:
|
||||
|
||||
MySQLStatementImpl(SessionImpl& s);
|
||||
/// Creates the MySQLStatementImpl.
|
||||
|
||||
~MySQLStatementImpl();
|
||||
/// Destroys the MySQLStatementImpl.
|
||||
|
||||
protected:
|
||||
|
||||
virtual Poco::UInt32 columnsReturned() const;
|
||||
/// Returns number of columns returned by query.
|
||||
|
||||
virtual Poco::UInt32 affectedRowCount() const;
|
||||
/// Returns the number of affected rows.
|
||||
/// Used to find out the number of rows affected by insert, delete or update.
|
||||
|
||||
virtual const MetaColumn& metaColumn(Poco::UInt32 pos) const;
|
||||
/// Returns column meta data.
|
||||
|
||||
virtual bool hasNext();
|
||||
/// Returns true if a call to next() will return data.
|
||||
|
||||
virtual Poco::UInt32 next();
|
||||
/// Retrieves the next row from the resultset.
|
||||
/// Will throw, if the resultset is empty.
|
||||
|
||||
virtual bool canBind() const;
|
||||
/// Returns true if a valid statement is set and we can bind.
|
||||
|
||||
virtual bool canCompile() const;
|
||||
/// Returns true if another compile is possible.
|
||||
|
||||
virtual void compileImpl();
|
||||
/// Compiles the statement, doesn't bind yet
|
||||
|
||||
virtual void bindImpl();
|
||||
/// Binds parameters
|
||||
|
||||
virtual AbstractExtractor& extractor();
|
||||
/// Returns the concrete extractor used by the statement.
|
||||
|
||||
virtual AbstractBinder& binder();
|
||||
/// Returns the concrete binder used by the statement.
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
NEXT_DONTKNOW,
|
||||
NEXT_TRUE,
|
||||
NEXT_FALSE
|
||||
};
|
||||
|
||||
StatementExecutor _stmt;
|
||||
ResultMetadata _metadata;
|
||||
Binder _binder;
|
||||
Extractor _extractor;
|
||||
int _hasNext;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
|
||||
#endif // Data_MySQL_MySQLStatementImpl_INCLUDED
|
89
Data/MySQL/include/Poco/Data/MySQL/ResultMetadata.h
Normal file
89
Data/MySQL/include/Poco/Data/MySQL/ResultMetadata.h
Normal file
@@ -0,0 +1,89 @@
|
||||
//
|
||||
// ResultMetadata.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/ResultMetadata.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: ResultMetadata
|
||||
//
|
||||
// Definition of the ResultMetadata class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_ResultMetadata_INCLUDED
|
||||
#define Data_MySQL_ResultMetadata_INCLUDED
|
||||
|
||||
#include <mysql.h>
|
||||
#include <vector>
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
class ResultMetadata
|
||||
/// MySQL result metadata
|
||||
{
|
||||
public:
|
||||
|
||||
void reset();
|
||||
/// Resets the metadata.
|
||||
|
||||
void init(MYSQL_STMT* stmt);
|
||||
/// Initializes the metadata.
|
||||
|
||||
Poco::UInt32 columnsReturned() const;
|
||||
/// Returns the number of columns in resultset.
|
||||
|
||||
const MetaColumn& metaColumn(Poco::UInt32 pos) const;
|
||||
/// Returns the reference to the specified metacolumn.
|
||||
|
||||
MYSQL_BIND* row();
|
||||
/// Returns pointer to native row.
|
||||
|
||||
std::size_t length(std::size_t pos) const;
|
||||
/// Returns the length.
|
||||
|
||||
const char* rawData(std::size_t pos) const;
|
||||
/// Returns raw data.
|
||||
|
||||
bool isNull(std::size_t pos) const;
|
||||
/// Returns true if value at pos is null.
|
||||
|
||||
private:
|
||||
std::vector<MetaColumn> _columns;
|
||||
std::vector<MYSQL_BIND> _row;
|
||||
std::vector<char> _buffer;
|
||||
std::vector<unsigned long> _lengths;
|
||||
std::vector<my_bool> _isNull;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif //Data_MySQL_ResultMetadata_INCLUDED
|
108
Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h
Normal file
108
Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h
Normal file
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// SesssionHandle.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/SessionHandle.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: SessionHandle
|
||||
//
|
||||
// Definition of the SessionHandle class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_SessionHandle_INCLUDED
|
||||
#define Data_MySQL_SessionHandle_INCLUDED
|
||||
|
||||
#include <mysql.h>
|
||||
#include "Poco/Data/MySQL/MySQLException.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
class SessionHandle
|
||||
/// MySQL session handle
|
||||
{
|
||||
public:
|
||||
|
||||
explicit SessionHandle(MYSQL* mysql);
|
||||
/// Creates session handle
|
||||
|
||||
~SessionHandle();
|
||||
/// Destroy handle, close connection
|
||||
|
||||
void options(mysql_option opt);
|
||||
/// Set connection options
|
||||
|
||||
void options(mysql_option opt, bool b);
|
||||
/// Set connection options
|
||||
|
||||
void connect(const char* host, const char* user, const char* password, const char* db, unsigned int port);
|
||||
/// Connect to server
|
||||
|
||||
void close();
|
||||
/// Close connection
|
||||
|
||||
void startTransaction();
|
||||
/// Start transaction
|
||||
|
||||
void commit();
|
||||
/// Commit transaction
|
||||
|
||||
void rollback();
|
||||
/// Rollback trabsaction
|
||||
|
||||
operator MYSQL* ();
|
||||
|
||||
private:
|
||||
|
||||
SessionHandle(const SessionHandle&);
|
||||
SessionHandle& operator=(const SessionHandle&);
|
||||
|
||||
private:
|
||||
|
||||
MYSQL* h;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
inline SessionHandle::operator MYSQL* ()
|
||||
{
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
}}}
|
||||
|
||||
#endif // Data_MySQL_SessionHandle_INCLUDED
|
135
Data/MySQL/include/Poco/Data/MySQL/SessionImpl.h
Normal file
135
Data/MySQL/include/Poco/Data/MySQL/SessionImpl.h
Normal file
@@ -0,0 +1,135 @@
|
||||
//
|
||||
// SessionImpl.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/SessionImpl.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: SessionImpl
|
||||
//
|
||||
// Definition of the SessionImpl class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_SessionImpl_INCLUDED
|
||||
#define Data_MySQL_SessionImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/MySQL/MySQL.h"
|
||||
#include "Poco/Data/AbstractSessionImpl.h"
|
||||
#include "Poco/Data/MySQL/SessionHandle.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
|
||||
class MySQL_API SessionImpl: public Poco::Data::AbstractSessionImpl<SessionImpl>
|
||||
/// Implements SessionImpl interface
|
||||
{
|
||||
public:
|
||||
|
||||
SessionImpl(const std::string& connectionString);
|
||||
/// Creates the SessionImpl. Opens a connection to the database
|
||||
///
|
||||
/// Connection string format:
|
||||
/// <str> == <assignment> | <assignment> ';' <str>
|
||||
/// <assignment> == <name> '=' <value>
|
||||
/// <name> == 'host' | 'port' | 'user' | 'password' | 'db' } 'compress' | 'auto-reconnect'
|
||||
/// <value> == [~;]*
|
||||
///
|
||||
/// for compress and auto-reconnect correct values are true/false
|
||||
/// for port - numeric in decimal notation
|
||||
///
|
||||
|
||||
~SessionImpl();
|
||||
/// Destroys the SessionImpl.
|
||||
|
||||
virtual Poco::Data::StatementImpl* createStatementImpl();
|
||||
/// Returns an MySQL StatementImpl
|
||||
|
||||
virtual void begin();
|
||||
/// Starts a transaction
|
||||
|
||||
virtual void commit();
|
||||
/// Commits and ends a transaction
|
||||
|
||||
virtual void rollback();
|
||||
/// Aborts a transaction
|
||||
|
||||
virtual void close();
|
||||
/// Closes the connection
|
||||
|
||||
virtual bool isConnected();
|
||||
/// Returns true iff session is connected.
|
||||
|
||||
virtual bool isTransaction();
|
||||
/// Returns true iff a transaction is in progress.
|
||||
|
||||
void setInsertId(const std::string&, const Poco::Any&);
|
||||
/// Try to set insert id - do nothing.
|
||||
|
||||
Poco::Any getInsertId(const std::string&);
|
||||
/// Get insert id
|
||||
|
||||
|
||||
SessionHandle& handle();
|
||||
// Get handle
|
||||
|
||||
private:
|
||||
|
||||
SessionHandle _mysql;
|
||||
bool _connected;
|
||||
int _inTransaction;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
inline void SessionImpl::setInsertId(const std::string&, const Poco::Any&)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
inline Poco::Any SessionImpl::getInsertId(const std::string&)
|
||||
{
|
||||
return Poco::Any(Poco::UInt64(mysql_insert_id(_mysql)));
|
||||
}
|
||||
|
||||
inline SessionHandle& SessionImpl::handle()
|
||||
{
|
||||
return _mysql;
|
||||
}
|
||||
|
||||
} } } // namespace Poco::Data::MySQL
|
||||
|
||||
|
||||
#endif // Data_MySQL_SessionImpl_INCLUDED
|
118
Data/MySQL/include/Poco/Data/MySQL/StatementExecutor.h
Normal file
118
Data/MySQL/include/Poco/Data/MySQL/StatementExecutor.h
Normal file
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// StatementExecutor.h
|
||||
//
|
||||
// $Id: //poco/1.4/Data/MySQL/include/Poco/Data/MySQL/StatementExecutor.h#1 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: MySQL
|
||||
// Module: StatementExecutor
|
||||
//
|
||||
// Definition of the StatementExecutor class.
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_MySQL_StatementHandle_INCLUDED
|
||||
#define Data_MySQL_StatementHandle_INCLUDED
|
||||
|
||||
#include <mysql.h>
|
||||
#include "Poco/Data/MySQL/MySQLException.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace MySQL {
|
||||
|
||||
class StatementExecutor
|
||||
/// MySQL statement executor.
|
||||
{
|
||||
public:
|
||||
enum State
|
||||
{
|
||||
STMT_INITED,
|
||||
STMT_COMPILED,
|
||||
STMT_EXECUTED
|
||||
};
|
||||
|
||||
explicit StatementExecutor(MYSQL* mysql);
|
||||
/// Creates the StatementExecutor.
|
||||
|
||||
~StatementExecutor();
|
||||
/// Destroys the StatementExecutor.
|
||||
|
||||
int state() const;
|
||||
/// Returns the current state.
|
||||
|
||||
void prepare(const std::string& query);
|
||||
/// Prepares the statement for execution.
|
||||
|
||||
void bindParams(MYSQL_BIND* params, size_t count);
|
||||
/// Binds the params.
|
||||
|
||||
void bindResult(MYSQL_BIND* result);
|
||||
/// Binds result.
|
||||
|
||||
void execute();
|
||||
/// Executes the statement.
|
||||
|
||||
bool fetch();
|
||||
/// Fetches the data.
|
||||
|
||||
bool fetchColumn(size_t n, MYSQL_BIND *bind);
|
||||
/// Fetches the column.
|
||||
|
||||
operator MYSQL_STMT* ();
|
||||
/// Cast operator to native handle type.
|
||||
|
||||
private:
|
||||
|
||||
StatementExecutor(const StatementExecutor&);
|
||||
StatementExecutor& operator=(const StatementExecutor&);
|
||||
|
||||
private:
|
||||
|
||||
MYSQL_STMT* h;
|
||||
int _state;
|
||||
std::string _query;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
inline StatementExecutor::operator MYSQL_STMT* ()
|
||||
{
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
}}}
|
||||
|
||||
|
||||
#endif // Data_MySQL_StatementHandle_INCLUDED
|
Reference in New Issue
Block a user