Skip to content

Commit 07ae00c

Browse files
committed
Update handling of Boolean session/client options.
1 parent 2b0a75e commit 07ae00c

File tree

3 files changed

+50
-32
lines changed

3 files changed

+50
-32
lines changed

common/settings.h

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -679,18 +679,19 @@ Settings_impl::Setter::set_option<Settings_impl::Session_option_impl::AUTH>(
679679
}
680680

681681

682-
// Other options that need special handling.
682+
// Connection attributes.
683683

684684

685-
//template<>
686-
//inline void
687-
//Settings_impl::Setter::set_option<Settings_impl::Session_option_impl::DNS_SRV>(
688-
// const bool &val
689-
//)
690-
//{
691-
// m_data.m_dns_srv = val;
692-
// add_option(Settings_impl::Session_option_impl::DNS_SRV, val);
693-
//}
685+
template<>
686+
inline void
687+
Settings_impl::Setter::set_option<
688+
Settings_impl::Session_option_impl::CONNECTION_ATTRIBUTES>(const bool& val)
689+
{
690+
if (val)
691+
m_data.init_connection_attr();
692+
else
693+
m_data.clear_connection_attr();
694+
}
694695

695696

696697
template<>
@@ -700,9 +701,9 @@ Settings_impl::Session_option_impl::CONNECTION_ATTRIBUTES>(const std::string &va
700701
{
701702

702703
struct processor
703-
: parser::JSON_parser::Processor
704-
, Any_prc
705-
, Scalar_prc
704+
: parser::JSON_parser::Processor
705+
, Any_prc
706+
, Scalar_prc
706707
{
707708
Settings_impl::Data &m_data;
708709
string m_key;
@@ -942,9 +943,6 @@ void Settings_impl::Setter::null()
942943
case Session_option_impl::USER:
943944
throw_error("Option ... can not be unset");
944945
break;
945-
case Session_option_impl::CONNECTION_ATTRIBUTES:
946-
m_data.clear_connection_attr();
947-
break;
948946
case Session_option_impl::LAST:
949947
break;
950948
default:
@@ -955,28 +953,45 @@ void Settings_impl::Setter::null()
955953

956954

957955
inline
958-
void Settings_impl::Setter::yesno(bool b)
956+
void Settings_impl::Setter::yesno(bool val)
959957
{
958+
959+
#define SET_OPTION_BOOL_bool(X,N) \
960+
case Session_option_impl::X: return set_option<Session_option_impl::X, bool>(val);
961+
#define SET_OPTION_BOOL_any(X,N) break;
962+
#define SET_OPTION_BOOL_num(X,N) SET_OPTION_BOOL_any(X,N)
963+
#define SET_OPTION_BOOL_str(X,N) SET_OPTION_BOOL_any(X,N)
964+
965+
#define SET_CLI_OPTION_BOOL_bool(X,N) \
966+
case Client_option_impl::X: return set_option<Client_option_impl::X, bool>(val);
967+
#define SET_CLI_OPTION_BOOL_any(X,N) SET_OPTION_BOOL_any(X,N)
968+
#define SET_CLI_OPTION_BOOL_num(X,N) SET_OPTION_BOOL_any(X,N)
969+
#define SET_CLI_OPTION_BOOL_str(X,N) SET_OPTION_BOOL_any(X,N)
970+
960971
switch (m_cur_opt)
961972
{
962-
case Client_option_impl::POOLING:
963-
add_option(m_cur_opt, b);
964-
return;
973+
SESSION_OPTION_LIST(SET_OPTION_BOOL)
974+
CLIENT_OPTION_LIST(SET_CLI_OPTION_BOOL)
975+
default:
976+
break;
977+
}
965978

966-
case Session_option_impl::CONNECTION_ATTRIBUTES:
967-
if (b)
968-
m_data.init_connection_attr();
969-
else
970-
m_data.clear_connection_attr();
971-
return;
972-
case Session_option_impl::DNS_SRV:
973-
add_option(m_cur_opt, b);
974-
return;
975-
default:break;
979+
/*
980+
Special handling of CONNECTION_ATTRIBUTES option which is declared
981+
as string option, but it can be also set to a bool value.
982+
*/
983+
984+
switch (m_cur_opt)
985+
{
986+
SET_OPTION_BOOL_bool(CONNECTION_ATTRIBUTES, val)
987+
default:
988+
break;
976989
}
990+
977991
throw_error("Option ... can not be bool");
978992
}
979993

994+
980995
// URI processor
981996

982997
inline

devapi/tests/session-t.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,7 +2383,7 @@ TEST_F(Sess, dns_srv)
23832383
try
23842384
{
23852385
auto cli = getClient("mysqlx+srv://root@_mysqlx._tcp.localhost:33060");
2386-
FAIL();
2386+
FAIL() << "Error expected if port is specified for mysqlx+srv settings";
23872387
}
23882388
catch(Error &e)
23892389
{
@@ -2397,7 +2397,7 @@ TEST_F(Sess, dns_srv)
23972397
SessionOption::PORT, 33060,
23982398
SessionOption::DNS_SRV, true,
23992399
SessionOption::USER, "root");
2400-
FAIL();
2400+
FAIL() << "Error expected if PORT specified together with DNS_SRV";
24012401
}
24022402
catch(Error &e)
24032403
{

include/mysqlx/common/settings.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,9 @@ void Settings_impl::Data::erase(int opt)
361361
case Session_option_impl::SSL_MODE:
362362
m_ssl_mode = SSL_mode::LAST;
363363
break;
364+
case Session_option_impl::CONNECTION_ATTRIBUTES:
365+
clear_connection_attr();
366+
break;
364367
default:
365368
break;
366369
}

0 commit comments

Comments
 (0)