@@ -507,10 +507,13 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
507
507
bool secure_auth= true ;
508
508
#endif
509
509
510
+ sql::ConnectOptionsMap::const_iterator it;
511
+
510
512
/* Port from options must be set as default for all hosts where port
511
513
is not specified */
512
514
{
513
- sql::ConnectOptionsMap::const_iterator it = properties.find (" port" );
515
+ it = properties.find (" port" );
516
+
514
517
if (it != properties.end ()) {
515
518
try {
516
519
p_i = (it->second ).get < int >();
@@ -527,31 +530,56 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
527
530
528
531
/* Values set in properties individually should have priority over those
529
532
we restore from Uri */
530
- sql::ConnectOptionsMap::const_iterator it = properties.find (" hostName" );
533
+ {
534
+ it = properties.find (" hostName" );
531
535
532
- if (it != properties.end ()) {
533
- try {
534
- p_s = (it->second ).get < sql::SQLString >();
535
- } catch (sql::InvalidArgumentException&) {
536
- throw sql::InvalidArgumentException (" Wrong type passed for userName expected sql::SQLString" );
537
- }
538
- if (p_s) {
539
- /*
540
- Parsing uri prior to processing all parameters, so indivudually
541
- specified parameters precede over those in the uri
542
- */
543
- if (!parseUri (*p_s, uri))
544
- throw sql::InvalidArgumentException (" Invalid hostname URI" );
536
+ if (it != properties.end ()) {
537
+ try {
538
+ p_s = (it->second ).get < sql::SQLString >();
539
+ } catch (sql::InvalidArgumentException&) {
540
+ throw sql::InvalidArgumentException (" Wrong type passed for userName expected sql::SQLString" );
541
+ }
542
+ if (p_s) {
543
+ /*
544
+ Parsing uri prior to processing all parameters, so indivudually
545
+ specified parameters precede over those in the uri
546
+ */
547
+ if (!parseUri (*p_s, uri))
548
+ throw sql::InvalidArgumentException (" Invalid hostname URI" );
545
549
546
- } else {
547
- throw sql::InvalidArgumentException (" No string value passed for hostName" );
550
+ } else {
551
+ throw sql::InvalidArgumentException (" No string value passed for hostName" );
552
+ }
548
553
}
549
554
}
550
555
556
+ /*
557
+ Note: We set pluginDir option early because other options that are plugin
558
+ specific might require loading plugins before they can be set.
559
+ */
551
560
552
- #define PROCESS_CONN_OPTION (option_type, options_map ) process_connection_option< option_type >(it, options_map, sizeof (options_map)/sizeof (String2IntMap), proxy)
561
+ {
562
+ it = properties.find (OPT_PLUGIN_DIR);
553
563
554
- for (it = properties.begin (); it != properties.end (); ++it) {
564
+ if (it != properties.end ()) {
565
+ try {
566
+ p_s = (it->second ).get < sql::SQLString >();
567
+ } catch (sql::InvalidArgumentException&) {
568
+ throw sql::InvalidArgumentException (" Wrong type passed for pluginDir expected sql::SQLString" );
569
+ }
570
+ if (p_s) {
571
+ proxy->options (sql::mysql::MYSQL_PLUGIN_DIR, *p_s);
572
+ }
573
+ else {
574
+ throw sql::InvalidArgumentException (" No string value passed for pluginDir" );
575
+ }
576
+ }
577
+ }
578
+
579
+ #define PROCESS_CONN_OPTION (option_type, options_map ) \
580
+ process_connection_option< option_type >(it, options_map, sizeof (options_map)/sizeof (String2IntMap), proxy)
581
+
582
+ for (it = properties.begin (); it != properties.end (); ++it) {
555
583
if (!it->first .compare (OPT_USERNAME)) {
556
584
try {
557
585
p_s = (it->second ).get < sql::SQLString >();
@@ -574,6 +602,42 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
574
602
} else {
575
603
throw sql::InvalidArgumentException (" No string value passed for password" );
576
604
}
605
+ } else if (!it->first .compare (OPT_PASSWORD1)) {
606
+ try {
607
+ p_s = (it->second ).get < sql::SQLString >();
608
+ } catch (sql::InvalidArgumentException&) {
609
+ throw sql::InvalidArgumentException (" Wrong type passed for password1 expected sql::SQLString" );
610
+ }
611
+ if (p_s) {
612
+ int num = 1 ;
613
+ proxy->options (sql::mysql::MYSQL_OPT_USER_PASSWORD, num, *p_s);
614
+ } else {
615
+ throw sql::InvalidArgumentException (" No string value passed for password1" );
616
+ }
617
+ } else if (!it->first .compare (OPT_PASSWORD2)) {
618
+ try {
619
+ p_s = (it->second ).get < sql::SQLString >();
620
+ } catch (sql::InvalidArgumentException&) {
621
+ throw sql::InvalidArgumentException (" Wrong type passed for password2 expected sql::SQLString" );
622
+ }
623
+ if (p_s) {
624
+ int num = 2 ;
625
+ proxy->options (sql::mysql::MYSQL_OPT_USER_PASSWORD, num, *p_s);
626
+ } else {
627
+ throw sql::InvalidArgumentException (" No string value passed for password2" );
628
+ }
629
+ } else if (!it->first .compare (OPT_PASSWORD3)) {
630
+ try {
631
+ p_s = (it->second ).get < sql::SQLString >();
632
+ } catch (sql::InvalidArgumentException&) {
633
+ throw sql::InvalidArgumentException (" Wrong type passed for password3 expected sql::SQLString" );
634
+ }
635
+ if (p_s) {
636
+ int num = 3 ;
637
+ proxy->options (sql::mysql::MYSQL_OPT_USER_PASSWORD, num, *p_s);
638
+ } else {
639
+ throw sql::InvalidArgumentException (" No string value passed for password3" );
640
+ }
577
641
} else if (!it->first .compare (OPT_PORT)) {
578
642
try {
579
643
p_i = (it->second ).get < int >();
@@ -716,7 +780,7 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
716
780
intern->defaultStatementResultType = static_cast < sql::ResultSet::enum_type >(*p_i);
717
781
/* The connector is not ready for unbuffered as we need to refetch */
718
782
} else if (!it->first .compare (" defaultPreparedStatementResultType" )) {
719
- #if WE_SUPPORT_USE_RESULT_WITH_PS
783
+ #if WE_SUPPORT_USE_RESULT_WITH_PS
720
784
try {
721
785
p_i = (it->second ).get < int >();
722
786
} catch (sql::InvalidArgumentException&) {
@@ -739,10 +803,10 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
739
803
throw sql::InvalidArgumentException (msg.str ());
740
804
} while (0 );
741
805
intern->defaultPreparedStatementResultType = static_cast < sql::ResultSet::enum_type >(*p_i);
742
- #else
806
+ #else
743
807
throw SQLException (" defaultPreparedStatementResultType parameter still not implemented" );
744
808
745
- #endif
809
+ #endif
746
810
} else if (!it->first .compare (OPT_METADATA_INFO_SCHEMA)) {
747
811
try {
748
812
p_b = (it->second ).get <bool >();
@@ -832,13 +896,13 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
832
896
} catch (sql::InvalidArgumentException&) {
833
897
throw sql::InvalidArgumentException (" Wrong type passed for useLegacyAuth expected sql::SQLString" );
834
898
}
835
- #if MYCPPCONN_STATIC_MYSQL_VERSION_ID < 80000
899
+ #if MYCPPCONN_STATIC_MYSQL_VERSION_ID < 80000
836
900
if (p_b) {
837
901
secure_auth= !*p_b;
838
902
} else {
839
903
throw sql::InvalidArgumentException (" No bool value passed for useLegacyAuth" );
840
904
}
841
- #endif
905
+ #endif
842
906
} else if (!it->first .compare (OPT_CONNECT_ATTR_ADD)) {
843
907
const std::map< sql::SQLString, sql::SQLString > *conVal;
844
908
try {
@@ -874,27 +938,48 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
874
938
} else if (!it->first .compare (OPT_CONNECT_ATTR_RESET)) {
875
939
proxy->options (MYSQL_OPT_CONNECT_ATTR_RESET, 0 );
876
940
877
- #if MYCPPCONN_STATIC_MYSQL_VERSION_ID > 80000
941
+ #if MYCPPCONN_STATIC_MYSQL_VERSION_ID > 80000
878
942
879
943
// Deprecated
880
944
} else if (!it->first .compare (" sslVerify" )) {
881
945
882
946
ssl_mode ssl_mode_val = (it->second ).get < bool >() ? SSL_MODE_VERIFY_CA
883
- : SSL_MODE_PREFERRED;
947
+ : SSL_MODE_PREFERRED;
884
948
proxy->options (MYSQL_OPT_SSL_MODE, &ssl_mode_val);
885
949
886
950
// Deprecated
887
951
} else if (!it->first .compare (" sslEnforce" )) {
888
952
ssl_mode ssl_mode_val = (it->second ).get < bool >() ? SSL_MODE_REQUIRED
889
- : SSL_MODE_PREFERRED;
953
+ : SSL_MODE_PREFERRED;
890
954
proxy->options (MYSQL_OPT_SSL_MODE, &ssl_mode_val);
891
955
892
- #endif
956
+ #endif
957
+ } else if (!it->first .compare (OPT_OCI_CONFIG_FILE)) {
958
+ try {
959
+ p_s= (it->second ).get <sql::SQLString>();
960
+ } catch (sql::InvalidArgumentException&) {
961
+ throw sql::InvalidArgumentException (" Wrong type passed for OPT_OCI_CONFIG_FILE. Expected sql::SQLString." );
962
+ }
963
+
964
+ try {
965
+ proxy->plugin_option (MYSQL_CLIENT_AUTHENTICATION_PLUGIN,
966
+ " authentication_oci_client" ,
967
+ " oci-config-file" ,
968
+ *p_s);
969
+ } catch (sql::InvalidArgumentException &e) {
970
+ throw ::sql::SQLUnsupportedOptionException (
971
+ " Failed to set config file for authentication_oci_client plugin" ,
972
+ OPT_OCI_CONFIG_FILE
973
+ );
974
+ }
893
975
976
+ }
977
+ else if (!it->first .compare (OPT_PLUGIN_DIR)) {
978
+ // Nothing to do here: this option was handeld before the loop
894
979
895
980
/* If you need to add new integer connection option that should result in
896
- calling mysql_optiong - add its mapping to the intOptions array
897
- */
981
+ calling mysql_optiong - add its mapping to the intOptions array
982
+ */
898
983
} else if (PROCESS_CONN_OPTION (int , intOptions)) {
899
984
// Nothing to do here
900
985
0 commit comments