parent
20dae86206
commit
c58ada4eae
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
/*
|
||||
* 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 <stdio.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
class CQnetDB {
|
||||
public:
|
||||
CQnetDB::CQnetDB() : db(NULL) {}
|
||||
CQnetDB::~CQnetDB() { if (db) sqlite3_close(db); }
|
||||
bool CQnetDB::Open(const char *name, const bool disable = false);
|
||||
bool CQnetDB::Update(const char *callsign, const char *urcall, const char *source);
|
||||
|
||||
private:
|
||||
sqlite3 *db;
|
||||
};
|
||||
Loading…
Reference in new issue