@@ -76,7 +76,16 @@ get_mysql_option(sql::mysql::MySQL_Connection_Options opt)
76
76
case sql::mysql::MYSQL_OPT_WRITE_TIMEOUT: return ::MYSQL_OPT_WRITE_TIMEOUT;
77
77
case sql::mysql::MYSQL_OPT_USE_RESULT: return ::MYSQL_OPT_USE_RESULT;
78
78
case sql::mysql::MYSQL_REPORT_DATA_TRUNCATION: return ::MYSQL_REPORT_DATA_TRUNCATION;
79
- case sql::mysql::MYSQL_OPT_RECONNECT: return ::MYSQL_OPT_RECONNECT;
79
+ case sql::mysql::MYSQL_OPT_RECONNECT:
80
+ #if MYCPPCONN_STATIC_MYSQL_VERSION_ID < 80300
81
+ return ::MYSQL_OPT_RECONNECT;
82
+ #else
83
+ {
84
+ std::string errorOption (" MYSQL_OPT_RECONNECT" );
85
+ throw sql::SQLUnsupportedOptionException (" Option is not supported" ,
86
+ errorOption);
87
+ }
88
+ #endif
80
89
case sql::mysql::MYSQL_PLUGIN_DIR: return ::MYSQL_PLUGIN_DIR;
81
90
case sql::mysql::MYSQL_DEFAULT_AUTH: return ::MYSQL_DEFAULT_AUTH;
82
91
case sql::mysql::MYSQL_OPT_BIND: return ::MYSQL_OPT_BIND;
@@ -177,6 +186,15 @@ MySQL_NativeConnectionWrapper::connect(const ::sql::SQLString & host,
177
186
const ::sql::SQLString & socket_or_pipe,
178
187
unsigned long client_flag)
179
188
{
189
+ m_host = host;
190
+ m_user = user;
191
+ m_passwd = passwd;
192
+ m_db = db;
193
+ m_port = port;
194
+ m_socket_or_pipe = socket_or_pipe;
195
+ m_client_flag = client_flag;
196
+ m_dns_srv = false ;
197
+
180
198
return (NULL != api->real_connect (mysql, nullIfEmpty (host), user.c_str (),
181
199
nullIfEmpty (passwd),
182
200
nullIfEmpty (db), port,
@@ -193,6 +211,13 @@ MySQL_NativeConnectionWrapper::connect_dns_srv(const ::sql::SQLString & host,
193
211
const ::sql::SQLString & db,
194
212
unsigned long client_flag)
195
213
{
214
+ m_host = host;
215
+ m_user = user;
216
+ m_passwd = passwd;
217
+ m_db = db;
218
+ m_client_flag = client_flag;
219
+ m_dns_srv = true ;
220
+
196
221
return (NULL != api->real_connect_dns_srv (mysql, nullIfEmpty (host), user.c_str (),
197
222
nullIfEmpty (passwd),
198
223
nullIfEmpty (db), client_flag));
@@ -318,6 +343,13 @@ MySQL_NativeConnectionWrapper::next_result()
318
343
int
319
344
MySQL_NativeConnectionWrapper::options (::sql::mysql::MySQL_Connection_Options option, const void * value)
320
345
{
346
+ #if MYCPPCONN_STATIC_MYSQL_VERSION_ID >= 80300
347
+ if (option == MYSQL_OPT_RECONNECT) {
348
+ reconnect = *(bool *)value;
349
+ // For reconnect option we don't pass the call to api.
350
+ return 0 ;
351
+ }
352
+ #endif
321
353
return api->options (mysql, get_mysql_option (option), value);
322
354
}
323
355
/* }}} */
@@ -378,6 +410,14 @@ MySQL_NativeConnectionWrapper::options(::sql::mysql::MySQL_Connection_Options op
378
410
int
379
411
MySQL_NativeConnectionWrapper::get_option (::sql::mysql::MySQL_Connection_Options option, const void * value)
380
412
{
413
+ #if MYCPPCONN_STATIC_MYSQL_VERSION_ID >= 80300
414
+ if (option == MYSQL_OPT_RECONNECT) {
415
+ *(bool *)value = reconnect;
416
+ // For reconnect option we don't pass the call to api.
417
+ return 0 ;
418
+ }
419
+ #endif
420
+
381
421
return api->get_option (mysql, get_mysql_option (option), value);
382
422
}
383
423
/* }}} */
@@ -506,7 +546,25 @@ MySQL_NativeConnectionWrapper::query(const SQLString & stmt_str)
506
546
int
507
547
MySQL_NativeConnectionWrapper::ping ()
508
548
{
509
- return api->ping (mysql);
549
+ int res = api->ping (mysql);
550
+
551
+ #if MYCPPCONN_STATIC_MYSQL_VERSION_ID >= 80300
552
+ if (res && reconnect) {
553
+ // Try reconnecting if could not ping and reconnect
554
+ // option is set.
555
+ bool connect_result = !m_dns_srv ?
556
+ connect (m_host, m_user, m_passwd, m_db, m_port,
557
+ m_socket_or_pipe, m_client_flag)
558
+ :
559
+ connect_dns_srv (m_host, m_user, m_passwd, m_db,
560
+ m_client_flag);
561
+ // If connected return success, otherwise let ping()
562
+ // return the proper error.
563
+ res = connect_result ? 0 : api->ping (mysql);
564
+ }
565
+ #endif
566
+
567
+ return res;
510
568
}
511
569
/* }}} */
512
570
0 commit comments