31#include "model/base_platform.h"
33#include "model/navutil_base.h"
36#include "wx/filename.h"
37#include "model/comm_appmsg_bus.h"
40extern std::shared_ptr<ObservableListener> ack_listener;
41extern RouteList* pRouteList;
43void ReportError(
const std::string zmsg);
45static bool executeSQL(sqlite3* db,
const char* sql) {
46 char* errMsg =
nullptr;
47 if (sqlite3_exec(db, sql,
nullptr,
nullptr, &errMsg) != SQLITE_OK) {
49 wxString::Format(_(
"navobj database error.") +
" %s", errMsg);
51 auto& noteman = NotificationManager::GetInstance();
52 noteman.AddNotification(NotificationSeverity::kWarning, msg.ToStdString());
59static bool executeSQL(sqlite3* db, wxString& sql) {
60 return executeSQL(db, sql.ToStdString().c_str());
63bool CreateTables(sqlite3* db) {
65 const char* create_tables_sql = R
"(
66 CREATE TABLE IF NOT EXISTS tracks (
67 guid TEXT PRIMARY KEY NOT NULL,
76 created_at DATETIME DEFAULT CURRENT_TIMESTAMP
79 CREATE TABLE IF NOT EXISTS trk_points (
80 track_guid TEXT NOT NULL,
81 latitude REAL NOT NULL,
82 longitude REAL NOT NULL,
83 timestamp TEXT NOT NULL,
85 FOREIGN KEY (track_guid) REFERENCES tracks(guid) ON DELETE CASCADE
89 CREATE TABLE IF NOT EXISTS track_html_links (
90 guid TEXT PRIMARY KEY,
91 track_guid TEXT NOT NULL,
93 html_description TEXT,
95 FOREIGN KEY (track_guid) REFERENCES tracks(guid) ON DELETE CASCADE
99 CREATE TABLE IF NOT EXISTS routes (
100 guid TEXT PRIMARY KEY NOT NULL,
105 planned_departure TEXT,
112 shared_wp_viz INTEGER,
113 created_at DATETIME DEFAULT CURRENT_TIMESTAMP
117 CREATE TABLE IF NOT EXISTS routepoints (
118 guid TEXT PRIMARY KEY NOT NULL,
130 RangeRingsNumber INTEGER,
132 RangeRingsStepUnits INTEGER,
133 RangeRingsVisible INTEGER,
134 RangeRingsColour TEXT,
142 created_at DATETIME DEFAULT CURRENT_TIMESTAMP
145 CREATE TABLE IF NOT EXISTS routepoints_link (
149 PRIMARY KEY (route_guid, point_guid),
150 FOREIGN KEY (route_guid) REFERENCES routes(guid) ON DELETE CASCADE
153 CREATE TABLE IF NOT EXISTS route_html_links (
154 guid TEXT PRIMARY KEY,
155 route_guid TEXT NOT NULL,
157 html_description TEXT,
159 FOREIGN KEY (route_guid) REFERENCES routes(guid) ON DELETE CASCADE
162 CREATE TABLE IF NOT EXISTS routepoint_html_links (
163 guid TEXT PRIMARY KEY,
164 routepoint_guid TEXT NOT NULL,
166 html_description TEXT,
168 FOREIGN KEY (routepoint_guid) REFERENCES routepoints(guid) ON DELETE CASCADE
173 if (!executeSQL(db, create_tables_sql))
return false;
178bool TrackExists(sqlite3* db,
const std::string& track_guid) {
179 const char* sql =
"SELECT 1 FROM tracks WHERE guid = ? LIMIT 1";
183 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
184 sqlite3_bind_text(stmt, 1, track_guid.c_str(), -1, SQLITE_TRANSIENT);
186 if (sqlite3_step(stmt) == SQLITE_ROW) {
190 sqlite3_finalize(stmt);
192 ReportError(
"TrackExists:prepare");
198bool TrackHtmlLinkExists(sqlite3* db,
const std::string& link_guid) {
199 const char* sql =
"SELECT 1 FROM track_html_links WHERE guid = ? LIMIT 1";
203 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
204 sqlite3_bind_text(stmt, 1, link_guid.c_str(), -1, SQLITE_TRANSIENT);
206 if (sqlite3_step(stmt) == SQLITE_ROW) {
210 sqlite3_finalize(stmt);
212 ReportError(
"TrackHtmlLinkExists:prepare");
218bool DeleteAllCommentsForTrack(sqlite3* db,
const std::string& track_guid) {
219 const char* sql =
"DELETE FROM track_html_links WHERE track_guid = ?";
222 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
223 sqlite3_bind_text(stmt, 1, track_guid.c_str(), -1, SQLITE_TRANSIENT);
224 if (sqlite3_step(stmt) != SQLITE_DONE) {
225 ReportError(
"DeleteAllCommentsForTrack:step");
229 sqlite3_finalize(stmt);
231 ReportError(
"DeleteAllCommentsForTrack:prepare");
237bool InsertTrackPoint(sqlite3* db,
const std::string& track_guid,
double lat,
238 double lon,
const std::string& timestamp,
int i_point) {
239 const char* sql = R
"(
240 INSERT INTO trk_points (track_guid, latitude, longitude, timestamp, point_order)
241 VALUES (?, ?, ?, ?, ?)
245 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
246 sqlite3_bind_text(stmt, 1, track_guid.c_str(), -1, SQLITE_TRANSIENT);
247 sqlite3_bind_double(stmt, 2, lat);
248 sqlite3_bind_double(stmt, 3, lon);
249 sqlite3_bind_text(stmt, 4, timestamp.c_str(), -1, SQLITE_TRANSIENT);
250 sqlite3_bind_int(stmt, 5, i_point);
251 if (sqlite3_step(stmt) != SQLITE_DONE) {
252 ReportError(
"InsertTrackPoint:step");
253 sqlite3_finalize(stmt);
256 sqlite3_finalize(stmt);
263bool InsertTrackHTML(sqlite3* db,
const std::string& track_guid,
264 const std::string& link_guid,
const std::string& descrText,
265 const std::string& link,
const std::string& ltype) {
266 const char* sql = R
"(
267 INSERT INTO track_html_links (guid, track_guid, html_link, html_description, html_type)
268 VALUES (?, ?, ?, ?, ?)
272 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
273 sqlite3_bind_text(stmt, 1, link_guid.c_str(), -1, SQLITE_TRANSIENT);
274 sqlite3_bind_text(stmt, 2, track_guid.c_str(), -1, SQLITE_TRANSIENT);
275 sqlite3_bind_text(stmt, 3, link.c_str(), -1, SQLITE_TRANSIENT);
276 sqlite3_bind_text(stmt, 4, descrText.c_str(), -1, SQLITE_TRANSIENT);
277 sqlite3_bind_text(stmt, 5, ltype.c_str(), -1, SQLITE_TRANSIENT);
278 if (sqlite3_step(stmt) != SQLITE_DONE) {
279 ReportError(
"InsertTrackHTML:step");
280 sqlite3_finalize(stmt);
283 sqlite3_finalize(stmt);
292bool DeleteAllCommentsForRoute(sqlite3* db,
const std::string& route_guid) {
293 const char* sql = R
"(
294 DELETE FROM route_html_links WHERE route_guid = ?
297 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
298 sqlite3_bind_text(stmt, 1, route_guid.c_str(), -1, SQLITE_TRANSIENT);
299 if (sqlite3_step(stmt) != SQLITE_DONE) {
300 ReportError(
"DeleteAllCommentsForRoute:step");
301 sqlite3_finalize(stmt);
304 sqlite3_finalize(stmt);
311bool RouteHtmlLinkExists(sqlite3* db,
const std::string& link_guid) {
312 const char* sql =
"SELECT 1 FROM route_html_links WHERE guid = ? LIMIT 1";
316 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
317 sqlite3_bind_text(stmt, 1, link_guid.c_str(), -1, SQLITE_TRANSIENT);
319 if (sqlite3_step(stmt) == SQLITE_ROW) {
323 sqlite3_finalize(stmt);
330bool RoutePointHtmlLinkExists(sqlite3* db,
const std::string& link_guid) {
332 "SELECT 1 FROM routepoint_html_links WHERE guid = ? LIMIT 1";
336 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
337 sqlite3_bind_text(stmt, 1, link_guid.c_str(), -1, SQLITE_TRANSIENT);
339 if (sqlite3_step(stmt) == SQLITE_ROW) {
343 sqlite3_finalize(stmt);
350bool RouteExistsDB(sqlite3* db,
const std::string& route_guid) {
351 const char* sql =
"SELECT 1 FROM routes WHERE guid = ? LIMIT 1";
355 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
356 sqlite3_bind_text(stmt, 1, route_guid.c_str(), -1, SQLITE_TRANSIENT);
358 if (sqlite3_step(stmt) == SQLITE_ROW) {
362 sqlite3_finalize(stmt);
369bool InsertRouteHTML(sqlite3* db,
const std::string& route_guid,
370 const std::string& link_guid,
const std::string& descrText,
371 const std::string& link,
const std::string& ltype) {
372 const char* sql = R
"(
373 INSERT INTO route_html_links (guid, route_guid, html_link, html_description, html_type)
374 VALUES (?, ?, ?, ?, ?)
378 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
379 sqlite3_bind_text(stmt, 1, link_guid.c_str(), -1, SQLITE_TRANSIENT);
380 sqlite3_bind_text(stmt, 2, route_guid.c_str(), -1, SQLITE_TRANSIENT);
381 sqlite3_bind_text(stmt, 3, link.c_str(), -1, SQLITE_TRANSIENT);
382 sqlite3_bind_text(stmt, 4, descrText.c_str(), -1, SQLITE_TRANSIENT);
383 sqlite3_bind_text(stmt, 5, ltype.c_str(), -1, SQLITE_TRANSIENT);
384 if (sqlite3_step(stmt) != SQLITE_DONE) {
385 ReportError(
"InsertRouteHTML:step");
386 sqlite3_finalize(stmt);
389 sqlite3_finalize(stmt);
396bool RoutePointExists(sqlite3* db,
const std::string& routepoint_guid) {
397 const char* sql =
"SELECT 1 FROM routepoints WHERE guid = ? LIMIT 1";
401 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
402 sqlite3_bind_text(stmt, 1, routepoint_guid.c_str(), -1, SQLITE_TRANSIENT);
404 if (sqlite3_step(stmt) == SQLITE_ROW) {
408 sqlite3_finalize(stmt);
415bool InsertRoutePointHTML(sqlite3* db,
const std::string& point_guid,
416 const std::string& link_guid,
417 const std::string& descrText,
const std::string& link,
418 const std::string& ltype) {
419 const char* sql = R
"(
420 INSERT INTO routepoint_html_links (guid, routepoint_guid, html_link, html_description, html_type)
421 VALUES (?, ?, ?, ?, ?)
425 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
426 sqlite3_bind_text(stmt, 1, link_guid.c_str(), -1, SQLITE_TRANSIENT);
427 sqlite3_bind_text(stmt, 2, point_guid.c_str(), -1, SQLITE_TRANSIENT);
428 sqlite3_bind_text(stmt, 3, link.c_str(), -1, SQLITE_TRANSIENT);
429 sqlite3_bind_text(stmt, 4, descrText.c_str(), -1, SQLITE_TRANSIENT);
430 sqlite3_bind_text(stmt, 5, ltype.c_str(), -1, SQLITE_TRANSIENT);
431 if (sqlite3_step(stmt) != SQLITE_DONE) {
432 ReportError(
"InsertRoutePointHTML:step");
433 sqlite3_finalize(stmt);
436 sqlite3_finalize(stmt);
442bool DeleteAllCommentsForRoutePoint(sqlite3* db,
443 const std::string& routepoint_guid) {
445 "DELETE FROM routepoint_html_links WHERE routepoint_guid = ?";
448 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
449 sqlite3_bind_text(stmt, 1, routepoint_guid.c_str(), -1, SQLITE_TRANSIENT);
450 if (sqlite3_step(stmt) != SQLITE_DONE) {
451 ReportError(
"DeleteAllCommentsForRoutepoint:step");
455 sqlite3_finalize(stmt);
457 ReportError(
"DeleteAllCommentsForRoutepoint:prepare");
463bool InsertRoutePointDB(sqlite3* db,
RoutePoint* point) {
464 const char* sql = R
"(
465 INSERT or REPLACE INTO routepoints(guid)
470 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
471 sqlite3_bind_text(stmt, 1, point->
m_GUID.ToStdString().c_str(), -1,
473 if (sqlite3_step(stmt) != SQLITE_DONE) {
474 ReportError(
"InsertRoutePointDB:step");
475 sqlite3_finalize(stmt);
478 sqlite3_finalize(stmt);
487 const char* sql = R
"(
488 INSERT or IGNORE INTO routepoints_link (route_guid, point_guid, point_order)
494 if (sqlite3_prepare_v2(db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
495 sqlite3_bind_text(stmt, 1, route->
m_GUID.ToStdString().c_str(), -1,
497 sqlite3_bind_text(stmt, 2, point->
m_GUID.ToStdString().c_str(), -1,
499 sqlite3_bind_int(stmt, 3, point_order);
500 if (sqlite3_step(stmt) != SQLITE_DONE) {
501 ReportError(
"InsertTrackPointLink:step");
502 sqlite3_finalize(stmt);
505 sqlite3_finalize(stmt);
512void DeleteOrphanedRoutepoint(sqlite3* db) {
513 const char* sql = R
"(
514 DELETE FROM routepoints
515 WHERE guid NOT IN (SELECT point_guid FROM routepoints_link)
517 char* errMsg =
nullptr;
519 if (sqlite3_exec(db, sql,
nullptr,
nullptr, &errMsg) != SQLITE_OK) {
524void errorLogCallback(
void* pArg,
int iErrCode,
const char* zMsg) {
526 wxString::Format(_(
"navobj database error.") +
" %d: %s", iErrCode, zMsg);
528 auto& noteman = NotificationManager::GetInstance();
529 noteman.AddNotification(NotificationSeverity::kWarning, msg.ToStdString());
532void ReportError(
const std::string zmsg) {
534 wxString::Format(_(
"navobj database error.") +
" %s", zmsg.c_str());
536 auto& noteman = NotificationManager::GetInstance();
537 noteman.AddNotification(NotificationSeverity::kWarning, msg.ToStdString());
545NavObj_dB::NavObj_dB() {
546 m_pImportProgress =
nullptr;
549 int ie = sqlite3_config(SQLITE_CONFIG_LOG, errorLogCallback,
nullptr);
553 wxFileName::GetPathSeparator() +
"navobj.db";
554 if (!wxFileExists(db_filename)) {
557 wxFileName::GetPathSeparator() +
"navobj.xml";
558 if (wxFileExists(xml_filename)) {
559 wxCopyFile(xml_filename, xml_filename +
".backup");
563 wxFileName::GetPathSeparator() +
564 "navobj.xml.import_backup";
565 if (!wxFileExists(deep_backup_filename)) {
566 wxCopyFile(xml_filename, deep_backup_filename);
572 int create_result = sqlite3_open_v2(
573 db_filename.ToStdString().c_str(),
575 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
578 if (create_result != SQLITE_OK) {
579 wxLogMessage(
"Cannot create new navobj.db database file");
588 int close_result = sqlite3_close_v2(m_db);
589 if (close_result != SQLITE_OK) {
595 int m_open_result = sqlite3_open_v2(db_filename.ToStdString().c_str(), &m_db,
596 SQLITE_OPEN_READWRITE, NULL);
597 sqlite3_exec(m_db,
"PRAGMA foreign_keys = ON;",
nullptr,
nullptr,
nullptr);
601 sqlite3_close_v2(m_db);
603 m_open_result = sqlite3_open_v2(db_filename.ToStdString().c_str(), &m_db,
604 SQLITE_OPEN_READWRITE, NULL);
605 sqlite3_exec(m_db,
"PRAGMA foreign_keys = ON;",
nullptr,
nullptr,
nullptr);
611NavObj_dB::~NavObj_dB() { sqlite3_close_v2(m_db); }
613void NavObj_dB::Close() {
614 sqlite3_close_v2(m_db);
618bool NavObj_dB::ImportLegacyNavobj(wxFrame* frame) {
620 wxFileName::GetPathSeparator() +
"navobj.xml";
622 if (::wxFileExists(navobj_filename)) {
624 CountImportNavObjects();
625 m_pImportProgress =
new wxProgressDialog(_(
"Importing Navobj database"),
"",
626 m_nImportObjects, frame);
627 m_import_progesscount = 0;
629 rv = ImportLegacyPoints();
630 rv |= ImportLegacyRoutes();
631 rv |= ImportLegacyTracks();
633 m_pImportProgress->Destroy();
637 if (::wxFileExists(navobj_filename)) ::wxRemoveFile(navobj_filename);
642void NavObj_dB::CountImportNavObjects() {
643 m_nImportObjects = 0;
650 wxFileName::GetPathSeparator() +
"navobj.xml";
652 if (::wxFileExists(navobj_filename) &&
653 input_set->load_file(navobj_filename.ToStdString().c_str()).status ==
654 pugi::xml_parse_status::status_ok) {
655 input_set->LoadAllGPXPointObjects();
656 auto pointlist = pWayPointMan->GetWaypointList();
657 wxRoutePointListNode* prpnode = pointlist->GetFirst();
664 prpnode = prpnode->GetNext();
667 input_set->LoadAllGPXRouteObjects();
668 for (wxRouteListNode* node = pRouteList->GetFirst(); node;
669 node = node->GetNext()) {
670 Route* route_import = node->GetData();
673 m_nImportObjects += route_import->GetnPoints();
676 input_set->LoadAllGPXTrackObjects();
677 m_nImportObjects += g_TrackList.size();
678 m_nimportTracks = g_TrackList.size();
680 for (
Track* track_import : g_TrackList) {
681 m_nImportObjects += track_import->GetnPoints();
687bool NavObj_dB::ImportLegacyTracks() {
688 std::vector<Track*> tracks_added;
691 for (
Track* track_import : g_TrackList) {
692 if (InsertTrack(track_import)) {
693 tracks_added.push_back(track_import);
696 m_import_progesscount += track_import->GetnPoints() + 1;
697 wxString msg = wxString::Format(
"Tracks %d/%d", ntrack, m_nimportTracks);
698 m_pImportProgress->Update(m_import_progesscount, msg);
699 m_pImportProgress->Show();
703 for (
Track* ptrack : tracks_added) {
704 if (ptrack->m_bIsInLayer)
continue;
705 g_pRouteMan->DeleteTrack(ptrack);
711bool NavObj_dB::ImportLegacyRoutes() {
712 std::vector<Route*> routes_added;
715 for (wxRouteListNode* node = pRouteList->GetFirst(); node;
716 node = node->GetNext()) {
717 Route* route_import = node->GetData();
718 if (InsertRoute(route_import)) {
719 routes_added.push_back(route_import);
722 m_import_progesscount += route_import->GetnPoints() + 1;
723 wxString msg = wxString::Format(
"Routes %d/%d", nroute, m_nimportRoutes);
724 m_pImportProgress->Update(m_import_progesscount, msg);
725 m_pImportProgress->Show();
729 for (
Route* route : routes_added) {
735 pWayPointMan->DeleteAllWaypoints(
true);
740bool NavObj_dB::ImportLegacyPoints() {
741 std::vector<RoutePoint*> points_added;
745 if (m_nimportPoints > 1000) nmod = 10;
746 if (m_nimportPoints > 10000) nmod = 100;
748 auto pointlist = pWayPointMan->GetWaypointList();
749 wxRoutePointListNode* prpnode = pointlist->GetFirst();
753 if (InsertRoutePointDB(m_db, point)) {
754 points_added.push_back(point);
757 UpdateDBRoutePointAttributes(point);
758 m_import_progesscount += 1;
759 if ((npoint % nmod) == 0) {
761 wxString::Format(
"Points %d/%d", npoint, m_nimportPoints);
762 m_pImportProgress->Update(m_import_progesscount, msg);
763 m_pImportProgress->Show();
767 prpnode = prpnode->GetNext();
779void NavObj_dB::LoadNavObjects() {
785bool NavObj_dB::InsertTrack(
Track* track) {
786 if (TrackExists(m_db, track->m_GUID.ToStdString()))
return false;
790 sqlite3_exec(m_db,
"BEGIN TRANSACTION", 0, 0, &errMsg);
793 wxString sql = wxString::Format(
"INSERT INTO tracks (guid) VALUES ('%s')",
794 track->m_GUID.ToStdString().c_str());
795 if (!executeSQL(m_db, sql)) {
796 sqlite3_exec(m_db,
"COMMIT", 0, 0, &errMsg);
800 UpdateDBTrackAttributes(track);
803 for (
int i = 0; i < track->GetnPoints(); i++) {
804 auto point = track->GetPoint(i);
806 InsertTrackPoint(m_db, track->m_GUID.ToStdString(), point->m_lat,
807 point->m_lon, point->GetTimeString(), i);
811 int NbrOfLinks = track->m_TrackHyperlinkList->GetCount();
812 if (NbrOfLinks > 0) {
813 wxHyperlinkListNode* linknode = track->m_TrackHyperlinkList->GetFirst();
817 if (!TrackHtmlLinkExists(m_db, link->GUID)) {
818 InsertTrackHTML(m_db, track->m_GUID.ToStdString(), link->GUID,
819 link->DescrText.ToStdString(), link->Link.ToStdString(),
820 link->LType.ToStdString());
822 linknode = linknode->GetNext();
825 sqlite3_exec(m_db,
"COMMIT", 0, 0, &errMsg);
827 if (errMsg) rv =
false;
832bool NavObj_dB::UpdateDBTrackAttributes(
Track* track) {
846 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
847 sqlite3_bind_text(stmt, 1, track->GetName().ToStdString().c_str(), -1,
849 sqlite3_bind_text(stmt, 2, track->m_TrackDescription.ToStdString().c_str(),
850 -1, SQLITE_TRANSIENT);
851 sqlite3_bind_int(stmt, 3, track->m_bVisible);
852 sqlite3_bind_text(stmt, 4, track->m_TrackStartString.ToStdString().c_str(),
853 -1, SQLITE_TRANSIENT);
854 sqlite3_bind_text(stmt, 5, track->m_TrackEndString.ToStdString().c_str(),
855 -1, SQLITE_TRANSIENT);
856 sqlite3_bind_int(stmt, 6, track->m_width);
857 sqlite3_bind_int(stmt, 7,
858 (
int)(track->m_style));
859 sqlite3_bind_text(stmt, 8, track->m_Colour.ToStdString().c_str(), -1,
861 sqlite3_bind_text(stmt, 9, track->m_GUID.c_str(), track->m_GUID.size(),
867 if (sqlite3_step(stmt) != SQLITE_DONE) {
868 ReportError(
"UpdateDBTrackAttributesA:step");
869 sqlite3_finalize(stmt);
873 sqlite3_finalize(stmt);
878 DeleteAllCommentsForTrack(m_db, track->m_GUID.ToStdString());
881 int NbrOfLinks = track->m_TrackHyperlinkList->GetCount();
882 if (NbrOfLinks > 0) {
883 wxHyperlinkListNode* linknode = track->m_TrackHyperlinkList->GetFirst();
887 if (!TrackHtmlLinkExists(m_db, link->GUID)) {
888 InsertTrackHTML(m_db, track->m_GUID.ToStdString(), link->GUID,
889 link->DescrText.ToStdString(), link->Link.ToStdString(),
890 link->LType.ToStdString());
893 "UPDATE track_html_links SET "
895 "html_description = ?, "
899 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
900 sqlite3_bind_text(stmt, 3, link->Link.ToStdString().c_str(), -1,
902 sqlite3_bind_text(stmt, 4, link->DescrText.ToStdString().c_str(), -1,
904 sqlite3_bind_text(stmt, 5, link->LType.ToStdString().c_str(), -1,
907 if (sqlite3_step(stmt) != SQLITE_DONE) {
908 ReportError(
"UpdateDBTRackAttributesB:step");
909 sqlite3_finalize(stmt);
913 sqlite3_finalize(stmt);
916 linknode = linknode->GetNext();
925 if (!TrackExists(m_db, track->m_GUID.ToStdString()))
return false;
928 int this_point_index = track->GetnPoints();
931 if (!InsertTrackPoint(m_db, track->m_GUID.ToStdString(), point->m_lat,
932 point->m_lon, point->GetTimeString(),
933 this_point_index - 1))
939bool NavObj_dB::LoadAllTracks() {
940 const char* sql = R
"(
942 description, visibility, start_string, end_string,
946 ORDER BY created_at ASC
950 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) != SQLITE_OK) {
954 while (sqlite3_step(stmt) == SQLITE_ROW) {
956 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 0));
958 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 1));
959 std::string description =
960 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 2));
961 int visibility = sqlite3_column_int(stmt, 3);
962 std::string start_string =
963 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 4));
964 std::string end_string =
965 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 5));
966 int width = sqlite3_column_int(stmt, 6);
967 int style = sqlite3_column_int(stmt, 7);
969 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 8));
970 std::string created =
971 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 9));
973 Track* new_trk = NULL;
976 const char* sql = R
"(
977 SELECT latitude, longitude, timestamp, point_order
980 ORDER BY point_order ASC
984 if (sqlite3_prepare_v2(m_db, sql, -1, &stmtp,
nullptr) != SQLITE_OK) {
988 sqlite3_bind_text(stmtp, 1, guid.c_str(), -1, SQLITE_TRANSIENT);
991 while (sqlite3_step(stmtp) == SQLITE_ROW) {
994 new_trk->m_GUID = guid;
997 new_trk->SetVisible(visibility == 1);
998 new_trk->SetName(name.c_str());
999 new_trk->m_TrackStartString = start_string.c_str();
1000 new_trk->m_TrackEndString = end_string.c_str();
1001 new_trk->m_width = width;
1002 new_trk->m_style = (wxPenStyle)style;
1003 new_trk->m_Colour = color;
1008 double latitude = sqlite3_column_double(stmtp, 0);
1009 double longitude = sqlite3_column_double(stmtp, 1);
1010 std::string timestamp =
1011 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, 2));
1012 int point_order = sqlite3_column_int(stmtp, 3);
1014 auto point =
new TrackPoint(latitude, longitude, timestamp);
1016 point->m_GPXTrkSegNo = GPXSeg;
1017 new_trk->AddPoint(point);
1019 sqlite3_finalize(stmtp);
1022 new_trk->SetCurrentTrackSeg(GPXSeg);
1025 const char* sqlh = R
"(
1026 SELECT guid, html_link, html_description, html_type
1027 FROM track_html_links
1028 WHERE track_guid = ?
1029 ORDER BY html_type ASC
1034 if (sqlite3_prepare_v2(m_db, sqlh, -1, &stmt,
nullptr) == SQLITE_OK) {
1035 sqlite3_bind_text(stmt, 1, new_trk->m_GUID.ToStdString().c_str(), -1,
1038 while (sqlite3_step(stmt) == SQLITE_ROW) {
1039 std::string link_guid =
1040 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 0));
1041 std::string link_link =
1042 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 1));
1043 std::string link_description =
1044 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 2));
1045 std::string link_type =
1046 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 3));
1049 h->DescrText = link_description;
1050 h->Link = link_link;
1051 h->LType = link_type;
1053 new_trk->m_TrackHyperlinkList->Append(h);
1057 sqlite3_finalize(stmt);
1064 g_TrackList.push_back(new_trk);
1066 pSelect->AddAllSelectableTrackSegments(new_trk);
1072bool NavObj_dB::DeleteTrack(
Track* track) {
1073 if (!track)
return false;
1074 std::string track_guid = track->m_GUID.ToStdString();
1075 const char* sql =
"DELETE FROM tracks WHERE guid = ?";
1078 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
1079 sqlite3_bind_text(stmt, 1, track_guid.c_str(), -1, SQLITE_TRANSIENT);
1080 if (sqlite3_step(stmt) != SQLITE_DONE) {
1081 ReportError(
"DeleteTrack:step");
1082 sqlite3_finalize(stmt);
1086 sqlite3_finalize(stmt);
1095bool NavObj_dB::InsertRoute(
Route* route) {
1099 if (!RouteExistsDB(m_db, route->
m_GUID.ToStdString())) {
1101 wxString sql = wxString::Format(
"INSERT INTO routes (guid) VALUES ('%s')",
1102 route->
m_GUID.ToStdString().c_str());
1103 if (!executeSQL(m_db, sql)) {
1106 UpdateDBRouteAttributes(route);
1109 sqlite3_exec(m_db,
"BEGIN TRANSACTION", 0, 0, &errMsg);
1111 ReportError(
"InsertRoute:transaction");
1116 for (
int i = 0; i < route->GetnPoints(); i++) {
1117 auto point = route->GetPoint(i + 1);
1120 if (!RoutePointExists(m_db, point->m_GUID.ToStdString())) {
1121 InsertRoutePointDB(m_db, point);
1122 UpdateDBRoutePointAttributes(point);
1128 for (
int i = 0; i < route->GetnPoints(); i++) {
1129 auto point = route->GetPoint(i + 1);
1132 InsertRoutePointLink(m_db, route, point, i + 1);
1138 if (NbrOfLinks > 0) {
1143 if (!RouteHtmlLinkExists(m_db, link->GUID)) {
1144 InsertRouteHTML(m_db, route->
m_GUID.ToStdString(), link->GUID,
1145 link->DescrText.ToStdString(), link->Link.ToStdString(),
1146 link->LType.ToStdString());
1148 linknode = linknode->GetNext();
1152 sqlite3_exec(m_db,
"COMMIT", 0, 0, &errMsg);
1155 ReportError(
"InsertRoute:commit");
1161bool NavObj_dB::UpdateRoute(
Route* route) {
1165 if (!RouteExistsDB(m_db, route->
m_GUID.ToStdString()))
return false;
1167 UpdateDBRouteAttributes(route);
1170 for (
int i = 0; i < route->GetnPoints(); i++) {
1171 auto point = route->GetPoint(i + 1);
1174 if (!RoutePointExists(m_db, point->m_GUID.ToStdString())) {
1175 InsertRoutePointDB(m_db, point);
1177 UpdateDBRoutePointAttributes(point);
1182 const char* sql =
"DELETE FROM routepoints_link WHERE route_guid = ?";
1184 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
1185 sqlite3_bind_text(stmt, 1, route->
m_GUID.ToStdString().c_str(), -1,
1190 if (sqlite3_step(stmt) != SQLITE_DONE) {
1191 ReportError(
"UpdateRoute:step");
1192 sqlite3_finalize(stmt);
1196 sqlite3_finalize(stmt);
1198 for (
int i = 0; i < route->GetnPoints(); i++) {
1199 auto point = route->GetPoint(i + 1);
1201 InsertRoutePointLink(m_db, route, point, i + 1);
1207 if (NbrOfLinks > 0) {
1212 if (!RouteHtmlLinkExists(m_db, link->GUID)) {
1213 InsertRouteHTML(m_db, route->
m_GUID.ToStdString(), link->GUID,
1214 link->DescrText.ToStdString(), link->Link.ToStdString(),
1215 link->LType.ToStdString());
1217 linknode = linknode->GetNext();
1222 if (errMsg) rv =
false;
1227bool NavObj_dB::UpdateRouteViz(
Route* route) {
1230 if (!RouteExistsDB(m_db, route->
m_GUID.ToStdString()))
return false;
1232 UpdateDBRouteAttributes(route);
1234 for (
int i = 0; i < route->GetnPoints(); i++) {
1235 auto point = route->GetPoint(i + 1);
1238 UpdateDBRoutePointViz(point);
1242 if (errMsg) rv =
false;
1247bool NavObj_dB::UpdateDBRouteAttributes(
Route* route) {
1249 "UPDATE routes SET "
1252 "start_string = ?, "
1255 "shared_wp_viz = ?, "
1256 "planned_departure = ?, "
1265 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
1266 sqlite3_bind_text(stmt, 1, route->GetName().ToStdString().c_str(), -1,
1269 -1, SQLITE_TRANSIENT);
1271 -1, SQLITE_TRANSIENT);
1273 -1, SQLITE_TRANSIENT);
1274 sqlite3_bind_int(stmt, 5, route->IsVisible());
1275 sqlite3_bind_int(stmt, 6, route->GetSharedWPViz());
1279 -1, SQLITE_TRANSIENT);
1280 sqlite3_bind_int(stmt, 10, route->
m_width);
1281 sqlite3_bind_int(stmt, 11,
1283 sqlite3_bind_text(stmt, 12, route->
m_Colour.ToStdString().c_str(), -1,
1285 sqlite3_bind_text(stmt, 13, route->
m_GUID.c_str(), route->
m_GUID.size(),
1291 if (sqlite3_step(stmt) != SQLITE_DONE) {
1292 ReportError(
"UpdateDBRouteAttributesA:step");
1293 sqlite3_finalize(stmt);
1297 sqlite3_finalize(stmt);
1302 DeleteAllCommentsForRoute(m_db, route->
m_GUID.ToStdString());
1306 if (NbrOfLinks > 0) {
1311 if (!RouteHtmlLinkExists(m_db, link->GUID)) {
1312 InsertRouteHTML(m_db, route->
m_GUID.ToStdString(), link->GUID,
1313 link->DescrText.ToStdString(), link->Link.ToStdString(),
1314 link->LType.ToStdString());
1317 "UPDATE route_html_links SET "
1319 "html_description = ?, "
1323 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
1324 sqlite3_bind_text(stmt, 3, link->Link.ToStdString().c_str(), -1,
1326 sqlite3_bind_text(stmt, 4, link->DescrText.ToStdString().c_str(), -1,
1328 sqlite3_bind_text(stmt, 5, link->LType.ToStdString().c_str(), -1,
1331 if (sqlite3_step(stmt) != SQLITE_DONE) {
1334 if (sqlite3_step(stmt) != SQLITE_DONE) {
1335 ReportError(
"UpdateDBRouteAttributesB:step");
1336 sqlite3_finalize(stmt);
1340 sqlite3_finalize(stmt);
1343 linknode = linknode->GetNext();
1349bool NavObj_dB::UpdateDBRoutePointAttributes(
RoutePoint* point) {
1351 "UPDATE routepoints SET "
1362 "ArrivalRadius = ?, "
1363 "RangeRingsNumber = ?, "
1364 "RangeRingsStep = ?, "
1365 "RangeRingsStepUnits = ?, "
1366 "RangeRingsVisible = ?, "
1367 "RangeRingsColour = ?, "
1378 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
1379 sqlite3_bind_double(stmt, 1, point->GetLatitude());
1380 sqlite3_bind_double(stmt, 2, point->GetLongitude());
1381 sqlite3_bind_text(stmt, 3, point->GetIconName().ToStdString().c_str(), -1,
1383 sqlite3_bind_text(stmt, 4, point->GetName().ToStdString().c_str(), -1,
1385 sqlite3_bind_text(stmt, 5, point->GetDescription().ToStdString().c_str(),
1386 -1, SQLITE_TRANSIENT);
1387 sqlite3_bind_text(stmt, 6, point->
m_TideStation.ToStdString().c_str(), -1,
1391 if (point->
GetETD().IsValid()) etd = point->
GetETD().GetTicks();
1392 sqlite3_bind_int(stmt, 8, etd);
1393 sqlite3_bind_text(stmt, 9,
"type", -1, SQLITE_TRANSIENT);
1394 sqlite3_bind_text(stmt, 10, point->
m_timestring.ToStdString().c_str(), -1,
1407 -1, SQLITE_TRANSIENT);
1409 sqlite3_bind_int(stmt, 17, point->GetScaMin());
1410 sqlite3_bind_int(stmt, 18, point->GetScaMax());
1411 sqlite3_bind_int(stmt, 19, point->GetUseSca());
1413 sqlite3_bind_int(stmt, 20, point->IsVisible());
1414 sqlite3_bind_int(stmt, 21, point->IsNameShown());
1415 sqlite3_bind_int(stmt, 22, point->IsShared());
1417 sqlite3_bind_int(stmt, 23, iso);
1419 sqlite3_bind_text(stmt, 24, point->
m_GUID.ToStdString().c_str(), -1,
1426 if (sqlite3_step(stmt) != SQLITE_DONE) {
1427 ReportError(
"UpdateDBRoutePointAttributesA:step");
1428 sqlite3_finalize(stmt);
1432 sqlite3_finalize(stmt);
1437 DeleteAllCommentsForRoutePoint(m_db, point->
m_GUID.ToStdString());
1441 if (NbrOfLinks > 0) {
1446 if (!RoutePointHtmlLinkExists(m_db, link->GUID)) {
1447 InsertRoutePointHTML(m_db, point->
m_GUID.ToStdString(), link->GUID,
1448 link->DescrText.ToStdString(),
1449 link->Link.ToStdString(),
1450 link->LType.ToStdString());
1453 "UPDATE routepoint_html_links SET "
1455 "html_description = ?, "
1459 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
1460 sqlite3_bind_text(stmt, 3, link->Link.ToStdString().c_str(), -1,
1462 sqlite3_bind_text(stmt, 4, link->DescrText.ToStdString().c_str(), -1,
1464 sqlite3_bind_text(stmt, 5, link->LType.ToStdString().c_str(), -1,
1467 if (sqlite3_step(stmt) != SQLITE_DONE) {
1470 if (sqlite3_step(stmt) != SQLITE_DONE) {
1471 ReportError(
"UpdateDBRoutePointAttributesB:step-h");
1472 sqlite3_finalize(stmt);
1476 sqlite3_finalize(stmt);
1479 linknode = linknode->GetNext();
1486bool NavObj_dB::UpdateDBRoutePointViz(
RoutePoint* point) {
1488 "UPDATE routepoints SET "
1493 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
1494 sqlite3_bind_int(stmt, 1, point->IsVisible());
1495 sqlite3_bind_text(stmt, 2, point->
m_GUID.ToStdString().c_str(), -1,
1502 if (sqlite3_step(stmt) != SQLITE_DONE) {
1503 ReportError(
"UpdateDBRoutePointVizA:step");
1504 sqlite3_finalize(stmt);
1508 sqlite3_finalize(stmt);
1513bool NavObj_dB::DeleteRoute(
Route* route) {
1514 if (m_importing)
return false;
1515 if (!route)
return false;
1516 std::string route_guid = route->
m_GUID.ToStdString();
1517 const char* sql =
"DELETE FROM routes WHERE guid = ?";
1520 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
1521 sqlite3_bind_text(stmt, 1, route_guid.c_str(), -1, SQLITE_TRANSIENT);
1522 if (sqlite3_step(stmt) != SQLITE_DONE) {
1523 ReportError(
"DeleteRoute:step");
1524 sqlite3_finalize(stmt);
1527 sqlite3_finalize(stmt);
1534bool NavObj_dB::LoadAllRoutes() {
1544 "planned_departure, "
1551 "ORDER BY created_at ASC";
1554 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) != SQLITE_OK) {
1558 int errcode0 = SQLITE_OK;
1559 while ((errcode0 = sqlite3_step(stmt)) == SQLITE_ROW) {
1561 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 0));
1563 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 1));
1564 std::string description =
1565 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 2));
1566 std::string start_string =
1567 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 3));
1568 std::string end_string =
1569 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 4));
1570 int visibility = sqlite3_column_int(stmt, 5);
1571 int sharewp_viz = sqlite3_column_int(stmt, 6);
1572 time_t planned_departure_ticks = sqlite3_column_int(stmt, 7);
1573 double plan_speed = sqlite3_column_double(stmt, 8);
1574 std::string time_format =
1575 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 9));
1577 int width = sqlite3_column_int(stmt, 10);
1578 int style = sqlite3_column_int(stmt, 11);
1580 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 12));
1582 Route* route = NULL;
1585 const char* sql = R
"(
1586 SELECT latitude, longitude, timestamp, point_order
1588 WHERE track_guid = ?
1589 ORDER BY point_order ASC
1605 "p.RangeRingsNumber, "
1606 "p.RangeRingsStep, "
1607 "p.RangeRingsStepUnits, "
1608 "p.RangeRingsVisible, "
1609 "p.RangeRingsColour, "
1617 "FROM routepoints_link tp "
1618 "JOIN routepoints p ON p.guid = tp.point_guid "
1619 "WHERE tp.route_guid = ? "
1620 "ORDER BY tp.point_order ASC";
1622 sqlite3_stmt* stmtp;
1623 if (sqlite3_prepare_v2(m_db, sqlp, -1, &stmtp,
nullptr) != SQLITE_OK) {
1624 ReportError(
"LoadAllRoutes-B:prepare");
1628 sqlite3_bind_text(stmtp, 1, guid.c_str(), -1, SQLITE_TRANSIENT);
1631 int errcode = SQLITE_OK;
1632 while ((errcode = sqlite3_step(stmtp)) == SQLITE_ROW) {
1638 route->SetVisible(visibility == 1);
1643 route->SetVisible(visibility == 1);
1644 route->SetSharedWPViz(sharewp_viz == 1);
1650 route->
m_style = (wxPenStyle)style;
1656 std::string point_guid =
1657 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1658 double latitude = sqlite3_column_double(stmtp, col++);
1659 double longitude = sqlite3_column_double(stmtp, col++);
1660 std::string symbol =
1661 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1663 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1664 std::string description =
1665 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1666 std::string tide_station =
1667 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1668 double plan_speed = sqlite3_column_double(stmtp, col++);
1669 time_t etd_epoch = sqlite3_column_int(stmtp, col++);
1671 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1673 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1674 double arrival_radius = sqlite3_column_double(stmtp, col++);
1676 int range_ring_number = sqlite3_column_int(stmtp, col++);
1677 double range_ring_step = sqlite3_column_double(stmtp, col++);
1678 int range_ring_units = sqlite3_column_int(stmtp, col++);
1679 int range_ring_visible = sqlite3_column_int(stmtp, col++);
1680 std::string range_ring_color =
1681 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1683 int scamin = sqlite3_column_int(stmtp, col++);
1684 int scamax = sqlite3_column_int(stmtp, col++);
1685 int use_scaminmax = sqlite3_column_int(stmtp, col++);
1687 int visibility = sqlite3_column_int(stmtp, col++);
1688 int viz_name = sqlite3_column_int(stmtp, col++);
1689 int shared = sqlite3_column_int(stmtp, col++);
1690 int isolated = sqlite3_column_int(stmtp, col++);
1694 auto containing_route =
1695 g_pRouteMan->FindRouteContainingWaypoint(point_guid);
1697 if (containing_route) {
1698 point = containing_route->GetPoint(point_guid);
1701 new RoutePoint(latitude, longitude, symbol, name, point_guid,
true);
1705 point->SetPlannedSpeed(plan_speed);
1708 etd.Set((time_t)etd_epoch);
1709 if (etd.IsValid()) point->
SetETD(etd);
1716 point->SetShowWaypointRangeRings(range_ring_visible == 1);
1720 point->SetScaMin(scamin);
1721 point->SetScaMax(scamax);
1722 point->SetUseSca(use_scaminmax == 1);
1724 point->SetVisible(visibility == 1);
1725 point->SetNameShown(viz_name == 1);
1726 point->SetShared(shared == 1);
1730 const char* sqlh = R
"(
1731 SELECT guid, html_link, html_description, html_type
1732 FROM routepoint_html_links
1733 WHERE routepoint_guid = ?
1734 ORDER BY html_type ASC
1739 if (sqlite3_prepare_v2(m_db, sqlh, -1, &stmt,
nullptr) == SQLITE_OK) {
1740 sqlite3_bind_text(stmt, 1, point->
m_GUID.ToStdString().c_str(), -1,
1743 while (sqlite3_step(stmt) == SQLITE_ROW) {
1744 std::string link_guid =
1745 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 0));
1746 std::string link_link =
1747 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 1));
1748 std::string link_description =
1749 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 2));
1750 std::string link_type =
1751 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 3));
1754 h->DescrText = link_description;
1755 h->Link = link_link;
1756 h->LType = link_type;
1763 route->AddPoint(point);
1765 sqlite3_finalize(stmtp);
1766 if (errcode != SQLITE_DONE) {
1767 ReportError(
"LoadAllRoutes-A:step");
1774 const char* sqlh = R
"(
1775 SELECT guid, html_link, html_description, html_type
1776 FROM route_html_links
1777 WHERE route_guid = ?
1778 ORDER BY html_type ASC
1783 if (sqlite3_prepare_v2(m_db, sqlh, -1, &stmt,
nullptr) == SQLITE_OK) {
1784 sqlite3_bind_text(stmt, 1, route->
m_GUID.ToStdString().c_str(), -1,
1787 int errcode2 = SQLITE_OK;
1788 while ((errcode2 = sqlite3_step(stmt)) == SQLITE_ROW) {
1789 std::string link_guid =
1790 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 0));
1791 std::string link_link =
1792 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 1));
1793 std::string link_description =
1794 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 2));
1795 std::string link_type =
1796 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 3));
1799 h->DescrText = link_description;
1800 h->Link = link_link;
1801 h->LType = link_type;
1805 if (errcode != SQLITE_DONE) {
1806 ReportError(
"LoadAllRoutes-B:step");
1810 sqlite3_finalize(stmt);
1813 ReportError(
"LoadAllRoutes-B:prepare");
1824 if (errcode0 != SQLITE_DONE) {
1825 ReportError(
"LoadAllRoutes-C:step");
1832bool NavObj_dB::LoadAllPoints() {
1847 "p.RangeRingsNumber, "
1848 "p.RangeRingsStep, "
1849 "p.RangeRingsStepUnits, "
1850 "p.RangeRingsVisible, "
1851 "p.RangeRingsColour, "
1859 "FROM routepoints p ";
1863 sqlite3_stmt* stmtp;
1864 if (sqlite3_prepare_v2(m_db, sqlp, -1, &stmtp,
nullptr) != SQLITE_OK) {
1868 while (sqlite3_step(stmtp) == SQLITE_ROW) {
1871 std::string point_guid =
1872 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1873 double latitude = sqlite3_column_double(stmtp, col++);
1874 double longitude = sqlite3_column_double(stmtp, col++);
1875 std::string symbol =
1876 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1878 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1879 std::string description =
1880 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1881 std::string tide_station =
1882 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1883 double plan_speed = sqlite3_column_double(stmtp, col++);
1884 time_t etd = sqlite3_column_int(stmtp, col++);
1886 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1887 std::string point_time_string =
1888 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1889 double arrival_radius = sqlite3_column_double(stmtp, col++);
1891 int range_ring_number = sqlite3_column_int(stmtp, col++);
1892 double range_ring_step = sqlite3_column_double(stmtp, col++);
1893 int range_ring_units = sqlite3_column_int(stmtp, col++);
1894 int range_ring_visible = sqlite3_column_int(stmtp, col++);
1895 std::string range_ring_color =
1896 reinterpret_cast<const char*
>(sqlite3_column_text(stmtp, col++));
1898 int scamin = sqlite3_column_int(stmtp, col++);
1899 int scamax = sqlite3_column_int(stmtp, col++);
1900 int use_scaminmax = sqlite3_column_int(stmtp, col++);
1902 int visibility = sqlite3_column_int(stmtp, col++);
1903 int viz_name = sqlite3_column_int(stmtp, col++);
1904 int shared = sqlite3_column_int(stmtp, col++);
1905 int isolated = sqlite3_column_int(stmtp, col++);
1909 new RoutePoint(latitude, longitude, symbol, name, point_guid,
false);
1913 point->SetPlannedSpeed(plan_speed);
1919 point->SetShowWaypointRangeRings(range_ring_visible == 1);
1923 point->SetScaMin(scamin);
1924 point->SetScaMax(scamax);
1925 point->SetUseSca(use_scaminmax == 1);
1927 point->SetVisible(visibility == 1);
1928 point->SetNameShown(viz_name == 1);
1929 point->SetShared(shared == 1);
1932 if (point_time_string.size()) {
1933 wxString sdt(point_time_string.c_str());
1939 pSelect->AddSelectableRoutePoint(point->m_lat, point->m_lon, point);
1942 sqlite3_finalize(stmtp);
1946 const char* sqlh = R
"(
1947 SELECT guid, html_link, html_description, html_type
1948 FROM routepoint_html_links
1949 WHERE routepoint_guid = ?
1950 ORDER BY html_type ASC
1955 if (sqlite3_prepare_v2(m_db, sqlh, -1, &stmt,
nullptr) == SQLITE_OK) {
1956 sqlite3_bind_text(stmt, 1, point->
m_GUID.ToStdString().c_str(), -1,
1959 while (sqlite3_step(stmt) == SQLITE_ROW) {
1960 std::string link_guid =
1961 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 0));
1962 std::string link_link =
1963 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 1));
1964 std::string link_description =
1965 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 2));
1966 std::string link_type =
1967 reinterpret_cast<const char*
>(sqlite3_column_text(stmt, 3));
1970 h->DescrText = link_description;
1971 h->Link = link_link;
1972 h->LType = link_type;
1977 sqlite3_finalize(stmt);
1985bool NavObj_dB::InsertRoutePoint(
RoutePoint* point) {
1989 if (!RoutePointExists(m_db, point->
m_GUID.ToStdString())) {
1992 wxString::Format(
"INSERT INTO routepoints (guid) VALUES ('%s')",
1993 point->
m_GUID.ToStdString().c_str());
1994 if (!executeSQL(m_db, sql)) {
1999 UpdateDBRoutePointAttributes(point);
2003 if (NbrOfLinks > 0) {
2008 if (!RoutePointHtmlLinkExists(m_db, link->GUID)) {
2009 InsertRoutePointHTML(m_db, point->
m_GUID.ToStdString(), link->GUID,
2010 link->DescrText.ToStdString(),
2011 link->Link.ToStdString(),
2012 link->LType.ToStdString());
2014 linknode = linknode->GetNext();
2021bool NavObj_dB::DeleteRoutePoint(
RoutePoint* point) {
2022 if (m_importing)
return false;
2023 if (!point)
return false;
2025 std::string point_guid = point->
m_GUID.ToStdString();
2029 const char* sql =
"DELETE FROM routepoints WHERE guid = ?";
2032 if (sqlite3_prepare_v2(m_db, sql, -1, &stmt,
nullptr) == SQLITE_OK) {
2033 sqlite3_bind_text(stmt, 1, point_guid.c_str(), -1, SQLITE_TRANSIENT);
2034 if (sqlite3_step(stmt) != SQLITE_DONE) {
2035 ReportError(
"DeleteRoutePoint:step");
2036 sqlite3_finalize(stmt);
2040 sqlite3_finalize(stmt);
2047bool NavObj_dB::UpdateRoutePoint(
RoutePoint* point) {
2048 if (m_importing)
return false;
2049 if (!RoutePointExists(m_db, point->
m_GUID.ToStdString()))
return false;
2050 UpdateDBRoutePointAttributes(point);
The navobj SQLite container object, a singleton.
Represents a waypoint or mark within the navigation system.
HyperlinkList * m_HyperlinkList
List of hyperlinks associated with this waypoint.
wxColour m_wxcWaypointRangeRingsColour
Color for the range rings display.
wxString m_MarkDescription
Description text for the waypoint.
int m_iWaypointRangeRingsNumber
Number of range rings to display around the waypoint.
wxString m_GUID
Globally Unique Identifier for the waypoint.
wxDateTime GetETD()
Retrieves the Estimated Time of Departure for this waypoint, in UTC.
wxDateTime m_CreateTimeX
Creation timestamp for the waypoint, in UTC.
bool m_bIsolatedMark
Flag indicating if the waypoint is a standalone mark.
wxString m_timestring
String representation of the waypoint creation time.
double GetPlannedSpeed()
Return the planned speed associated with this waypoint.
double m_WaypointArrivalRadius
Arrival radius in nautical miles.
int m_iWaypointRangeRingsStepUnits
Units for the range rings step (0=nm, 1=km).
float m_fWaypointRangeRingsStep
Distance between consecutive range rings.
wxString m_TideStation
Associated tide station identifier.
bool m_bShowWaypointRangeRings
Flag indicating if range rings should be shown around the waypoint.
void SetETD(const wxDateTime &etd)
Sets the Estimated Time of Departure for this waypoint, in UTC.
Represents a navigational route in the navigation system.
double m_PlannedSpeed
Default planned speed for the route in knots.
wxString m_RouteStartString
Name or description of the route's starting point.
wxString m_RouteDescription
Additional descriptive information about the route.
wxString m_Colour
Color name for rendering the route on the chart.
wxString m_RouteEndString
Name or description of the route's ending point.
wxPenStyle m_style
Style of the route line when rendered on the chart.
wxString m_TimeDisplayFormat
Format for displaying times in the UI.
int m_width
Width of the route line in pixels when rendered on the chart.
wxString m_RouteNameString
User-assigned name for the route.
wxString m_GUID
Globally unique identifier for this route.
wxDateTime m_PlannedDeparture
Planned departure time for the route, in UTC.
HyperlinkList * m_HyperlinkList
List of hyperlinks associated with this route.
bool DeleteRoute(Route *pRoute)
Represents a single point in a track.
Represents a track, which is a series of connected track points.
bool AddRoutePoint(RoutePoint *prp)
Add a point to list which owns it.
bool RemoveRoutePoint(RoutePoint *prp)
Remove a routepoint from list if present, deallocate it all cases.
bool exists(const std::string &name)
Class NotificationManager.