2023-07-25 13:00:05 +08:00
|
|
|
#pragma once
|
|
|
|
|
2013-08-14 04:43:10 +08:00
|
|
|
/*
|
2015-02-16 02:00:21 +08:00
|
|
|
* Copyright (c) 2013-2015, Roland Bock
|
2013-08-14 04:43:10 +08:00
|
|
|
* All rights reserved.
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
2013-08-14 04:43:10 +08:00
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
2013-08-14 04:43:10 +08:00
|
|
|
* Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
2013-08-14 04:43:10 +08:00
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
* other materials provided with the distribution.
|
2015-08-05 20:43:21 +08:00
|
|
|
*
|
2013-08-14 04:43:10 +08:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2014-06-03 05:57:21 +08:00
|
|
|
#include <sqlpp11/statement.h>
|
2014-09-29 19:45:29 +08:00
|
|
|
#include <sqlpp11/connection.h>
|
2013-08-14 04:43:10 +08:00
|
|
|
#include <sqlpp11/type_traits.h>
|
2014-01-26 20:24:42 +08:00
|
|
|
#include <sqlpp11/parameter_list.h>
|
2014-01-09 04:31:29 +08:00
|
|
|
#include <sqlpp11/prepared_insert.h>
|
2014-02-04 14:32:37 +08:00
|
|
|
#include <sqlpp11/default_value.h>
|
2014-06-14 00:51:51 +08:00
|
|
|
#include <sqlpp11/noop.h>
|
|
|
|
#include <sqlpp11/into.h>
|
|
|
|
#include <sqlpp11/insert_value_list.h>
|
2014-01-09 04:31:29 +08:00
|
|
|
|
2013-08-14 04:43:10 +08:00
|
|
|
namespace sqlpp
|
|
|
|
{
|
2015-09-14 03:33:19 +08:00
|
|
|
struct insert_name_t
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
struct insert_t : public statement_name_t<insert_name_t>
|
|
|
|
{
|
|
|
|
using _traits = make_traits<no_value_t, tag::is_return_value>;
|
|
|
|
struct _alias_t
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Statement>
|
|
|
|
struct _result_methods_t
|
|
|
|
{
|
|
|
|
using _statement_t = Statement;
|
|
|
|
|
|
|
|
const _statement_t& _get_statement() const
|
|
|
|
{
|
|
|
|
return static_cast<const _statement_t&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Execute
|
|
|
|
template <typename Db, typename Composite>
|
|
|
|
auto _run(Db& db, const Composite& composite) const -> decltype(db.insert(composite))
|
|
|
|
{
|
|
|
|
return db.insert(composite);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Db>
|
|
|
|
auto _run(Db& db) const -> decltype(db.insert(this->_get_statement()))
|
|
|
|
{
|
|
|
|
return db.insert(_get_statement());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare
|
|
|
|
template <typename Db, typename Composite>
|
|
|
|
auto _prepare(Db& db, const Composite& composite) const -> prepared_insert_t<Db, Composite>
|
|
|
|
{
|
|
|
|
return {{}, db.prepare_insert(composite)};
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Db>
|
|
|
|
auto _prepare(Db& db) const -> prepared_insert_t<Db, _statement_t>
|
|
|
|
{
|
|
|
|
return {{}, db.prepare_insert(_get_statement())};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Context>
|
2021-08-01 18:54:46 +08:00
|
|
|
Context& serialize(const insert_name_t&, Context& context)
|
2015-09-14 03:33:19 +08:00
|
|
|
{
|
2021-08-01 18:54:46 +08:00
|
|
|
context << "INSERT";
|
2015-09-14 03:33:19 +08:00
|
|
|
|
2021-08-01 18:54:46 +08:00
|
|
|
return context;
|
|
|
|
}
|
2015-09-14 03:33:19 +08:00
|
|
|
|
2024-06-09 00:33:40 +08:00
|
|
|
using blank_insert_t = statement_t<insert_t, no_into_t, no_insert_value_list_t>;
|
2015-09-14 03:33:19 +08:00
|
|
|
|
2024-06-09 00:33:40 +08:00
|
|
|
inline auto insert() -> blank_insert_t
|
2015-09-14 03:33:19 +08:00
|
|
|
{
|
2017-09-10 21:40:54 +08:00
|
|
|
return {};
|
2015-09-14 03:33:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Table>
|
2024-06-09 00:33:40 +08:00
|
|
|
constexpr auto insert_into(Table table) -> decltype(blank_insert_t().into(table))
|
2015-09-14 03:33:19 +08:00
|
|
|
{
|
2024-06-09 00:33:40 +08:00
|
|
|
return {blank_insert_t().into(table)};
|
2015-09-14 03:33:19 +08:00
|
|
|
}
|
|
|
|
|
2017-09-10 20:56:51 +08:00
|
|
|
} // namespace sqlpp
|