Skip to content

Commit c2eb5be

Browse files
committed
resolve 'next' warnings + protect textbook query
1 parent cd30361 commit c2eb5be

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

.github/workflows/bin/generate-OPL-tables.pl

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ sub pgfiles {
566566
} else {
567567
# Tags are not valid, error printed by validation part.
568568
#print "File $name\n";
569-
next;
569+
return; # next is not valid for subs
570570
}
571571

572572
my @DBsection_ids = ($aDBsection_id);
@@ -705,16 +705,18 @@ sub pgfiles {
705705
$edition = 0 unless $edition;
706706
$dbh->do(qq{INSERT INTO `$tables{textbook}`
707707
VALUES( NULL, "$text", "$edition", "$textauthor", NULL, NULL, NULL)});
708-
dbug qq{INSERT INTO textbook VALUES("", "$text", "$edition", "$textauthor", "", "", "")\n};
709-
dbug qq{\nLate add into $tables{textbook} "$text", "$edition", "$textauthor"\n}, 1;
710708
$textbook_id = $dbh->selectrow_array($textbook_id_query);
709+
unless ($textbook_id) {
710+
warn qq{INSERT INTO textbook VALUES("", "$text", "$edition", "$textauthor", "", "", "")\n};
711+
warn qq{\nLate add into $tables{textbook} "$text", "$edition", "$textauthor"\n};
712+
}
711713
}
712714

713715
# chapter weak table of textbook
714716
my $chapter_id_query = qq{SELECT chapter_id FROM `$tables{chapter}`
715717
WHERE textbook_id="$textbook_id" AND number="$chapnum"};
716718
my $chapter_id = $dbh->selectrow_array($chapter_id_query);
717-
if (!defined($chapter_id)) {
719+
if (!defined($chapter_id) && defined($textbook_id)) {
718720
$dbh->do(qq{INSERT INTO `$tables{chapter}`
719721
VALUES(NULL, "$textbook_id", "$chapnum", "$tags->{DBchapter}", NULL)});
720722
dbug qq{\nLate add into $tables{chapter} "$text", "$edition",
@@ -728,7 +730,7 @@ sub pgfiles {
728730
my $section_id_query = qq{SELECT section_id FROM `$tables{section}`
729731
WHERE chapter_id="$chapter_id" AND number="$secnum"};
730732
my $section_id = $dbh->selectrow_array($section_id_query);
731-
if (!defined($section_id)) {
733+
if (!defined($section_id) && defined($chapter_id) && defined($textbook_id)) {
732734
$dbh->do(qq{INSERT INTO `$tables{section}`
733735
VALUES(NULL, "$chapter_id", "$secnum", "$tags->{DBsection}", NULL)});
734736
dbug qq{INSERT INTO section VALUES("", "$textbook_id", "$secnum", "$tags->{DBsection}", "" )\n};
@@ -738,23 +740,25 @@ sub pgfiles {
738740
}
739741

740742
@textproblems = @{ $texthashref->{problems} };
741-
for my $tp (@textproblems) {
742-
my $problem_id_query = qq{SELECT problem_id FROM `$tables{problem}`
743-
WHERE section_id="$section_id" AND number="$tp"};
744-
my $problem_id = $dbh->selectrow_array($problem_id_query);
745-
if (!defined($problem_id)) {
746-
$dbh->do(qq{INSERT INTO `$tables{problem}` VALUES(NULL, "$section_id", "$tp", NULL)});
747-
dbug qq{INSERT INTO problem VALUES("", "$section_id", "$tp", "")\n};
748-
$problem_id = $dbh->selectrow_array($problem_id_query);
749-
}
743+
if ($section_id) {
744+
for my $tp (@textproblems) {
745+
my $problem_id_query = qq{SELECT problem_id FROM `$tables{problem}`
746+
WHERE section_id="$section_id" AND number="$tp"};
747+
my $problem_id = $dbh->selectrow_array($problem_id_query);
748+
if (!defined($problem_id)) {
749+
$dbh->do(qq{INSERT INTO `$tables{problem}` VALUES(NULL, "$section_id", "$tp", NULL)});
750+
dbug qq{INSERT INTO problem VALUES("", "$section_id", "$tp", "")\n};
751+
$problem_id = $dbh->selectrow_array($problem_id_query);
752+
}
750753

751-
# pgfile_problem table associates pgfiles with textbook problems
752-
for my $pgfile_id (@pgfile_ids) {
753-
my $pg_problem_id = $dbh->selectrow_array(qq{SELECT problem_id FROM `$tables{pgfile_problem}`
754-
WHERE problem_id="$problem_id" AND pgfile_id="$pgfile_id"});
755-
if (!defined($pg_problem_id)) {
756-
$dbh->do(qq{INSERT INTO `$tables{pgfile_problem}` VALUES("$pgfile_id", "$problem_id")});
757-
dbug qq{INSERT INTO pgfile_problem VALUES("$pgfile_id", "$problem_id")\n};
754+
# pgfile_problem table associates pgfiles with textbook problems
755+
for my $pgfile_id (@pgfile_ids) {
756+
my $pg_problem_id = $dbh->selectrow_array(qq{SELECT problem_id FROM `$tables{pgfile_problem}`
757+
WHERE problem_id="$problem_id" AND pgfile_id="$pgfile_id"});
758+
if (!defined($pg_problem_id)) {
759+
$dbh->do(qq{INSERT INTO `$tables{pgfile_problem}` VALUES("$pgfile_id", "$problem_id")});
760+
dbug qq{INSERT INTO pgfile_problem VALUES("$pgfile_id", "$problem_id")\n};
761+
}
758762
}
759763
}
760764
}

0 commit comments

Comments
 (0)