tqcq
99c258107b
All checks were successful
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m24s
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m30s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m43s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m47s
linux-x64-gcc / linux-gcc (push) Successful in 2m11s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 3m19s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 3m39s
Co-authored-by: tqcq <99722391+tqcq@users.noreply.github.com> Reviewed-on: #2
1.8 KiB
1.8 KiB
Introduction
This page explains insert statements with a static structure. If you want to learn about constructing insert statements at runtime, you should still read this page first and then move on to dynamic insert statements.
A Basic example
Haven't found the time to document this in any detail, yet, but this is an example:
db(insert_into(tab).set(tab.gamma = true));
db(insert_into(tabDateTime)
.set(tabDateTime.colTimePoint = std::chrono::system_clock::now()));
This is how you could insert multiple rows at a time:
auto multi_insert = insert_into(t).columns(t.gamma, t.beta, t.delta);
multi_insert.values.add(t.gamma = true, t.beta = "cheesecake", t.delta = 1);
multi_insert.values.add(t.gamma = sqlpp::default_value, t.beta = sqlpp::default_value,
t.delta = sqlpp::default_value);
multi_insert.values.add(t.gamma = sqlpp::value_or_null(true),
t.beta = sqlpp::value_or_null("pie"),
t.delta = sqlpp::value_or_null<sqlpp::integer>(sqlpp::null));
db(multi_insert);
Note that add
currently requires precise value types, equal to the respective column's value
type. For instance, time point columns are represented as
std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>
.
Thus, when using such a column in a multi_insert
, you might have to cast to the right
time point.
auto multi_time_insert = insert_into(tabDateTime).columns(tabDateTime.colTimePoint);
multi_time_insert.values.add(tabDateTime.colTimePoint = std::chrono::time_point_cast<std::chrono::microseconds>(
std::chrono::system_clock::now()));
Similar for other data types.
See also dynamic insert statements.