Files
2025-04-09 21:36:51 +02:00

104 lines
3.0 KiB
Perl

#!perl -w
# manuelle Nacharbeit
# nach dem erstellen muss die insert ohne werte entfernt werden
# bei abschließenden Inserts muss ), durch ); ersetzt werden
use strict;
use File::Slurp qw(:std);
use IO::Handle;
use File::Path qw(make_path);
use Data::Printer;
my $datei = "admin ori.sql";
if ( -e $datei ) {
my @lines = read_file($datei);
write_file("admin_neu.sql", "" );
my $tblname = "";
my %spalten; # spaltennamen merken
my $cre = 0;
my $ins = 0;
for my $l ( @lines ) {
chomp($l);
if ( $l =~ /CREATE/ ) {
if ( $l =~ /CX_/ ) {
if ( $l =~ /CREATE TABLE/ ) {
my @spl = split( / /, $l);
$tblname = $spl[2];
$tblname =~ s/SYSADM.//;
$tblname .= "_";
}
$l =~ s/$tblname//g;
$l =~ s/CREATE TABLE/CREATE TABLE IF NOT EXISTS /;
$cre = 1;
} else {
$cre = 0;
}
$ins = 0;
}
next if ( $cre == 0 );
if ($cre > 0 ) {
if ($cre > 1 ) {
my @s = split( / /, $l );
$spalten{$cre} = $s[2];
}
$cre += 1;
if ($l =~ /\)$/) {
$cre = -1;
$l =~ s/\)$/);/;
}
}
#ALTER TABLE `etv_foerderer` ADD UNIQUE INDEX `Art` (`Art`);
my $letzte = substr $l, -1;
next if ( $letzte =~ /\~|LOADVERSION/ );
next if ( $l =~ /\/\/|\$DATATYPES|AL~5|D~}|~\||wwwwp|~IC~}/ );
next if ( $l eq "/" || $l eq "" || $l eq "\\" );
# allgemeine Sachen entfernen tauschen
$l =~ s/SYSADM.//g;
$l =~ s/PCTFREE 10//;
$l =~ s/~OE~/ä/g;
$l =~ s/~PM~/ü/g;
$l =~ s/~NM~/Ü/g;
$l =~ s/~NP~/ß/g;
$l =~ s/~ANAK~"/"/g;
$l =~ s/~ANAK~/\\n/g;
$l =~ s/\$long/""/;
$l =~ s/'//;
if ($ins > 0 ) {
if ( $l =~ /:$ins/ ) {
$l =~ s/:$ins/$spalten{$ins + 1}/;
if ( $l =~ /\)/ ) {
$l =~ s/\)/\) VALUES/;
}
} else {
$l =~ s/,$/),/;
$l =~ s/'/\\'/g;
$l =~ s/,\),$/,''),/;
$l = "(".$l;
$l =~ s/"/'/g;
$l =~ s/\(,/('',/;
$l =~ s/,,,/,'','',/;
$l =~ s/,,/,'',/;
}
$ins += 1
}
if ( $l =~ /INSERT INTO/ ) {
$l =~ s/VALUES//;
$l =~ s/INSERT INTO/INSERT IGNORE INTO/;
$ins = 1;
}
append_file("admin_neu.sql", "$l\n");
}
}
1;