QnetDB do-over

dev
Tom Early 5 years ago
parent 227e9c014c
commit 5c6c5f4735

@ -103,9 +103,29 @@ bool CQnetDB::UpdateLH(const char *callsign, const char *sfx, const char module,
if (NULL == db) if (NULL == db)
return false; return false;
std::stringstream sql; std::stringstream sql;
sql << "INSERT OR REPLACE INTO LHEARD (callsign,sfx,module,reflector,lasttime) VALUES ('" << callsign << "','" << sfx << "','" << module << "','" << reflector << "',strftime('%s','now'));"; sql << "SELECT COUNT(*) FROM LHEARD WHERE callsign='" << callsign << "';";
int count = 0;
char *eMsg; char *eMsg;
if (SQLITE_OK != sqlite3_exec(db, sql.str().c_str(), countcallback, &count, &eMsg))
{
fprintf(stderr, "CQnetDB::UpdateLH [%s] error: %s\n", sql.str().c_str(), eMsg);
sqlite3_free(eMsg);
return true;
}
sql.clear();
if (count)
{
sql << "UPDATE LHEARD SET sfx = '" << sfx << "', module = '" << module << "', reflector = '" << reflector << "', lasttime = strftime('%s','now') WHERE callsign = '" << callsign << "';";
}
else
{
sql << "INSERT INTO LHEARD (callsign, sfx, module, reflector, lasttime) VALUES ('" << callsign << "', '" << sfx << "', '" << module << "', '" << reflector << "', strftime('%s','now'));";
}
if (SQLITE_OK != sqlite3_exec(db, sql.str().c_str(), NULL, 0, &eMsg)) if (SQLITE_OK != sqlite3_exec(db, sql.str().c_str(), NULL, 0, &eMsg))
{ {
fprintf(stderr, "CQnetDB::UpdateLH [%s] error: %s\n", sql.str().c_str(), eMsg); fprintf(stderr, "CQnetDB::UpdateLH [%s] error: %s\n", sql.str().c_str(), eMsg);
@ -121,7 +141,7 @@ bool CQnetDB::UpdatePosition(const char *callsign, const char *maidenhead, doubl
if (NULL == db) if (NULL == db)
return false; return false;
std::stringstream sql; std::stringstream sql;
sql << "UPDATE LHEARD SET (maidenhead,latitude,longitude,lasttime) = ('" << maidenhead << "'," << latitude << "," << longitude << ",strftime('%s','now')) WHERE callsign='" << callsign << "';"; sql << "UPDATE LHEARD SET maidenhead = '" << maidenhead << "', latitude = " << latitude << ", longitude = " << longitude << ",lasttime = strftime('%s','now')) WHERE callsign='" << callsign << "';";
char *eMsg; char *eMsg;
if (SQLITE_OK != sqlite3_exec(db, sql.str().c_str(), NULL, 0, &eMsg)) if (SQLITE_OK != sqlite3_exec(db, sql.str().c_str(), NULL, 0, &eMsg))
@ -222,14 +242,13 @@ bool CQnetDB::DeleteLS(const char *address)
{ {
if (NULL == db) if (NULL == db)
return false; return false;
std::string sql("DELETE FROM LINKSTATUS WHERE ip_address=='"); std::stringstream sql;
sql.append(address); sql << "DELETE FROM LINKSTATUS WHERE ip_address=='" << address << "';";
sql.append("';");
char *eMsg; char *eMsg;
if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) if (SQLITE_OK != sqlite3_exec(db, sql.str().c_str(), NULL, 0, &eMsg))
{ {
fprintf(stderr, "CQnetDB::DeleteLS [%s] error: %s\n", sql.c_str(), eMsg); fprintf(stderr, "CQnetDB::DeleteLS [%s] error: %s\n", sql.str().c_str(), eMsg);
sqlite3_free(eMsg); sqlite3_free(eMsg);
return true; return true;
} }
@ -241,15 +260,14 @@ bool CQnetDB::FindLS(const char mod, std::list<CLink> &linklist)
{ {
if (NULL == db) if (NULL == db)
return false; return false;
std::string sql("SELECT ip_address,to_callsign,to_mod,linked_time FROM LINKSTATUS WHERE from_mod=='"); std::stringstream sql;
sql.append(1, mod); sql << "SELECT ip_address,to_callsign,to_mod,linked_time FROM LINKSTATUS WHERE from_mod=='" << mod << "';";
sql.append("';");
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
int rval = sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, 0); int rval = sqlite3_prepare_v2(db, sql.str().c_str(), -1, &stmt, 0);
if (SQLITE_OK != rval) if (SQLITE_OK != rval)
{ {
fprintf(stderr, "CQnetDB::FindLS [%s] error\n", sql.c_str()); fprintf(stderr, "CQnetDB::FindLS [%s] error\n", sql.str().c_str());
return true; return true;
} }
@ -276,12 +294,11 @@ bool CQnetDB::FindGW(const char *name, std::string &address, unsigned short &por
return false; return false;
std::string n(name); std::string n(name);
n.resize(6, ' '); n.resize(6, ' ');
std::string sql("SELECT address,port FROM GATEWAYS WHERE name=='"); std::stringstream sql;
sql.append(n); sql << "SELECT address, port FROM GATEWAYS WHERE name=='" << n << "';";
sql.append("';");
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
int rval = sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, 0); int rval = sqlite3_prepare_v2(db, sql.str().c_str(), -1, &stmt, 0);
if (SQLITE_OK != rval) if (SQLITE_OK != rval)
{ {
fprintf(stderr, "CQnetDB::FindGW error: %d\n", rval); fprintf(stderr, "CQnetDB::FindGW error: %d\n", rval);
@ -309,12 +326,11 @@ bool CQnetDB::FindGW(const char *name)
return false; return false;
std::string n(name); std::string n(name);
n.resize(6, ' '); n.resize(6, ' ');
std::string sql("SELECT address,port FROM GATEWAYS WHERE name=='"); std::stringstream sql;
sql.append(n); sql << "SELECT address,port FROM GATEWAYS WHERE name=='" << n << "';";
sql.append("';");
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
int rval = sqlite3_prepare_v2(db, sql.c_str(), -1, &stmt, 0); int rval = sqlite3_prepare_v2(db, sql.str().c_str(), -1, &stmt, 0);
if (SQLITE_OK != rval) if (SQLITE_OK != rval)
{ {
fprintf(stderr, "CQnetDB::FindGW error: %d\n", rval); fprintf(stderr, "CQnetDB::FindGW error: %d\n", rval);

Loading…
Cancel
Save

Powered by TurnKey Linux.