From af715ca0ff641fb7bf12923aa5bda9fe8609788a Mon Sep 17 00:00:00 2001 From: Grant Limberg Date: Thu, 8 May 2025 09:22:28 -0700 Subject: [PATCH] query & null fix --- controller/CV2.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/controller/CV2.cpp b/controller/CV2.cpp index c4f7ad393..87f21483c 100644 --- a/controller/CV2.cpp +++ b/controller/CV2.cpp @@ -375,7 +375,9 @@ void CV2::initializeNetworks() try { char qbuf[2048]; - sprintf(qbuf, "SELECT id, name, configuration , creation_time, last_modified, revision FROM networks_ctl WHERE controller_id = '%s'", _myAddressStr.c_str()); + sprintf(qbuf, "SELECT id, name, configuration , (EXTRACT(EPOCH FROM creation_time AT TIME ZONE 'UTC')*1000)::bigint, " + "(EXTRACT(EPOCH FROM last_modified AT TIME ZONE 'UTC')*1000):bigint, revision " + "FROM networks_ctl WHERE controller_id = '%s'", _myAddressStr.c_str()); auto c = _pool->borrow(); pqxx::work w(*c->c); @@ -386,7 +388,7 @@ void CV2::initializeNetworks() std::string // network ID , std::optional // name , std::string // configuration - , std::optional // created_at + , std::optional // creation_time , std::optional // last_modified , std::optional // revision > row; @@ -490,9 +492,11 @@ void CV2::initializeMembers() char qbuf[2048]; sprintf(qbuf, "SELECT nm.device_id, nm.network_id, nm.authorized, nm.active_bridge, nm.ip_assignments, nm.no_auto_assign_ips, " - "nm.sso_exempt, authentication_expiry_time, nm.creation_time, nm.identity, nm.last_authorized_credential, " - "nm.last_authorized_time, nm.last_deauthorized_time, nm.remote_trace_level, nm.remote_trace_target, " - "nm.revision, nm.capabilities, nm.tags " + "nm.sso_exempt, (EXTRACT(EPOCH FROM nm.authentication_expiry_time AT TIME ZONE 'UTC')*1000)::bigint, " + "EXTRACT(EPOCH FROM nm.creation_time AT TIME ZONE 'UTC')*1000)::bigint, nm.identity, nm.last_authorized_credential, " + "EXTRACT(EPOCH FROM nm.last_authorized_time AT TIME ZONE 'UTC')*1000)::bigint, " + "EXTRACT(EPOCH FROM nm.last_deauthorized_time AT TIME ZONE 'UTC')*1000)::bigint, " + "nm.remote_trace_level, nm.remote_trace_target, nm.revision, nm.capabilities, nm.tags " "FROM network_memberships_ctl nm " "INNER JOIN networks_ctl n " " ON nm.network_id = n.id " @@ -512,7 +516,7 @@ void CV2::initializeMembers() , std::optional // sso_exempt , std::optional // authentication_expiry_time , std::optional // creation_time - , std::string // identity + , std::optional // identity , std::optional // last_authorized_credential , std::optional // last_authorized_time , std::optional // last_deauthorized_time @@ -541,7 +545,7 @@ void CV2::initializeMembers() std::optional sso_exempt = std::get<6>(row); std::optional authentication_expiry_time = std::get<7>(row); std::optional creation_time = std::get<8>(row); - std::string identity = std::get<9>(row); + std::optional identity = std::get<9>(row); std::optional last_authorized_credential = std::get<10>(row); std::optional last_authorized_time = std::get<11>(row); std::optional last_deauthorized_time = std::get<12>(row); @@ -553,7 +557,7 @@ void CV2::initializeMembers() config["objtype"] = "member"; config["id"] = memberId; - config["address"] = identity; + config["address"] = identity.value_or(""); config["nwid"] = networkId; config["authorized"] = authorized; config["activeBridge"] = active_bridge.value_or(false);