Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add query transformation callback feature
Implementation of query transformation requested in ticket #66: * Add query_transformation.h with internal types * Add method session::set_query_transformation<T>() - assigns user-defined function or functor * Add session::get_query() - returns string with transformed query. * Replace use of session::get_query_stream() with get_query() * Keep session::get_query_stream() to access original query accumulated in current session statement * Add test_query_transformation to common tests. Tested using VS2012 on Windows 8 against DB2, ODBC (PostgreSQL, SQL Server), MySQL, Oracle, SQLite3.
- Loading branch information
Showing
6 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Copyright (C) 2013 Mateusz Loskot <mateusz@loskot.net> | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// (See accompanying file LICENSE_1_0.txt or copy at | ||
// http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
|
||
#ifndef SOCI_QUERY_TRANSFORMATION_H_INCLUDED | ||
#define SOCI_QUERY_TRANSFORMATION_H_INCLUDED | ||
|
||
#include "soci-config.h" | ||
#include <functional> | ||
#include <string> | ||
|
||
namespace soci | ||
{ | ||
|
||
namespace details | ||
{ | ||
|
||
// TODO: use std::unary_function<const std::string&, std::string> | ||
class query_transformation_function : public std::unary_function<std::string, std::string> | ||
{ | ||
public: | ||
virtual result_type operator()(argument_type a) const = 0; | ||
}; | ||
|
||
template <typename T> | ||
class query_transformation : public query_transformation_function | ||
{ | ||
public: | ||
query_transformation(T callback) | ||
: callback_(callback) | ||
{} | ||
|
||
result_type operator()(argument_type query) const | ||
{ | ||
return callback_(query); | ||
} | ||
|
||
private: | ||
T callback_; | ||
}; | ||
|
||
} // namespace details | ||
|
||
} // namespace soci | ||
|
||
#endif // SOCI_QUERY_TRANSFORMATION_H_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters