diff options
author | Grant Limberg <grant.limberg@zerotier.com> | 2019-04-04 15:11:01 -0700 |
---|---|---|
committer | Grant Limberg <grant.limberg@zerotier.com> | 2019-04-04 15:11:01 -0700 |
commit | 6014df2847087f0682cd2bdcd25b91d5c700b750 (patch) | |
tree | ef6291fd2c6e7d74c232ce16aaa0b39e98d0f6dd | |
parent | 55a9e6e05ebd18ca6d9b4f1ac482b980173d832d (diff) | |
download | infinitytier-6014df2847087f0682cd2bdcd25b91d5c700b750.tar.gz infinitytier-6014df2847087f0682cd2bdcd25b91d5c700b750.zip |
fix compile & sql errors
-rw-r--r-- | controller/PostgreSQL.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp index aa87331c..ad53bc54 100644 --- a/controller/PostgreSQL.cpp +++ b/controller/PostgreSQL.cpp @@ -1314,13 +1314,15 @@ void PostgreSQL::onlineNotificationThread() if (found == _networks.end()) { continue; // skip members trying to join non-existant networks } - + + std::string networkId(nwidTmp); + std::string memberId(memTmp); + std::vector<std::string> &members = updateMap[networkId]; members.push_back(memberId); lastOnlineCumulative[i->first] = i->second.first; - std::string networkId(nwidTmp); - std::string memberId(memTmp); + const char *qvals[2] = { networkId.c_str(), @@ -1356,7 +1358,13 @@ void PostgreSQL::onlineNotificationThread() memberUpdate << ", "; } - memberUpdate << "('" << networkId << "', '" << memberId << '", ' << ipAddr << "', TO_TIMESTAMP(" << timestamp << "::double precision/1000))"; + memberUpdate << "('" << networkId << "', '" << memberId << "', "; + if (ipAddr.empty()) { + memberUpdate << "NULL, "; + } else { + memberUpdate << "'" << ipAddr << "', "; + } + memberUpdate << "TO_TIMESTAMP(" << timestamp << "::double precision/1000))"; memberAdded = true; } else if (nrows > 1) { fprintf(stderr, "nrows > 1?!?"); @@ -1369,7 +1377,7 @@ void PostgreSQL::onlineNotificationThread() if (memberAdded) { res = PQexec(conn, memberUpdate.str().c_str()); - if (res != PGRES_COMMAND_OK) { + if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "Multiple insert failed: %s", PQerrorMessage(conn)); } PQclear(res); @@ -1422,11 +1430,11 @@ void PostgreSQL::onlineNotificationThread() } } - char *nvals[1] = { - networkId.c_str(); + const char *nvals[1] = { + networkId.c_str() }; - res = PQExecParams(conn, + res = PQexecParams(conn, "SELECT id FROM ztc_network WHERE id = $1", 1, NULL, @@ -1473,8 +1481,8 @@ void PostgreSQL::onlineNotificationThread() << "authorized_member_count = EXCLUDED.authorized_member_count, online_member_count = EXCLUDED.online_member_count, " << "total_member_count = EXCLUDED.total_member_count, last_modified = EXCLUDED.last_modified"; if (networkAdded) { - res = PQExec(conn, networkUpdate.str().c_str()); - if (res != PGRES_COMMAND_OK) { + res = PQexec(conn, networkUpdate.str().c_str()); + if (PQresultStatus(res) != PGRES_COMMAND_OK) { fprintf(stderr, "Error during multiple network upsert: %s", PQresultErrorMessage(res)); } PQclear(res); |