mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Added insert_set to create first custom insert
This commit is contained in:
parent
712c79cb8a
commit
0b8ccaa985
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2013-2015, Roland Bock
|
* Copyright (c) 2013-2016, Roland Bock
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without modification,
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
@ -635,6 +635,20 @@ namespace sqlpp
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename... Assignments>
|
||||||
|
auto insert_set(Assignments... assignments)
|
||||||
|
-> decltype(statement_t<void, no_insert_value_list_t>().set(assignments...))
|
||||||
|
{
|
||||||
|
return statement_t<void, no_insert_value_list_t>().set(assignments...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename Database, typename... Assignments>
|
||||||
|
auto dynamic_insert_set(Assignments... assignments)
|
||||||
|
-> decltype(statement_t<Database, no_insert_value_list_t>().dynamic_set(assignments...))
|
||||||
|
{
|
||||||
|
return statement_t<Database, no_insert_value_list_t>().dynamic_set(assignments...);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -57,6 +57,10 @@ int CustomQuery(int, char* [])
|
|||||||
std::cerr << row.alpha << std::endl;
|
std::cerr << row.alpha << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a custom "insert or ignore"
|
||||||
|
db(custom_query(sqlpp::insert(), sqlpp::verbatim(" OR IGNORE"), into(t),
|
||||||
|
insert_set(t.beta = "sample", t.gamma = true)));
|
||||||
|
|
||||||
// A custom (select ... into) with adjusted return type
|
// A custom (select ... into) with adjusted return type
|
||||||
// The first argument with a return type is the select, but the custom query is really an insert. Thus, we tell it so.
|
// The first argument with a return type is the select, but the custom query is really an insert. Thus, we tell it so.
|
||||||
printer.reset();
|
printer.reset();
|
||||||
|
Loading…
Reference in New Issue
Block a user