Skip to content

Commit 36ab87b

Browse files
committed
Merge branch 'wl15425' into trunk
Change-Id: I6207dc536927132f60d8e3950baf7bbb005e5aed
2 parents 5f30829 + 61082ec commit 36ab87b

File tree

6 files changed

+102
-19
lines changed

6 files changed

+102
-19
lines changed

common/CMakeLists.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,6 @@ if(CLANG)
4343
)
4444
endif()
4545

46-
#
47-
# Generate version info
48-
#
49-
50-
set(CLIENT_VERSION ${CONCPP_VERSION})
51-
52-
if(EXTRA_NAME_SUFFIX STREQUAL "-commercial")
53-
SET(CONCPP_LICENSE "COMMERCIAL")
54-
else()
55-
SET(CONCPP_LICENSE "GPL-2.0")
56-
endif()
57-
5846
#
5947
# Note: generated version_info.h is placed in the build location
6048
# and the common target is configured to include it before the

jdbc/cppconn/version_info.h.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636

3737
#define MYCPPCONN_DM_VERSION "@CONCPP_VERSION@"
3838
#define MYCPPCONN_DM_VERSION_ID @CONCPP_VERSION_NUMBER@
39+
#define MYSQL_CONCPP_LICENSE "@CONCPP_LICENSE@"
3940

4041
#define MYSQL_CONCPP_VERSION_MAJOR @CONNECTOR_MAJOR@
4142
#define MYSQL_CONCPP_VERSION_MINOR @CONNECTOR_MINOR@

jdbc/driver/mysql_connection.cpp

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,18 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
522522
bool secure_auth= true;
523523
#endif
524524

525+
/*
526+
Add default connector connection attributes
527+
*/
528+
std::map<sql::SQLString, sql::SQLString> default_attr = {
529+
{"_connector_name", "mysql-connector-cpp"},
530+
{"_connector_version", MYCPPCONN_DM_VERSION},
531+
{"_connector_license", MYSQL_CONCPP_LICENSE}};
532+
533+
for (auto &el : default_attr) {
534+
proxy->options(sql::mysql::MYSQL_OPT_CONNECT_ATTR_ADD, el.first, el.second);
535+
}
536+
525537
sql::ConnectOptionsMap::const_iterator it;
526538

527539
/* Port from options must be set as default for all hosts where port
@@ -951,7 +963,11 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
951963
std::map< sql::SQLString, sql::SQLString >::const_iterator conn_attr_it;
952964
for (conn_attr_it = conVal->begin(); conn_attr_it != conVal->end(); conn_attr_it++) {
953965
try {
954-
proxy->options(sql::mysql::MYSQL_OPT_CONNECT_ATTR_ADD, conn_attr_it->first, conn_attr_it->second);
966+
//Skip default values
967+
if (default_attr.find(conn_attr_it->first) != default_attr.end())
968+
continue;
969+
proxy->options(sql::mysql::MYSQL_OPT_CONNECT_ATTR_ADD,
970+
conn_attr_it->first, conn_attr_it->second);
955971
} catch (sql::InvalidArgumentException& e) {
956972
std::string errorOption("MYSQL_OPT_CONNECT_ATTR_ADD");
957973
throw ::sql::SQLUnsupportedOptionException(e.what(), errorOption);
@@ -966,12 +982,15 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
966982
}
967983
std::list< sql::SQLString >::const_iterator conn_attr_it;
968984
for (conn_attr_it = conVal->begin(); conn_attr_it != conVal->end(); conn_attr_it++) {
985+
// Skip default values
986+
if (default_attr.find(*conn_attr_it) != default_attr.end())
987+
continue;
969988
try {
970989
proxy->options(MYSQL_OPT_CONNECT_ATTR_DELETE, *conn_attr_it);
971-
} catch (sql::InvalidArgumentException& e) {
972-
std::string errorOption("MYSQL_OPT_CONNECT_ATTR_DELETE");
973-
throw ::sql::SQLUnsupportedOptionException(e.what(), errorOption);
974-
}
990+
} catch (sql::InvalidArgumentException &e) {
991+
std::string errorOption("MYSQL_OPT_CONNECT_ATTR_DELETE");
992+
throw ::sql::SQLUnsupportedOptionException(e.what(), errorOption);
993+
}
975994
}
976995
} else if (!it->first.compare(OPT_CONNECT_ATTR_RESET)) {
977996
proxy->options(MYSQL_OPT_CONNECT_ATTR_RESET, 0);

jdbc/test/unit/classes/connection.cpp

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,9 +2382,68 @@ void connection::enableClearTextAuth()
23822382
stmt->executeUpdate("DROP USER 't_ct_user'@'%'");
23832383
}
23842384

2385+
void connection::default_connector_attributes() {
2386+
logMsg(
2387+
"connection::default_connector_attributes - Check if default attributes "
2388+
"are set");
2389+
2390+
sql::SQLString query =
2391+
"SELECT ATTR_NAME, ATTR_VALUE FROM "
2392+
"performance_schema.session_account_connect_attrs WHERE ATTR_NAME LIKE "
2393+
"'_connector_%' AND PROCESSLIST_ID = connection_id() ORDER BY ATTR_NAME "
2394+
"ASC;";
2395+
2396+
std::map<sql::SQLString, sql::SQLString> attributes = {
2397+
{"_connector_version", MYCPPCONN_DM_VERSION},
2398+
{"_connector_license", MYSQL_CONCPP_LICENSE},
2399+
{"_connector_name", "mysql-connector-cpp"}};
2400+
2401+
auto check_attr = [&attributes](ResultSet &res) {
2402+
ASSERT_EQUALS(attributes.size(), res->rowsCount());
2403+
while (res->next()) {
2404+
ASSERT_EQUALS(attributes[res->getString("ATTR_NAME")],
2405+
res->getString("ATTR_VALUE"));
2406+
}
2407+
};
23852408

2386-
void connection::connectAttrAdd()
2387-
{
2409+
res.reset(stmt->executeQuery(query));
2410+
2411+
check_attr(res);
2412+
2413+
{
2414+
testsuite::Connection conn1;
2415+
sql::ConnectOptionsMap opts;
2416+
std::map<sql::SQLString, sql::SQLString> connectAttrMap = {
2417+
{"_connector_version", "1.1.1"},
2418+
{"_connector_license", "MIT"},
2419+
{"_connector_name", "mysql-connector-cpp-modified"}};
2420+
2421+
opts[OPT_CONNECT_ATTR_ADD] = connectAttrMap;
2422+
2423+
conn1.reset(getConnection(&opts));
2424+
stmt.reset(conn1->createStatement());
2425+
res.reset(stmt->executeQuery(query));
2426+
2427+
check_attr(res);
2428+
}
2429+
2430+
{
2431+
testsuite::Connection conn1;
2432+
sql::ConnectOptionsMap opts;
2433+
std::list<sql::SQLString> connectAttrMapDelete = {
2434+
"_connector_version", "_connector_license", "_connector_name"};
2435+
2436+
opts[OPT_CONNECT_ATTR_DELETE] = connectAttrMapDelete;
2437+
2438+
conn1.reset(getConnection(&opts));
2439+
stmt.reset(conn1->createStatement());
2440+
res.reset(stmt->executeQuery(query));
2441+
2442+
check_attr(res);
2443+
}
2444+
}
2445+
2446+
void connection::connectAttrAdd() {
23882447
logMsg("connection::connectAttr - MYSQL_OPT_CONNECT_ATTR_ADD|MYSQL_OPT_CONNECT_ATTR_DELETE");
23892448

23902449
int serverVersion=getMySQLVersion(con);

jdbc/test/unit/classes/connection.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class connection : public unit_fixture
8080
TEST_CASE(loadSameLibraryTwice);
8181
#endif
8282
TEST_CASE(enableClearTextAuth);
83+
TEST_CASE(default_connector_attributes);
8384
TEST_CASE(connectAttrAdd);
8485
TEST_CASE(connectAttrReset);
8586
TEST_CASE(connectCharsetDir);
@@ -213,6 +214,11 @@ class connection : public unit_fixture
213214

214215
void enableClearTextAuth();
215216

217+
/*
218+
Test to check if connector default attributes are set
219+
*/
220+
void default_connector_attributes();
221+
216222
/*
217223
* Test for Connection attributes options MYSQL_OPT_CONNECT_ATTR_ADD
218224
* | MYSQL_OPT_CONNECT_ATTR_DELETE

version.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ set(CONCPP_VERSION_NUMBER
4747
CACHE INTERNAL "version info"
4848
)
4949

50+
#
51+
# Generate version info
52+
#
53+
54+
if(EXTRA_NAME_SUFFIX STREQUAL "-commercial")
55+
SET(CONCPP_LICENSE "COMMERCIAL" CACHE INTERNAL "license info")
56+
else()
57+
SET(CONCPP_LICENSE "GPL-2.0" CACHE INTERNAL "license info")
58+
endif()
59+
5060
#
5161
# ABI versions
5262
#

0 commit comments

Comments
 (0)