-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.cpp
More file actions
1267 lines (1084 loc) · 44.4 KB
/
database.cpp
File metadata and controls
1267 lines (1084 loc) · 44.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
database.cpp - description
-------------------
begin : sept 2011
copyright : (C) 2011 by Jaime Robles
email : jaime@robles.es
***************************************************************************/
/*****************************************************************************
* This file is part of KLuster. *
* *
* KLuster 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 3 of the License, or *
* (at your option) any later version. *
* *
* KLuster 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 KLuster. If not, see <http://www.gnu.org/licenses/>. *
* *
*****************************************************************************/
#include "database.h"
//#include <qDebug>
DataBase::DataBase(const QString _softVersion){
//qDebug() << "DataBase::DataBase: " << _softVersion << endl;
dbVersion = DBVersionf;
softVersion = _softVersion;
//inMemoryOnly = inmemoryonly;
latestReaded = 0.0;
}
DataBase::~DataBase()
{
//qDebug() << "DataBase::~DataBase" << endl;
}
void DataBase::compress()
{
//qDebug() << "DataBase::compress " << endl;
QSqlDatabase db = QSqlDatabase::database();
if (!db.open()) {
QMessageBox::warning(nullptr, QObject::tr("Database Error"),
db.lastError().text());
}
else
{
db.exec("VACUUM;");
}
}
bool DataBase::createConnection()
{
//qDebug() << "DataBase::createConnection: " << QString::number(dbVersion) << "/" << softVersion << endl;
QString stringQuery;
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
QSqlQuery query;
//db.setDatabaseName(":memory:"); // 2m 07s
db.setDatabaseName("kluster.dat");
//qDebug() << "DataBase::createConnection: 0" << endl;
//rc = sqlite3_open(":memory:", &db);
if (!db.open()) {
QMessageBox::warning(nullptr, QObject::tr("Database Error"),
db.lastError().text());
//qDebug() << "DataBase::createConnection: DB creation ERROR" << endl;
return false;
}
else
{
//qDebug() << "DataBase::createConnection: created?" << endl;
if (isTheDBCreated())
{
//qDebug() << "DataBase::createConnection: DB Exists" << endl;
}
else
{
//qDebug() << "DataBase::createConnection: DB does not exist" << endl;
createDataBase();
stringQuery ="PRAGMA main.page_size = 4096;";
query.exec(stringQuery);
stringQuery ="PRAGMA main.cache_size=10000;";
query.exec(stringQuery);
stringQuery ="PRAGMA main.locking_mode=EXCLUSIVE;";
query.exec(stringQuery);
stringQuery ="PRAGMA main.synchronous=NORMAL;";
query.exec(stringQuery);
stringQuery ="PRAGMA main.journal_mode=WAL;";
query.exec(stringQuery);
stringQuery ="PRAGMA main.cache_size=5000;";
query.exec(stringQuery);
stringQuery ="PRAGMA synchronous=OFF;";
query.exec(stringQuery);
stringQuery ="PRAGMA main.temp_store = MEMORY;";
query.exec(stringQuery);
//stringQuery="PRAGMA auto_vacuum = FULL;";
//query.exec(stringQuery);
stringQuery ="PRAGMA case_sensitive_like=OFF;";
query.exec(stringQuery);
}
createBandModeMaps();
}
return unMarkAllQSO();
}
bool DataBase::isTheDBCreated()
{
//qDebug() << "DataBase::isTheDBCreated" << endl;
QSqlQuery query;
int _num = 0;
QString stringQuery ("SELECT count(id) FROM softwarecontrol");
query.exec(stringQuery);
query.next();
if (query.isValid())
{
//qDebug() << "DataBase::isTheDBCreated - valid" << endl;
_num = (query.value(0)).toInt();
if (_num > 0)
{
//qDebug() << "DataBase::isTheDBCreated - DB Exists" << endl;
return true;
}
else
{
//qDebug() << "DataBase::isTheDBCreated - DB does not Exist" << endl;
return false;
}
}
else
{
//qDebug() << "DataBase::isTheDBCreated - not valid" << endl;
return false;
}
return false;
}
bool DataBase::createTableLog()
{ //Creates log=0 or selectedlog=1
//QString logToCreate = "log";
QSqlQuery query;
QString stringQuery = "CREATE TABLE log" ;
stringQuery = stringQuery + QString(" (id INTEGER PRIMARY KEY AUTOINCREMENT, "
"qso_date VARCHAR(10) NOT NULL, "
"time_on VARCHAR(8) NOT NULL, "
"call VARCHAR(40) NOT NULL, "
"rst_sent VARCHAR, "
"rst_rcvd VARCHAR, "
"bandid INTEGER NOT NULL, "
"modeid INTEGER NOT NULL, "
"srx VARCHAR(10), "
"stx VARCHAR(10), "
"points INTEGER,"
"multiplier INTEGER,"
"cqz INTEGER,"
"ituz INTEGER,"
"dxcc INTEGER,"
"address VARCHAR, "
"age INTEGER, "
"cnty VARCHAR, "
"comment VARCHAR, "
"a_index INTEGER, "
"ant_az INTEGER, "
"ant_el INTEGER, "
"ant_path INTEGER, "
"arrl_sect INTEGER, "
"band_rx INTEGER, "
"checkcontest VARCHAR, "
"class VARCHAR, "
"contacted_op VARCHAR(40), "
"contest_id VARCHAR, "
"country VARCHAR, "
"credit_submitted VARCHAR, "
"credit_granted VARCHAR, "
"distance INTEGER, "
"email VARCHAR, "
"eq_call VARCHAR, "
"eqsl_qslrdate VARCHAR(10), "
"eqsl_qslsdate VARCHAR(10), "
"eqsl_qsl_rcvd VARCHAR(1), "
"eqsl_qsl_sent VARCHAR(1), "
"force_init INTEGER, "
"freq INTEGER, "
"freq_rx INTEGER, "
"gridsquare VARCHAR, "
"iota VARCHAR(6), "
"iota_island_id VARCHAR, "
"k_index INTEGER, "
"lat VARCHAR(11), "
"lon VARCHAR(11), "
"lotw_qslrdate VARCHAR(10), "
"lotw_qslsdate VARCHAR(10), "
"lotw_qsl_rcvd VARCHAR(1), "
"lotw_qsl_sent VARCHAR(1), "
"max_bursts INTEGER, "
"ms_shower VARCHAR, "
"my_city VARCHAR, "
"my_cnty VARCHAR, "
"my_country INTEGER, "
"my_cq_zone INTEGER, "
"my_gridsquare VARCHAR, "
"my_iota VARCHAR(6), "
"my_iota_island_id VARCHAR, "
"my_lat VARCHAR(11), "
"my_lon VARCHAR(11), "
"my_name VARCHAR, "
"my_rig VARCHAR, "
"my_sig VARCHAR, "
"my_sig_info VARCHAR, "
"my_state VARCHAR, "
"my_street VARCHAR, "
"name VARCHAR, "
"notes VARCHAR, "
"nr_bursts INTEGER, "
"nr_pings INTEGER, "
"operator VARCHAR, "
"owner_callsign VARCHAR, "
"pfx VARCHAR, "
"precedence VARCHAR, "
"prop_mode VARCHAR(8), "
"public_key VARCHAR, "
"qslmsg VARCHAR, "
"qslrdate VARCHAR(10), "
"qslsdate VARCHAR(10), "
"qsl_rcvd VARCHAR(1), "
"qsl_sent VARCHAR(1), "
"qsl_rcvd_via VARCHAR(1), "
"qsl_sent_via VARCHAR(1), "
"qsl_via VARCHAR, "
"qso_complete VARCHAR(1), "
"qso_random INTEGER, "
"qth VARCHAR, "
"rx_pwr REAL, "
"sat_mode VARCHAR, "
"sat_name VARCHAR, "
"sfi INTEGER, "
"sig VARCHAR, "
"sig_info VARCHAR, "
"srx_string VARCHAR, "
"stx_string VARCHAR, "
"state VARCHAR, "
"station_callsign VARCHAR, "
"swl INTEGER, "
"ten_ten INTEGER, "
"tx_pwr REAL, "
"web VARCHAR, "
"qso_date_off VARCHAR(10), "
"time_off VARCHAR(8), "
"transmiterid VARCHAR, "
"marked VARCHAR(1), "
"lognumber INTEGER NOT NULL, "
"UNIQUE (call, qso_date, time_on, bandid, modeid, lognumber), "
"FOREIGN KEY (qso_complete) REFERENCES qso_complete_enumeration, "
"FOREIGN KEY (qsl_rcvd_via) REFERENCES qsl_via_enumeration, "
"FOREIGN KEY (qsl_sent_via) REFERENCES qsl_via_enumeration, "
"FOREIGN KEY (qsl_rcvd) REFERENCES qsl_rec_status, "
"FOREIGN KEY (qsl_sent) REFERENCES qsl_sent_status, "
"FOREIGN KEY (prop_mode) REFERENCES prop_mode_emumeration, "
"FOREIGN KEY (my_country) REFERENCES entity, "
"FOREIGN KEY (lotw_qsl_rcvd) REFERENCES qsl_rec_status, "
"FOREIGN KEY (lotw_qsl_sent) REFERENCES qsl_sent_status, "
"FOREIGN KEY (eqsl_qsl_rcvd) REFERENCES qsl_rec_status, "
"FOREIGN KEY (eqsl_qsl_sent) REFERENCES qsl_sent_status, "
"FOREIGN KEY (credit_submitted) REFERENCES award_enumeration, "
"FOREIGN KEY (credit_granted) REFERENCES award_enumeration, "
"FOREIGN KEY (country) REFERENCES entity, "
"FOREIGN KEY (ant_path) REFERENCES ant_path_enumeration, "
"FOREIGN KEY (arrl_sect) REFERENCES arrl_sect_enumeration, "
"FOREIGN KEY (band_rx) REFERENCES band, "
"FOREIGN KEY (modeid) REFERENCES mode, "
"FOREIGN KEY (dxcc) REFERENCES entity, "
"FOREIGN KEY (bandid) REFERENCES band)");
//qDebug() << "DataBase::createTableLog: " << stringQuery << endl;
return query.exec(stringQuery);
}
bool DataBase::createDataBase()
{
//qDebug() << "DataBase::createDataBase" << endl;
bool qres;
//http://www.sqlite.org/
//http://www.sqlite.org/datatype3.html
//qDebug() << "DataBase::createData" << endl;
//int softDB = dbVersion;
//QString softV = _softVersion;
QString dateString;
QSqlQuery query;
query.exec("DROP TABLE log");
query.exec("DROP TABLE band");
query.exec("DROP TABLE mode");
//query.exec("DROP TABLE mode");
query.exec("DROP TABLE prefixesofentity");
query.exec("DROP TABLE continent");
query.exec("DROP TABLE entity");
query.exec("CREATE TABLE softwarecontrol ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"dateupgrade VARCHAR(10) NOT NULL, "
"softversion REAL NOT NULL, "
"dbversion REAL NOT NULL)");
dateString = (date.currentDateTime()).toString("yyyyMMdd");
query.exec("INSERT INTO softwarecontrol (dateupgrade, softversion, dbversion) VALUES ('" + dateString + "', '" + softVersion + "', '" + QString::number(dbVersion) + "')");
qres = query.exec("CREATE TABLE band ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"lower REAL NOT NULL, "
"upper REAL NOT NULL, "
"cabrillo VARCHAR(6) NOT NULL, "
"name VARCHAR(40) NOT NULL, "
"UNIQUE (lower, upper, cabrillo, name) )");
/*
if (qres)
{
//qDebug() << "DataBase::createDataBase - Band created" << endl;
}
else
{
//qDebug() << "DataBase::createDataBase - Band not created" << endl;
//qDebug() << "DataBase::createDataBase: " << query.lastError().text() << endl;
}
*/
query.exec("CREATE TABLE mode ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"cabrillo VARCHAR(2) NOT NULL, "
"name VARCHAR(40) NOT NULL, "
"UNIQUE (cabrillo, name) )");
createTableLog();
//DATE YYYY-MM-DD
//TIME HHmmss
//http://www.sqlite.org/lang_datefunc.html
/*
"confirmed INTEGER NOT NULL, "
confirmed means:
confirmed = 0 Set as Worked
confirmed = 1 Set as Confirmed
*/
query.exec("CREATE TABLE continent ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(2) NOT NULL, "
"name VARCHAR(15) NOT NULL)");
query.exec("CREATE TABLE ant_path_enumeration ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(1) NOT NULL, "
"name VARCHAR(15) NOT NULL)");
query.exec("CREATE TABLE arrl_sect_enumeration ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(2) NOT NULL, "
"name VARCHAR(30) NOT NULL)");
query.exec("CREATE TABLE qso_complete_enumeration ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(3) NOT NULL, "
"name VARCHAR(10) NOT NULL)");
createTableContest();
query.exec("CREATE TABLE contestcategory ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(20) NOT NULL, "
"name VARCHAR(40) NOT NULL");
query.exec("CREATE TABLE award_enumeration ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"name VARCHAR(15) NOT NULL)");
query.exec("CREATE TABLE entity ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"name VARCHAR(40) NOT NULL,"
"cqz INTEGER NOT NULL, "
"ituz INTEGER NOT NULL, "
"continent INTEGER NOT NULL, "
"latitude REAL NOT NULL, "
"longitude REAL NOT NULL, "
"utc INTEGER NOT NULL, "
"dxcc INTEGER NOT NULL, "
"mainprefix VARCHAR(15) NOT NULL, "
"deleted INTEGER, "
"sincedate VARCHAR(10), "
"todate VARCHAR(10), "
"UNIQUE (dxcc, mainprefix), "
"FOREIGN KEY (continent) REFERENCES continent(shortname))");
//TODO: To add some columns in this the table to mark if worked/confirmed/band/Mode
//query.exec("INSERT INTO entity (name, cqz, ituz, continent, latitude, longitude, utc, dxcc, mainprefix, deleted, sincedate, todate) VALUES ('Canada', '0', '0', '0', '0', '0', '0', '0', 'VE', 'q', 'sincedate', 'todate')");
query.exec("CREATE TABLE prefixesofentity ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"prefix VARCHAR(15) NOT NULL,"
"dxcc INTEGER NOT NULL,"
"cqz INTEGER NOT NULL,"
"ituz INTEGER NOT NULL,"
"UNIQUE (prefix, dxcc), "
"FOREIGN KEY (dxcc) REFERENCES entity)");
query.exec("CREATE TABLE awarddxcc ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"dxcc INTEGER NOT NULL,"
"band INTEGER NOT NULL, "
"mode INTEGER NOT NULL, "
"confirmed INTEGER, "
"qsoid INTEGER NOT NULL, "
"lognumber INTEGER, "
"UNIQUE (dxcc, band, mode, lognumber), "
"FOREIGN KEY (dxcc) REFERENCES entity, "
"FOREIGN KEY (band) REFERENCES band, "
"FOREIGN KEY (mode) REFERENCES mode, "
"FOREIGN KEY (qsoid) REFERENCES log)");
/*
In awarddxcc confirmed means:
confirmed = 0 Set as Worked
confirmed = 1 Set as Confirmed
*/
query.exec("CREATE TABLE awardwaz ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"cqz INTEGER NOT NULL,"
"band INTEGER NOT NULL, "
"mode INTEGER NOT NULL, "
"confirmed INTEGER, "
"qsoid INTEGER NOT NULL, "
"lognumber INTEGER, "
"UNIQUE (cqz, band, mode, confirmed, lognumber), "
"FOREIGN KEY (band) REFERENCES band, "
"FOREIGN KEY (mode) REFERENCES mode, "
"FOREIGN KEY (qsoid) REFERENCES log)");
/*
In awardwaz confirmed means:
confirmed = 0 Set as Worked
confirmed = 1 Set as Confirmed
*/
query.exec("CREATE TABLE qsl_rec_status ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(1) NOT NULL, "
"name VARCHAR(15) NOT NULL)");
query.exec("CREATE TABLE qsl_sent_status ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(1) NOT NULL, "
"name VARCHAR(15) NOT NULL)");
query.exec("CREATE TABLE qsl_via ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(1) NOT NULL, "
"name VARCHAR(15) NOT NULL)");
query.exec("CREATE TABLE prop_mode_enumeration ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(8) NOT NULL, "
"name VARCHAR(55) NOT NULL)");
query.exec("CREATE TABLE logs ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"logdate VARCHAR(10), "
"stationcall VARCHAR(15) NOT NULL, "
"comment VARCHAR, "
"logtype VARCHAR, "
"logtypen INTEGER, "
"FOREIGN KEY (logtypen) REFERENCES supportedcontests(id),"
"FOREIGN KEY (logtype) REFERENCES supportedcontests(name))");
/*
query.exec("CREATE TABLE sat_modes ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"name VARCHAR(15) NOT NULL,"
"uplink INTEGER NOT NULL,"
"downlink INTEGER NOT NULL,"
"FOREIGN KEY (uplink) REFERENCES band, "
"FOREIGN KEY (downlink) REFERENCES band)");
//http://en.wikipedia.org/wiki/OSCAR#Mode_designators
//query.exec("INSERT INTO sat_modes (name, uplink, downlink) VALUES ('H', '15M', '148', '144')");
query.exec("CREATE TABLE sat_modes ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"shortname VARCHAR(8) NOT NULL, "
"uplink VARCHAR(8) NOT NULL, "
"downlink VARCHAR(55) NOT NULL)");
query.exec("CREATE TABLE sat_modes ("
"id INTEGER PRIMARY KEY AUTOINCREMENT, "
"name VARCHAR(15) NOT NULL,"
"uplink INTEGER NOT NULL,"
"downlink INTEGER NOT NULL,"
"FOREIGN KEY (uplink) REFERENCES band, "
"FOREIGN KEY (downlink) REFERENCES band)");
*/
/*
qry.prepare( "INSERT INTO names (id, firstname, lastname) VALUES (:id, :firstname, :lastname)" );
qry.bindValue( ":id", 9 );
qry.bindValue( ":firstname", "Ralph" );
qry.bindValue( ":lastname", "Roe" );
query.prepare("INSERT INTO qsl_sent_status (shortname, name) VALUES (:shortname, :name)");
query.bindValue(":shortname", "Y");
query.bindValue(":name", "Yes");
query.prepare("INSERT INTO qsl_sent_status (shortname, name) VALUES (:shortname, :name)");
query.bindValue(":shortname", "N");
query.bindValue(":name", "No");
query.exec();
*/
query.exec("INSERT INTO qsl_sent_status (shortname, name) VALUES ('Y', 'Yes')");
query.exec("INSERT INTO qsl_sent_status (shortname, name) VALUES ('N', 'No')");
query.exec("INSERT INTO qsl_sent_status (shortname, name) VALUES ('R', 'Requested')");
query.exec("INSERT INTO qsl_sent_status (shortname, name) VALUES ('Q', 'Queued')");
query.exec("INSERT INTO qsl_sent_status (shortname, name) VALUES ('I', 'Ignore/Invalid')");
query.exec("INSERT INTO qsl_rec_status (shortname, name) VALUES ('Y', 'Yes')");
query.exec("INSERT INTO qsl_rec_status (shortname, name) VALUES ('N', 'No')");
query.exec("INSERT INTO qsl_rec_status (shortname, name) VALUES ('R', 'Requested')");
query.exec("INSERT INTO qsl_rec_status (shortname, name) VALUES ('I', 'Ignore/Invalid')");
query.exec("INSERT INTO qsl_rec_status (shortname, name) VALUES ('V', 'Validated')");
query.exec("INSERT INTO continent (shortname, name) VALUES ('AF', 'Africa')");
query.exec("INSERT INTO continent (shortname, name) VALUES ('AS', 'Asia')");
query.exec("INSERT INTO continent (shortname, name) VALUES ('EU', 'Europe')");
query.exec("INSERT INTO continent (shortname, name) VALUES ('NA', 'North America')");
query.exec("INSERT INTO continent (shortname, name) VALUES ('OC', 'Oceania')");
query.exec("INSERT INTO continent (shortname, name) VALUES ('SA', 'South America')");
query.exec("INSERT INTO continent (shortname, name) VALUES ('AN', 'Antartica')");
populateContestData();
//To add a band, just create another line:
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('0', '0', '0', 'Light')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('1mm', '241000', '250000', '241G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('2mm', '142000', '149000', '142G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('2.5mm', '119980', '120020', '119G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('4mm', '75500', '81000', '75G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('6mm', '47000', '47200', '47G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('1.25CM', '24000', '24250', '24G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('3CM', '10000', '10500', '10G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('6CM', '5650', '5925', '5.7G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('9CM', '3300', '3500', '3.4G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('13CM', '1240', '1300', '1.2G')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('33CM', '902', '928', '902')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('70CM', '420', '450', '432')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('1.25M', '222', '225', '222')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('2M', '144', '148', '144')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('4M', '70', '71', '4M')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('6M', '50', '54', '50')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('10M', '28.0', '29.7', '28000')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('12M', '24.89', '24.99', '24000')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('15M', '21.0', '21.45', '21000')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('17M', '18.068', '18.168', '18100')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('20M', '14.0', '14.35', '14000')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('30M', '10.0', '10.15', '10000')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('40M', '7.0', '7.3', '7000')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('60M', '5.102', '5.404', '5100')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('80M', '3.5', '4.0', '3500')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('160M', '1.8', '2.0', '1800')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('560M', '0.501', '0.504', '560M')");
query.exec("INSERT INTO band (name, lower, upper, cabrillo) VALUES ('2190M', '0.136', '0.137', '2190M')");
//To add a mode, just create another line:
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('AM', 'PH')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('AMTORFEC', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('ASCI', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('ATV', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('CHIP64', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('CHIP128', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('CLO', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('CONTESTI', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('CW', 'CW')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('DSTAR', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('DOMINO', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('DOMINOF', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('FAX, 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('FM', 'PH')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('FMHELL', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('FSK31', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('FSK441', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('GTOR', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('HELL', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('HELL80', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('HFSK', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT44', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT4A', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT4B', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT4C', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT4D', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT4E', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT4F', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT4G', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT65A', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT65B', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT65C', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('JT6M', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('MFSK8', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('MFSK16', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('MT63', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('OLIVIA', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PAC', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PAC2', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PAC3', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PAX', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PAX2', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PCW', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PKT', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSK10', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSK31', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSK63', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSK63F', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSK125', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSKAM10', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSKAM31', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSKAM50', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSKFEC31', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('PSKHELL', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('Q15', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('QPSK31', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('QPSK63', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('QPSK125', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('ROS', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('RTTY', 'RY')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('RTTYM', 'RY')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('SSB', 'PH')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('SSTV', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('THRB', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('THOR', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('THRBX', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('TOR', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('VOI', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('WINMOR', 'NO')");
query.exec("INSERT INTO mode (name, cabrillo) VALUES ('WSPR', 'NO')");
query.exec("INSERT INTO ant_path_enumeration (shortname, name) VALUES ('G', 'GrayLine')");
query.exec("INSERT INTO ant_path_enumeration (shortname, name) VALUES ('O', 'Other')");
query.exec("INSERT INTO ant_path_enumeration (shortname, name) VALUES ('S', 'ShortPath')");
query.exec("INSERT INTO ant_path_enumeration (shortname, name) VALUES ('L', 'LongPath')");
query.exec("INSERT INTO arrl_sect_enumeration (shortname, name) VALUES ('AL', 'Alabama')");
query.exec("INSERT INTO award_enumeration (name) VALUES ('AJA')");
query.exec("INSERT INTO award_enumeration (name) VALUES ('CQDX')");
query.exec("INSERT INTO award_enumeration (name) VALUES (CQDXFIELD')");
query.exec("INSERT INTO award_enumeration (name) VALUES (DXCC')");
query.exec("INSERT INTO award_enumeration (name) VALUES (TPEA')");
query.exec("INSERT INTO prop_mode_enumeration (shortname, name) VALUES ('AUR', 'Aurora')");
query.exec("INSERT INTO prop_mode_enumeration (shortname, name) VALUES ('AUE', 'Aurora-E')");
query.exec("INSERT INTO prop_mode_enumeration (shortname, name) VALUES ('BS', 'Back scatter')");
query.exec("INSERT INTO qsl_via (shortname, name) VALUES ('B', 'Bureau')");
query.exec("INSERT INTO qsl_via (shortname, name) VALUES ('D', 'Direct')");
query.exec("INSERT INTO qsl_via (shortname, name) VALUES ('E', 'Electronic')");
query.exec("INSERT INTO qsl_via (shortname, name) VALUES ('M', 'Manager')");
query.exec("INSERT INTO qso_complete_enumeration (shortname, name) VALUES ('Y', 'Yes')");
query.exec("INSERT INTO qso_complete_enumeration (shortname, name) VALUES ('N', 'No')");
query.exec("INSERT INTO qso_complete_enumeration (shortname, name) VALUES ('NIL', 'Not heard')");
query.exec("INSERT INTO qso_complete_enumeration (shortname, name) VALUES ('?', 'Uncertain')");
return true;
}
int DataBase::getBandIdFromName(const QString b)
{
//qDebug() << "DataBase::getBandIdFromName: " << b << endl;
QSqlQuery query;
if (isValidBand(b))
{
QString queryString = QString("SELECT id FROM band WHERE name='%1'").arg(b);
query.exec(queryString);
query.next();
if ( query.isValid() )
{
//qDebug() << "DataBase::getBandIdFromName: OK" << QString::number((query.value(0)).toInt()) << endl;
return (query.value(0)).toInt();
}
else
{
//qDebug() << "DataBase::getBandIdFromName: NOK 1" << endl;
return -1;
}
}
else
{
//qDebug() << "DataBase::getBandIdFromName: NOK 2" << endl;
return -1;
}
//qDebug() << "DataBase::getBandIdFromName: NOK 3" << endl;
return -1;
}
int DataBase::getModeIdFromName(const QString b)
{
//qDebug() << "DataBase::getModeIdFromName: " << b << endl;
QSqlQuery query;
if (isValidBand(b))
{
QString queryString = QString("SELECT id FROM mode WHERE name='%1'").arg(b);
//qDebug() << "DataBase::getModeIdFromName: queryString: " << queryString << endl;
query.exec(queryString);
query.next();
if ( query.isValid() )
{
//qDebug() << "DataBase::getModeIdFromName: OK" << QString::number((query.value(0)).toInt()) << endl;
return (query.value(0)).toInt();
}
else
{
//qDebug() << "DataBase::getModeIdFromName: NOK 1" << endl;
return -1;
}
}
else
{
//qDebug() << "DataBase::getModeIdFromName: NOK 2" << endl;
return -1;
}
//qDebug() << "DataBase::getModeIdFromName: NOK 3" << endl;
return -1;
}
QString DataBase::getBandNameFromNumber(const int _n)
{
QSqlQuery query;
QString queryString = QString("SELECT name FROM band WHERE id='%1'").arg(_n);
query.exec(queryString);
query.next();
if ( query.isValid() )
{
if ( isValidBand((query.value(0)).toString()) )
{
return (query.value(0)).toString();
}
else
{
return "";
}
}
else
{
return "";
}
}
QString DataBase::getModeNameFromNumber(const int _n)
{
QSqlQuery query;
QString queryString = QString("SELECT name FROM mode WHERE id='%1'").arg(_n);
query.exec(queryString);
query.next();
if ( query.isValid() )
{
if ( isValidMode((query.value(0)).toString()) )
{
return (query.value(0)).toString();
}
else
{
return "";
}
}
else
{
return "";
}
}
bool DataBase::isValidBand (const QString b)
{
if (b.length()<1)
{
return false;
}
QString stringQuery = QString("SELECT id FROM band WHERE name='%1'").arg(b);
QSqlQuery query(stringQuery);
query.next();
return query.isValid();
}
bool DataBase::isValidMode (const QString b)
{
if (b.length()<2)
{
return false;
}
QString stringQuery = QString("SELECT id FROM mode WHERE name='%1'").arg(b);
QSqlQuery query(stringQuery);
query.next();
return query.isValid();
}
bool DataBase::isValidBandNumber (const int b)
{
return isValidBand(getBandNameFromNumber(b));
}
bool DataBase::isValidModeNumber (const int b)
{
return isValidMode(getModeNameFromNumber(b));
}
int DataBase::getBandIdFromFreq(const QString fr)
{
//qDebug() << "DataBase::getBandIdFromFreq: " << fr << endl;
//Freq should be in MHz
QString queryString = QString("SELECT id FROM band WHERE lower < '%1' and upper > '%2'").arg(fr).arg(fr);
QSqlQuery query(queryString);
query.next();
if (query.isValid())
{
return (query.value(0)).toInt();
}
else
{
return -1;
}
return -1;
}
bool DataBase::unMarkAllQSO()
{
QString stringQuery = QString("UPDATE log SET marked = 'N' WHERE 1");
QSqlQuery query(stringQuery);
//qDebug() << "MainWindow::slotQSLSentViaBureauFromLog: " << stringQuery << endl;
//query.exec(stringQuery);
//TODO: Check if the execution of this query is OK or NOK (should return false)
return true;
}
bool DataBase::updateIfNeeded()
{
//qDebug() << "DataBase::updateIfNeeded - Version: " << QString::number(dbVersion) << endl;
/**************************************************************************************
* This function should call to bool updateToXXX () being XXX dbVersion and
*
*/
float aux = 0.0;
int nameCol;
int errorCode = -1;
bool toBeUpdated = false;
bool sqlOK;
QString dateString;
QString SQLString, auxs;
QStringList SQLStrings;
SQLStrings.clear();
QSqlQuery query("SELECT dbversion FROM softwarecontrol");
QSqlRecord rec = query.record();
while ( (query.next())) { // We run the DB to find what is the latest DB version updated.
if (query.isValid())
{
nameCol = rec.indexOf("dbversion");
aux = (query.value(nameCol)).toFloat();
if (aux > latestReaded)
{
latestReaded = aux;
}
else
{
}
}
else
{
}
}
if (latestReaded >= dbVersion)
{ // DB is updated, no update is needed
//qDebug() << "DataBase::updateIfNeeded - DB updated (no need to update anything!) " << endl;
toBeUpdated = false;
return true;
}
else
{ // DB is outdated. We need to update!!
QMessageBox msgBox;
msgBox.setText("KlusterDB needs to be upgraded.");
msgBox.setInformativeText("Do you want to upgrade it now?\nIf DB is not upgraded Kluster may not work properly.");
msgBox.setStandardButtons(QMessageBox::Apply | QMessageBox::Discard);
msgBox.setDefaultButton(QMessageBox::Apply);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Apply:
// Save was clicked
updateToLatest();
break;
case QMessageBox::Discard:
// Discard was clicked
break;
default:
// should never be reached
return false;
break;
}
}
// If the DB needs to be updated... we update it! :-)
return true;
}
bool DataBase::createTheBandQuickReference()
{
/*
KEY Value
QHash<QString, int> bandIDHash;
QHash<QString, int> modeIDHash;
QHash<int, QString> IDBandHash;
QHash<int, QString> IDModeHash
QHash<double, int> freqBandIdHash;
*/
//qDebug() << "DataBase::createTheBandQuickReference: " << endl;
QString st = "NULL";
int in = 0;
double fr = 0;
QSqlQuery query("SELECT id, name, lower FROM band");
while (query.next())
{
if (query.isValid())
{
st = (query.value(1)).toString();
in = (query.value(0)).toInt();