@@ -506,10 +506,13 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
506
506
bool secure_auth= true ;
507
507
#endif
508
508
509
+ sql::ConnectOptionsMap::const_iterator it;
510
+
509
511
/* Port from options must be set as default for all hosts where port
510
512
is not specified */
511
513
{
512
- sql::ConnectOptionsMap::const_iterator it = properties.find (" port" );
514
+ it = properties.find (" port" );
515
+
513
516
if (it != properties.end ()) {
514
517
try {
515
518
p_i = (it->second ).get < int >();
@@ -526,31 +529,56 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
526
529
527
530
/* Values set in properties individually should have priority over those
528
531
we restore from Uri */
529
- sql::ConnectOptionsMap::const_iterator it = properties.find (" hostName" );
532
+ {
533
+ it = properties.find (" hostName" );
530
534
531
- if (it != properties.end ()) {
532
- try {
533
- p_s = (it->second ).get < sql::SQLString >();
534
- } catch (sql::InvalidArgumentException&) {
535
- throw sql::InvalidArgumentException (" Wrong type passed for userName expected sql::SQLString" );
536
- }
537
- if (p_s) {
538
- /*
539
- Parsing uri prior to processing all parameters, so indivudually
540
- specified parameters precede over those in the uri
541
- */
542
- if (!parseUri (*p_s, uri))
543
- throw sql::InvalidArgumentException (" Invalid hostname URI" );
535
+ if (it != properties.end ()) {
536
+ try {
537
+ p_s = (it->second ).get < sql::SQLString >();
538
+ } catch (sql::InvalidArgumentException&) {
539
+ throw sql::InvalidArgumentException (" Wrong type passed for userName expected sql::SQLString" );
540
+ }
541
+ if (p_s) {
542
+ /*
543
+ Parsing uri prior to processing all parameters, so indivudually
544
+ specified parameters precede over those in the uri
545
+ */
546
+ if (!parseUri (*p_s, uri))
547
+ throw sql::InvalidArgumentException (" Invalid hostname URI" );
544
548
545
- } else {
546
- throw sql::InvalidArgumentException (" No string value passed for hostName" );
549
+ } else {
550
+ throw sql::InvalidArgumentException (" No string value passed for hostName" );
551
+ }
547
552
}
548
553
}
549
554
555
+ /*
556
+ Note: We set pluginDir option early because other options that are plugin
557
+ specific might require loading plugins before they can be set.
558
+ */
550
559
551
- #define PROCESS_CONN_OPTION (option_type, options_map ) process_connection_option< option_type >(it, options_map, sizeof (options_map)/sizeof (String2IntMap), proxy)
560
+ {
561
+ it = properties.find (OPT_PLUGIN_DIR);
552
562
553
- for (it = properties.begin (); it != properties.end (); ++it) {
563
+ if (it != properties.end ()) {
564
+ try {
565
+ p_s = (it->second ).get < sql::SQLString >();
566
+ } catch (sql::InvalidArgumentException&) {
567
+ throw sql::InvalidArgumentException (" Wrong type passed for pluginDir expected sql::SQLString" );
568
+ }
569
+ if (p_s) {
570
+ proxy->options (sql::mysql::MYSQL_PLUGIN_DIR, *p_s);
571
+ }
572
+ else {
573
+ throw sql::InvalidArgumentException (" No string value passed for pluginDir" );
574
+ }
575
+ }
576
+ }
577
+
578
+ #define PROCESS_CONN_OPTION (option_type, options_map ) \
579
+ process_connection_option< option_type >(it, options_map, sizeof (options_map)/sizeof (String2IntMap), proxy)
580
+
581
+ for (it = properties.begin (); it != properties.end (); ++it) {
554
582
if (!it->first .compare (OPT_USERNAME)) {
555
583
try {
556
584
p_s = (it->second ).get < sql::SQLString >();
@@ -751,7 +779,7 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
751
779
intern->defaultStatementResultType = static_cast < sql::ResultSet::enum_type >(*p_i);
752
780
/* The connector is not ready for unbuffered as we need to refetch */
753
781
} else if (!it->first .compare (" defaultPreparedStatementResultType" )) {
754
- #if WE_SUPPORT_USE_RESULT_WITH_PS
782
+ #if WE_SUPPORT_USE_RESULT_WITH_PS
755
783
try {
756
784
p_i = (it->second ).get < int >();
757
785
} catch (sql::InvalidArgumentException&) {
@@ -774,10 +802,10 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
774
802
throw sql::InvalidArgumentException (msg.str ());
775
803
} while (0 );
776
804
intern->defaultPreparedStatementResultType = static_cast < sql::ResultSet::enum_type >(*p_i);
777
- #else
805
+ #else
778
806
throw SQLException (" defaultPreparedStatementResultType parameter still not implemented" );
779
807
780
- #endif
808
+ #endif
781
809
} else if (!it->first .compare (OPT_METADATA_INFO_SCHEMA)) {
782
810
try {
783
811
p_b = (it->second ).get <bool >();
@@ -867,13 +895,13 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
867
895
} catch (sql::InvalidArgumentException&) {
868
896
throw sql::InvalidArgumentException (" Wrong type passed for useLegacyAuth expected sql::SQLString" );
869
897
}
870
- #if MYCPPCONN_STATIC_MYSQL_VERSION_ID < 80000
898
+ #if MYCPPCONN_STATIC_MYSQL_VERSION_ID < 80000
871
899
if (p_b) {
872
900
secure_auth= !*p_b;
873
901
} else {
874
902
throw sql::InvalidArgumentException (" No bool value passed for useLegacyAuth" );
875
903
}
876
- #endif
904
+ #endif
877
905
} else if (!it->first .compare (OPT_CONNECT_ATTR_ADD)) {
878
906
const std::map< sql::SQLString, sql::SQLString > *conVal;
879
907
try {
@@ -909,22 +937,22 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
909
937
} else if (!it->first .compare (OPT_CONNECT_ATTR_RESET)) {
910
938
proxy->options (MYSQL_OPT_CONNECT_ATTR_RESET, 0 );
911
939
912
- #if MYCPPCONN_STATIC_MYSQL_VERSION_ID > 80000
940
+ #if MYCPPCONN_STATIC_MYSQL_VERSION_ID > 80000
913
941
914
942
// Deprecated
915
943
} else if (!it->first .compare (" sslVerify" )) {
916
944
917
945
ssl_mode ssl_mode_val = (it->second ).get < bool >() ? SSL_MODE_VERIFY_CA
918
- : SSL_MODE_PREFERRED;
946
+ : SSL_MODE_PREFERRED;
919
947
proxy->options (MYSQL_OPT_SSL_MODE, &ssl_mode_val);
920
948
921
949
// Deprecated
922
950
} else if (!it->first .compare (" sslEnforce" )) {
923
951
ssl_mode ssl_mode_val = (it->second ).get < bool >() ? SSL_MODE_REQUIRED
924
- : SSL_MODE_PREFERRED;
952
+ : SSL_MODE_PREFERRED;
925
953
proxy->options (MYSQL_OPT_SSL_MODE, &ssl_mode_val);
926
954
927
- #endif
955
+ #endif
928
956
} else if (!it->first .compare (OPT_OCI_CONFIG_FILE)) {
929
957
try {
930
958
p_s= (it->second ).get <sql::SQLString>();
@@ -938,12 +966,19 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
938
966
" oci-config-file" ,
939
967
*p_s);
940
968
} catch (sql::InvalidArgumentException &e) {
941
- throw ::sql::SQLUnsupportedOptionException (e.what (), OPT_OCI_CONFIG_FILE);
969
+ throw ::sql::SQLUnsupportedOptionException (
970
+ " Failed to set config file for authentication_oci_client plugin" ,
971
+ OPT_OCI_CONFIG_FILE
972
+ );
942
973
}
943
974
975
+ }
976
+ else if (!it->first .compare (OPT_PLUGIN_DIR)) {
977
+ // Nothing to do here: this option was handeld before the loop
978
+
944
979
/* If you need to add new integer connection option that should result in
945
- calling mysql_optiong - add its mapping to the intOptions array
946
- */
980
+ calling mysql_optiong - add its mapping to the intOptions array
981
+ */
947
982
} else if (PROCESS_CONN_OPTION (int , intOptions)) {
948
983
// Nothing to do here
949
984
0 commit comments