Skip to content

Commit

Permalink
handle large ADIF files
Browse files Browse the repository at this point in the history
  • Loading branch information
jxmx committed May 11, 2023
1 parent c2221f3 commit 523dd5e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
29 changes: 24 additions & 5 deletions load/qsladifloadcommit.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,38 @@

# get the id of the last log
$sql = sprintf("SELECT LAST_INSERT_ID()");

# Insertion transaction
$res = $conn->query($sql);
list($logid) = $res->fetch_row();

# insert the actual transaction
$conn->begin_transaction();
$vals = base64_decode($transdata);
$vals = preg_replace("/\)/",",$logid)",$vals);
$sql = sprintf("INSERT INTO qsos (callsign,band,freq,rstrcvd,qsodate,timeon,operator,station,mode,county,logid) VALUES %s",
$vals);
if( $conn->query($sql) === false ){
printf("<p class=\"lead\">Could not write the QSOs to the DB. Transaction
$inserts = explode("),(", $vals);
foreach( $inserts as $insert){
$insert = preg_replace("/[\(\)]/", "", $insert);
$sql = sprintf("INSERT INTO qsos (callsign,band,freq,rstrcvd,qsodate," .
"timeon,operator,station,mode,county,logid) VALUES (%s)",
$insert);
$res = $conn->query($sql);
if( $res === false ){
printf("<p class=\"lead\">Individual transaction insert failed due to bad input</p>");
printf("<pre>%s</pre>", $conn->error);
printf("<pre>%s</pre>", $sql);
printf("Transaction ID is:<br>%s</p>\n", $transid);
$conn->rollback();
goto end;
}
}

if( $conn->commit() === false ){
$conn->rollback();
printf("<p class=\"lead\">Could not write the QSO transaction to the DB. Transaction
ID is:<br>%s</p>\n", $transid);
goto end;
}

$sql = sprintf("DELETE FROM trans WHERE transid=\"%s\"", $transid);
if( $conn->query($sql) === false ){
printf("<p class=\"lead\">Could not unlock transaction. Transaction
Expand Down
8 changes: 5 additions & 3 deletions qsl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ CREATE TABLE `qsos` (
`timeon` char(14) DEFAULT NULL,
`operator` char(10) NOT NULL,
`station` char(10) NOT NULL,
`mode` char(10) DEFAULT NULL,
`mode` char(30) DEFAULT NULL,
`tstamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`logid` int(11) NOT NULL,
`county` char(30) DEFAULT NULL,
`county` varchar(255) DEFAULT NULL,
PRIMARY KEY (`qsoid`),
KEY `callsign_idx` (`callsign`)
) ENGINE=InnoDB AUTO_INCREMENT=1883 DEFAULT CHARSET=latin1;
Expand Down Expand Up @@ -88,4 +88,6 @@ CREATE TABLE `trans` (
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2017-06-04 16:01:21
ALTER TABLE `qsos` MODIFY `mode` char(30) DEFAULT NULL;
ALTER TABLE `qsos` MODIFY `county` varchar(255) DEFAULT NULL;

0 comments on commit 523dd5e

Please sign in to comment.