Source
#!/usr/bin/env perl
#
# Copyright (C) 2001-2025 Zabbix SIA
#
# This program is free software: you can redistribute it and/or modify it under the terms of
# the GNU Affero General Public License as published by the Free Software Foundation, version 3.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License along with this program.
# If not, see <https://www.gnu.org/licenses/>.
use ;
use :: ;
my (%output, $insert_into, $fields, @values_list);
my %mysql = (
"database" => "mysql",
"before" => "START TRANSACTION;\n",
"after" => "COMMIT;\n",
"exec_cmd" => ";\n"
);
my %oracle = (
"database" => "oracle",
"before" => "SET DEFINE OFF\n",
"after" => "",
"exec_cmd" => "\n/\n\n"
);
my %postgresql = (
"database" => "postgresql",
"before" => "START TRANSACTION;\n",
"after" => "COMMIT;\n",
"exec_cmd" => ";\n"
);
# Maximum line length that SQL*Plus can read from .sql file is 2499 characters.
# Splitting long entries in 'media_type' table have to happen before SQL*Plus limit has been reached and end-of-line
# character has to stay intact in one line.
my $oracle_field_limit = 2048;
sub
{
my $line = $_[0];
$line = "`$line`" if ($output{'database'} eq 'mysql');
$insert_into = "INSERT INTO $line";
@values_list = (); # Reset the values list when processing a new table
}
sub
{
my $line = $_[0];
my @array = split(/\|/, $line);
my $first = 1;
$fields = "(";