Skip to content

Commit

Permalink
Duration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anarthal committed Feb 13, 2024
1 parent 9124ec9 commit e04e1c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion doc/qbk/08_prepared_statements.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ is interpreted by MySQL, depeding on `v`'s type.
[`DATETIME`, `TIMESTAMP`]
]
[
[[reflink time]]
[
[reflink time][br]
Any `std::chrono::duration` convertible to `time`
]
[`TIME`]
[`TIME`]
]
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test/detail/writable_field_traits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ static_assert(!is_writable_field<int&&>::value, "");
static_assert(!is_writable_field<const double&>::value, "");
static_assert(!is_writable_field<const boost::mysql::date&>::value, "");

// durations accepted as long as they can be converted to time
static_assert(is_writable_field<std::chrono::hours>::value, "");
static_assert(is_writable_field<std::chrono::minutes>::value, "");
static_assert(is_writable_field<std::chrono::seconds>::value, "");
static_assert(is_writable_field<std::chrono::milliseconds>::value, "");
static_assert(is_writable_field<std::chrono::microseconds>::value, "");
static_assert(!is_writable_field<std::chrono::nanoseconds>::value, "");

// characters (except signed/unsigned char) not accepted
static_assert(!is_writable_field<char>::value, "");
static_assert(!is_writable_field<const char>::value, "");
Expand Down
12 changes: 12 additions & 0 deletions test/unit/test/format_sql/individual_value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,18 @@ BOOST_AUTO_TEST_CASE(individual_time)
BOOST_TEST(format_sql(single_fmt, opts, (mysql_time::max)()) == "SELECT '2562047788:00:54.775807';");
}

BOOST_AUTO_TEST_CASE(individual_duration)
{
// Durations work as long as they're compatible with time
using namespace std::chrono;

BOOST_TEST(format_sql(single_fmt, opts, hours(21)) == "SELECT '21:00:00.000000';");
BOOST_TEST(format_sql(single_fmt, opts, minutes(3)) == "SELECT '00:03:00.000000';");
BOOST_TEST(format_sql(single_fmt, opts, seconds(-10)) == "SELECT '-00:00:10.000000';");
BOOST_TEST(format_sql(single_fmt, opts, milliseconds(-9)) == "SELECT '-00:00:00.009000';");
BOOST_TEST(format_sql(single_fmt, opts, microseconds(3214)) == "SELECT '00:00:00.003214';");
}

BOOST_AUTO_TEST_CASE(individual_field_view)
{
field referenced("def\\");
Expand Down

0 comments on commit e04e1c3

Please sign in to comment.