You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
QnetGateway/QnetDB.cpp

70 lines
1.9 KiB

/*
* Copyright (C) 2020 by Thomas Early N7TAE
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string>
#include "QnetDB.h"
bool CQnetDB::Open(const char *name, const bool disable)
{
if (disable)
return false;
if (sqlite3_open(name, &db))
return true;
std::string sql = "DROP TABLE IF EXISTS LHEARD; "
"CREATE TABLE LHEARD("
"callsign TEXT PRIMARY KEY, "
"urcall TEXT, "
"source TEXT, "
"lasttime INT NOT NULL"
") WITHOUT ROWID;";
char *eMsg;
if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) {
fprintf(stderr, "CQnetDB::Open error: %s\n", eMsg);
sqlite3_free(eMsg);
return true;
}
return false;
}
bool CQnetDB::Update(const char *callsign, const char *urcall, const char *source)
{
if (NULL == db)
return false;
std::string sql = "REPLACE INTO LHEARD (callsign,urcall,source,lasttime) VALUES (";
sql.append(callsign);
sql.append("\",\"");
sql.append(urcall);
sql.append("\",\"");
sql.append(source);
sql.append("\",");
sql.append("strftime('%s','now'));");
char *eMsg;
if (SQLITE_OK != sqlite3_exec(db, sql.c_str(), NULL, 0, &eMsg)) {
fprintf(stderr, "CQnetDB::Update error: %s\n", eMsg);
sqlite3_free(eMsg);
return true;
}
return false;
}

Powered by TurnKey Linux.