<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># --
# Kernel/System/DB/mysql.pm - mysql database backend
# Copyright (C) 2001-2014 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

package Kernel::System::DB::mysql;

use strict;
use warnings;

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {%Param};
    bless( $Self, $Type );

    return $Self;
}

sub LoadPreferences {
    my ( $Self, %Param ) = @_;

    # db settings
    $Self-&gt;{'DB::Limit'}                = 'limit';
    $Self-&gt;{'DB::DirectBlob'}           = 1;
    $Self-&gt;{'DB::QuoteSingle'}          = '\\';
    $Self-&gt;{'DB::QuoteBack'}            = '\\';
    $Self-&gt;{'DB::QuoteSemicolon'}       = '\\';
    $Self-&gt;{'DB::QuoteUnderscoreStart'} = '\\';
    $Self-&gt;{'DB::QuoteUnderscoreEnd'}   = '';
    $Self-&gt;{'DB::CaseSensitive'}        = 0;
    $Self-&gt;{'DB::LikeEscapeString'}     = '';

    # how to determine server version
    # version can have package prefix, we need to extract that
    # example of VERSION() output: '5.5.32-0ubuntu0.12.04.1'
    # if VERSION() contains 'MariaDB', add MariaDB, otherwise MySQL.
    $Self-&gt;{'DB::Version'}
        = "SELECT CONCAT( IF (INSTR( VERSION(),'MariaDB'),'MariaDB ','MySQL '), SUBSTRING_INDEX(VERSION(),'-',1))";

    # DBI/DBD::mysql attributes
    # disable automatic reconnects as they do not execute DB::Connect, which will
    # cause charset problems
    $Self-&gt;{'DB::Attribute'} = {
        mysql_auto_reconnect =&gt; 0,
    };

    # set current time stamp if different to "current_timestamp"
    $Self-&gt;{'DB::CurrentTimestamp'} = '';

    # set encoding of selected data to utf8
    $Self-&gt;{'DB::Encode'} = 1;

    # shell setting
    $Self-&gt;{'DB::Comment'}     = '# ';
    $Self-&gt;{'DB::ShellCommit'} = ';';

    #$Self-&gt;{'DB::ShellConnect'} = '';

    # init sql setting on db connect
    if ( !$Self-&gt;{ConfigObject}-&gt;Get('Database::ShellOutput') ) {
        $Self-&gt;{'DB::Connect'} = 'SET NAMES utf8';
    }

    return 1;
}

sub Quote {
    my ( $Self, $Text, $Type ) = @_;

    if ( defined ${$Text} ) {
        if ( $Self-&gt;{'DB::QuoteBack'} ) {
            ${$Text} =~ s/\\/$Self-&gt;{'DB::QuoteBack'}\\/g;
        }
        if ( $Self-&gt;{'DB::QuoteSingle'} ) {
            ${$Text} =~ s/'/$Self-&gt;{'DB::QuoteSingle'}'/g;
        }
        if ( $Self-&gt;{'DB::QuoteSemicolon'} ) {
            ${$Text} =~ s/;/$Self-&gt;{'DB::QuoteSemicolon'};/g;
        }
        if ( $Type &amp;&amp; $Type eq 'Like' ) {
            if ( $Self-&gt;{'DB::QuoteUnderscoreStart'} || $Self-&gt;{'DB::QuoteUnderscoreEnd'} ) {
                ${$Text}
                    =~ s/_/$Self-&gt;{'DB::QuoteUnderscoreStart'}_$Self-&gt;{'DB::QuoteUnderscoreEnd'}/g;
            }
        }
    }
    return $Text;
}

sub DatabaseCreate {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    if ( !$Param{Name} ) {
        $Self-&gt;{LogObject}-&gt;Log( Priority =&gt; 'error', Message =&gt; 'Need Name!' );
        return;
    }

    # return SQL
    return ("CREATE DATABASE $Param{Name} DEFAULT CHARSET=utf8");
}

sub DatabaseDrop {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    if ( !$Param{Name} ) {
        $Self-&gt;{LogObject}-&gt;Log( Priority =&gt; 'error', Message =&gt; 'Need Name!' );
        return;
    }

    # return SQL
    return ("DROP DATABASE IF EXISTS $Param{Name}");
}

sub TableCreate {
    my ( $Self, @Param ) = @_;

    my $SQLStart     = '';
    my $SQLEnd       = '';
    my $SQL          = '';
    my @Column       = ();
    my $TableName    = '';
    my $ForeignKey   = ();
    my %Foreign      = ();
    my $IndexCurrent = ();
    my %Index        = ();
    my $UniqCurrent  = ();
    my %Uniq         = ();
    my $PrimaryKey   = '';
    my @Return       = ();
    for my $Tag (@Param) {

        if (
            ( $Tag-&gt;{Tag} eq 'Table' || $Tag-&gt;{Tag} eq 'TableCreate' )
            &amp;&amp; $Tag-&gt;{TagType} eq 'Start'
            )
        {
            if ( $Self-&gt;{ConfigObject}-&gt;Get('Database::ShellOutput') ) {
                $SQLStart .= $Self-&gt;{'DB::Comment'}
                    . "----------------------------------------------------------\n";
                $SQLStart .= $Self-&gt;{'DB::Comment'} . " create table $Tag-&gt;{Name}\n";
                $SQLStart .= $Self-&gt;{'DB::Comment'}
                    . "----------------------------------------------------------\n";
            }
        }
        if ( $Tag-&gt;{Tag} eq 'Table' || $Tag-&gt;{Tag} eq 'TableCreate' ) {
            if ( $Tag-&gt;{TagType} eq 'Start' ) {
                $SQLStart .= "CREATE TABLE $Tag-&gt;{Name} (\n";
                $TableName = $Tag-&gt;{Name};
            }
            elsif ( $Tag-&gt;{TagType} eq 'End' ) {
                $SQLEnd .= ')';
            }
        }
        elsif ( $Tag-&gt;{Tag} eq 'Column' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            push @Column, $Tag;
        }
        elsif ( $Tag-&gt;{Tag} eq 'Index' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            $IndexCurrent = $Tag-&gt;{Name};
        }
        elsif ( $Tag-&gt;{Tag} eq 'IndexColumn' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            push @{ $Index{$IndexCurrent} }, $Tag;
        }
        elsif ( $Tag-&gt;{Tag} eq 'Unique' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            $UniqCurrent = $Tag-&gt;{Name} || $TableName . '_U_' . int( rand(999) );
        }
        elsif ( $Tag-&gt;{Tag} eq 'UniqueColumn' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            push @{ $Uniq{$UniqCurrent} }, $Tag;
        }
        elsif ( $Tag-&gt;{Tag} eq 'ForeignKey' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            $ForeignKey = $Tag-&gt;{ForeignTable};
        }
        elsif ( $Tag-&gt;{Tag} eq 'Reference' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            push @{ $Foreign{$ForeignKey} }, $Tag;
        }
    }
    for my $Tag (@Column) {

        # type translation
        $Tag = $Self-&gt;_TypeTranslation($Tag);

        # add new line
        if ($SQL) {
            $SQL .= ",\n";
        }

        # normal data type
        $SQL .= "    $Tag-&gt;{Name} $Tag-&gt;{Type}";

        # handle require
        if ( $Tag-&gt;{Required} &amp;&amp; lc $Tag-&gt;{Required} eq 'true' ) {
            $SQL .= ' NOT NULL';
        }
        else {
            $SQL .= ' NULL';
        }

        # handle default
        if ( defined $Tag-&gt;{Default} ) {
            if ( $Tag-&gt;{Type} =~ /int/i ) {
                $SQL .= " DEFAULT " . $Tag-&gt;{Default};
            }
            else {
                $SQL .= " DEFAULT '" . $Tag-&gt;{Default} . "'";
            }
        }

        # auto increment
        if ( $Tag-&gt;{AutoIncrement} &amp;&amp; $Tag-&gt;{AutoIncrement} =~ /^true$/i ) {
            $SQL .= ' AUTO_INCREMENT';
        }

        # add primary key
        if ( $Tag-&gt;{PrimaryKey} &amp;&amp; $Tag-&gt;{PrimaryKey} =~ /true/i ) {
            $PrimaryKey = "    PRIMARY KEY($Tag-&gt;{Name})";
        }
    }

    # add primary key
    if ($PrimaryKey) {
        if ($SQL) {
            $SQL .= ",\n";
        }
        $SQL .= $PrimaryKey;
    }

    # add uniq
    for my $Name ( sort keys %Uniq ) {
        if ($SQL) {
            $SQL .= ",\n";
        }
        $SQL .= "    UNIQUE INDEX $Name (";
        my @Array = @{ $Uniq{$Name} };
        for ( 0 .. $#Array ) {
            if ( $_ &gt; 0 ) {
                $SQL .= ', ';
            }
            $SQL .= $Array[$_]-&gt;{Name};
        }
        $SQL .= ')';
    }

    # add index
    for my $Name ( sort keys %Index ) {
        if ($SQL) {
            $SQL .= ",\n";
        }
        $SQL .= "    INDEX $Name (";
        my @Array = @{ $Index{$Name} };
        for ( 0 .. $#Array ) {
            if ( $_ &gt; 0 ) {
                $SQL .= ', ';
            }
            $SQL .= $Array[$_]-&gt;{Name};
            if ( $Array[$_]-&gt;{Size} ) {
                $SQL .= "($Array[$_]-&gt;{Size})";
            }
        }
        $SQL .= ')';
    }
    $SQL .= "\n";
    push @Return, $SQLStart . $SQL . $SQLEnd;

    # add indexs
    #    for my $Name (sort keys %Index) {
    #        push (@Return, $Self-&gt;IndexCreate(
    #            TableName =&gt; $TableName,
    #            Name =&gt; $Name,
    #            Data =&gt; $Index{$Name},
    #        ));
    #    }
    # add uniq
    #    for my $Name (sort keys %Uniq) {
    #        push (@Return, $Self-&gt;UniqueCreate(
    #            TableName =&gt; $TableName,
    #            Name =&gt; $Name,
    #            Data =&gt; $Uniq{$Name},
    #        ));
    #    }
    # add foreign keys
    for my $ForeignKey ( sort keys %Foreign ) {
        my @Array = @{ $Foreign{$ForeignKey} };
        for ( 0 .. $#Array ) {
            push(
                @{ $Self-&gt;{Post} },
                $Self-&gt;ForeignKeyCreate(
                    LocalTableName   =&gt; $TableName,
                    Local            =&gt; $Array[$_]-&gt;{Local},
                    ForeignTableName =&gt; $ForeignKey,
                    Foreign          =&gt; $Array[$_]-&gt;{Foreign},
                ),
            );
        }
    }
    return @Return;
}

sub TableDrop {
    my ( $Self, @Param ) = @_;

    my $SQL = '';
    for my $Tag (@Param) {
        if ( $Tag-&gt;{Tag} eq 'Table' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            if ( $Self-&gt;{ConfigObject}-&gt;Get('Database::ShellOutput') ) {
                $SQL .= $Self-&gt;{'DB::Comment'}
                    . "----------------------------------------------------------\n";
                $SQL .= $Self-&gt;{'DB::Comment'} . " drop table $Tag-&gt;{Name}\n";
                $SQL .= $Self-&gt;{'DB::Comment'}
                    . "----------------------------------------------------------\n";
            }
        }
        $SQL .= 'DROP TABLE IF EXISTS ' . $Tag-&gt;{Name};
        return ($SQL);
    }
    return ();
}

sub TableAlter {
    my ( $Self, @Param ) = @_;

    my $SQLStart      = '';
    my @SQL           = ();
    my @Index         = ();
    my $IndexName     = '';
    my $ForeignTable  = '';
    my $ReferenceName = '';
    my @Reference     = ();
    my $Table         = '';
    for my $Tag (@Param) {

        if ( $Tag-&gt;{Tag} eq 'TableAlter' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            $Table = $Tag-&gt;{Name} || $Tag-&gt;{NameNew};
            if ( $Self-&gt;{ConfigObject}-&gt;Get('Database::ShellOutput') ) {
                $SQLStart .= $Self-&gt;{'DB::Comment'}
                    . "----------------------------------------------------------\n";
                $SQLStart .= $Self-&gt;{'DB::Comment'} . " alter table $Table\n";
                $SQLStart .= $Self-&gt;{'DB::Comment'}
                    . "----------------------------------------------------------\n";
            }

            # rename table
            if ( $Tag-&gt;{NameOld} &amp;&amp; $Tag-&gt;{NameNew} ) {
                push @SQL, $SQLStart . "ALTER TABLE $Tag-&gt;{NameOld} RENAME $Tag-&gt;{NameNew}";
            }
            $SQLStart .= "ALTER TABLE $Table";
        }
        elsif ( $Tag-&gt;{Tag} eq 'ColumnAdd' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {

            # Type translation
            $Tag = $Self-&gt;_TypeTranslation($Tag);

            # normal data type
            push @SQL, $SQLStart . " ADD $Tag-&gt;{Name} $Tag-&gt;{Type} NULL";

            # investigate the default value
            my $Default = '';
            if ( $Tag-&gt;{Type} =~ /int/i ) {
                $Default = defined $Tag-&gt;{Default} ? $Tag-&gt;{Default} : 0;
            }
            else {
                $Default = defined $Tag-&gt;{Default} ? "'$Tag-&gt;{Default}'" : "''";
            }

            # investigate the require
            my $Required = ( $Tag-&gt;{Required} &amp;&amp; lc $Tag-&gt;{Required} eq 'true' ) ? 1 : 0;

            # handle default and require
            if ( $Required || defined $Tag-&gt;{Default} ) {

                # fill up empty rows
                push @SQL, "UPDATE $Table SET $Tag-&gt;{Name} = $Default WHERE $Tag-&gt;{Name} IS NULL";

                my $SQLAlter = "ALTER TABLE $Table CHANGE $Tag-&gt;{Name} $Tag-&gt;{Name} $Tag-&gt;{Type}";

                # add default
                if ( defined $Tag-&gt;{Default} ) {
                    $SQLAlter .= " DEFAULT $Default";
                }

                # add require
                if ($Required) {
                    $SQLAlter .= ' NOT NULL';
                }
                else {
                    $SQLAlter .= ' NULL';
                }

                push @SQL, $SQLAlter;
            }
        }
        elsif ( $Tag-&gt;{Tag} eq 'ColumnChange' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {

            # Type translation
            $Tag = $Self-&gt;_TypeTranslation($Tag);

            # normal data type
            push @SQL, $SQLStart . " CHANGE $Tag-&gt;{NameOld} $Tag-&gt;{NameNew} $Tag-&gt;{Type} NULL";

            # remove possible default (not on TEXT/BLOB/LONGBLOB type, not supported by mysql)
            if ( $Tag-&gt;{Type} !~ /^(TEXT|MEDIUMTEXT|BLOB|LONGBLOB)$/i ) {
                push @SQL, "ALTER TABLE $Table ALTER $Tag-&gt;{NameNew} DROP DEFAULT";
            }

            # investigate the default value
            my $Default = '';
            if ( $Tag-&gt;{Type} =~ /int/i ) {
                $Default = defined $Tag-&gt;{Default} ? $Tag-&gt;{Default} : 0;
            }
            else {
                $Default = defined $Tag-&gt;{Default} ? "'$Tag-&gt;{Default}'" : "''";
            }

            # investigate the require
            my $Required = ( $Tag-&gt;{Required} &amp;&amp; lc $Tag-&gt;{Required} eq 'true' ) ? 1 : 0;

            # handle default and require
            if ( $Required || defined $Tag-&gt;{Default} ) {

                # fill up empty rows
                push @SQL,
                    "UPDATE $Table SET $Tag-&gt;{NameNew} = $Default WHERE $Tag-&gt;{NameNew} IS NULL";

                my $SQLAlter
                    = "ALTER TABLE $Table CHANGE $Tag-&gt;{NameNew} $Tag-&gt;{NameNew} $Tag-&gt;{Type}";

                # add default
                if ( defined $Tag-&gt;{Default} ) {
                    $SQLAlter .= " DEFAULT $Default";
                }

                # add require
                if ($Required) {
                    $SQLAlter .= ' NOT NULL';
                }
                else {
                    $SQLAlter .= ' NULL';
                }

                push @SQL, $SQLAlter;
            }
        }
        elsif ( $Tag-&gt;{Tag} eq 'ColumnDrop' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            my $SQLEnd = $SQLStart . " DROP $Tag-&gt;{Name}";
            push @SQL, $SQLEnd;
        }
        elsif ( $Tag-&gt;{Tag} =~ /^((Index|Unique)(Create|Drop))/ ) {
            my $Method = $Tag-&gt;{Tag};
            if ( $Tag-&gt;{Name} ) {
                $IndexName = $Tag-&gt;{Name};
            }
            if ( $Tag-&gt;{TagType} eq 'End' ) {
                push @SQL, $Self-&gt;$Method(
                    TableName =&gt; $Table,
                    Name      =&gt; $IndexName,
                    Data      =&gt; \@Index,
                );
                $IndexName = '';
                @Index     = ();
            }
        }
        elsif ( $Tag-&gt;{Tag} =~ /^(IndexColumn|UniqueColumn)/ &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            push @Index, $Tag;
        }
        elsif ( $Tag-&gt;{Tag} =~ /^((ForeignKey)(Create|Drop))/ ) {
            my $Method = $Tag-&gt;{Tag};
            if ( $Tag-&gt;{ForeignTable} ) {
                $ForeignTable = $Tag-&gt;{ForeignTable};
            }
            if ( $Tag-&gt;{TagType} eq 'End' ) {
                for my $Reference (@Reference) {
                    push @SQL, $Self-&gt;$Method(
                        LocalTableName   =&gt; $Table,
                        Local            =&gt; $Reference-&gt;{Local},
                        ForeignTableName =&gt; $ForeignTable,
                        Foreign          =&gt; $Reference-&gt;{Foreign},
                    );
                }
                $ReferenceName = '';
                @Reference     = ();
            }
        }
        elsif ( $Tag-&gt;{Tag} =~ /^(Reference)/ &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            push @Reference, $Tag;
        }
    }

    return @SQL;
}

sub IndexCreate {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    for (qw(TableName Name Data)) {
        if ( !$Param{$_} ) {
            $Self-&gt;{LogObject}-&gt;Log( Priority =&gt; 'error', Message =&gt; "Need $_!" );
            return;
        }
    }

    my $SQL   = "CREATE INDEX $Param{Name} ON $Param{TableName} (";
    my @Array = @{ $Param{Data} };
    for ( 0 .. $#Array ) {
        if ( $_ &gt; 0 ) {
            $SQL .= ', ';
        }
        $SQL .= $Array[$_]-&gt;{Name};
        if ( $Array[$_]-&gt;{Size} ) {
            $SQL .= "($Array[$_]-&gt;{Size})";
        }
    }
    $SQL .= ')';

    # return SQL
    return ($SQL);

}

sub IndexDrop {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    for (qw(TableName Name)) {
        if ( !$Param{$_} ) {
            $Self-&gt;{LogObject}-&gt;Log( Priority =&gt; 'error', Message =&gt; "Need $_!" );
            return;
        }
    }
    my $SQL = 'DROP INDEX ' . $Param{Name} . ' ON ' . $Param{TableName};
    return ($SQL);
}

sub ForeignKeyCreate {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    for (qw(LocalTableName Local ForeignTableName Foreign)) {
        if ( !$Param{$_} ) {
            $Self-&gt;{LogObject}-&gt;Log( Priority =&gt; 'error', Message =&gt; "Need $_!" );
            return;
        }
    }

    # create foreign key name
    my $ForeignKey = "FK_$Param{LocalTableName}_$Param{Local}_$Param{Foreign}";
    if ( length($ForeignKey) &gt; 60 ) {
        my $MD5 = $Self-&gt;{MainObject}-&gt;MD5sum(
            String =&gt; $ForeignKey,
        );
        $ForeignKey = substr $ForeignKey, 0, 58;
        $ForeignKey .= substr $MD5, 0,  1;
        $ForeignKey .= substr $MD5, 61, 1;
    }

    # add foreign key
    my $SQL = "ALTER TABLE $Param{LocalTableName} ADD CONSTRAINT $ForeignKey FOREIGN KEY "
        . "($Param{Local}) REFERENCES $Param{ForeignTableName} ($Param{Foreign})";

    return ($SQL);
}

sub ForeignKeyDrop {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    for (qw(LocalTableName Local ForeignTableName Foreign)) {
        if ( !$Param{$_} ) {
            $Self-&gt;{LogObject}-&gt;Log( Priority =&gt; 'error', Message =&gt; "Need $_!" );
            return;
        }
    }

    # create foreign key name
    my $ForeignKey = "FK_$Param{LocalTableName}_$Param{Local}_$Param{Foreign}";
    if ( length($ForeignKey) &gt; 60 ) {
        my $MD5 = $Self-&gt;{MainObject}-&gt;MD5sum(
            String =&gt; $ForeignKey,
        );
        $ForeignKey = substr $ForeignKey, 0, 58;
        $ForeignKey .= substr $MD5, 0,  1;
        $ForeignKey .= substr $MD5, 61, 1;
    }

    # drop foreign key
    my @SQL;

    if ( $Self-&gt;{ConfigObject}-&gt;Get('Database::ShellOutput') ) {
        push @SQL, $Self-&gt;{'DB::Comment'}
            . ' MySQL does not create foreign key constraints in MyISAM. Dropping nonexisting constraints in MyISAM works just fine.';
        push @SQL, $Self-&gt;{'DB::Comment'}
            . ' However, if the table is converted to InnoDB, this will result in an error. Therefore, only drop constraints if they exist.';
    }

    push @SQL,
        "SET \@FKExists := (SELECT COUNT(*) FROM information_schema.table_constraints WHERE table_schema = DATABASE() AND table_name = '$Param{LocalTableName}' AND constraint_name = '$ForeignKey')";
    push @SQL,
        "SET \@FKSQLStatement := IF( \@FKExists &gt; 0, 'ALTER TABLE $Param{LocalTableName} DROP FOREIGN KEY $ForeignKey', 'SELECT ''INFO: Foreign key constraint $ForeignKey does not exist, skipping.''' )";
    push @SQL, "PREPARE FKStatement FROM \@FKSQLStatement";
    push @SQL, "EXECUTE FKStatement";

    return @SQL;
}

sub UniqueCreate {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    for (qw(TableName Name Data)) {
        if ( !$Param{$_} ) {
            $Self-&gt;{LogObject}-&gt;Log( Priority =&gt; 'error', Message =&gt; "Need $_!" );
            return;
        }
    }
    my $SQL   = "ALTER TABLE $Param{TableName} ADD CONSTRAINT $Param{Name} UNIQUE INDEX (";
    my @Array = @{ $Param{Data} };
    for ( 0 .. $#Array ) {
        if ( $_ &gt; 0 ) {
            $SQL .= ', ';
        }
        $SQL .= $Array[$_]-&gt;{Name};
    }
    $SQL .= ')';

    # return SQL
    return ($SQL);

}

sub UniqueDrop {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    for (qw(TableName Name)) {
        if ( !$Param{$_} ) {
            $Self-&gt;{LogObject}-&gt;Log( Priority =&gt; 'error', Message =&gt; "Need $_!" );
            return;
        }
    }
    my $SQL = 'ALTER TABLE ' . $Param{TableName} . ' DROP INDEX ' . $Param{Name};
    return ($SQL);
}

sub Insert {
    my ( $Self, @Param ) = @_;

    my $SQL    = '';
    my @Keys   = ();
    my @Values = ();
    for my $Tag (@Param) {
        if ( $Tag-&gt;{Tag} eq 'Insert' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            if ( $Self-&gt;{ConfigObject}-&gt;Get('Database::ShellOutput') ) {
                $SQL .= $Self-&gt;{'DB::Comment'}
                    . "----------------------------------------------------------\n";
                $SQL .= $Self-&gt;{'DB::Comment'} . " insert into table $Tag-&gt;{Table}\n";
                $SQL .= $Self-&gt;{'DB::Comment'}
                    . "----------------------------------------------------------\n";
            }
            $SQL .= "INSERT INTO $Tag-&gt;{Table} ";
        }
        if ( $Tag-&gt;{Tag} eq 'Data' &amp;&amp; $Tag-&gt;{TagType} eq 'Start' ) {
            $Tag-&gt;{Key} = ${ $Self-&gt;Quote( \$Tag-&gt;{Key} ) };
            push @Keys, $Tag-&gt;{Key};
            my $Value;
            if ( defined $Tag-&gt;{Value} ) {
                $Value = $Tag-&gt;{Value};
                $Self-&gt;{LogObject}-&gt;Log(
                    Priority =&gt; 'error',
                    Message  =&gt; 'The content for inserts is not longer appreciated '
                        . 'attribut Value, use Content from now on! Reason: You can\'t '
                        . 'use new lines in attributes.',
                );
            }
            elsif ( defined $Tag-&gt;{Content} ) {
                $Value = $Tag-&gt;{Content};
            }
            else {
                $Value = '';
            }
            if ( $Tag-&gt;{Type} &amp;&amp; $Tag-&gt;{Type} eq 'Quote' ) {
                $Value = '\'' . ${ $Self-&gt;Quote( \$Value ) } . '\'';
            }
            else {
                $Value = ${ $Self-&gt;Quote( \$Value ) };
            }
            push @Values, $Value;
        }
    }
    my $Key = '';
    for (@Keys) {
        if ( $Key ne '' ) {
            $Key .= ', ';
        }
        $Key .= $_;
    }
    my $Value = '';
    for my $Tmp (@Values) {
        if ( $Value ne '' ) {
            $Value .= ', ';
        }
        if ( $Tmp eq 'current_timestamp' ) {
            if ( $Self-&gt;{ConfigObject}-&gt;Get('Database::ShellOutput') ) {
                $Value .= $Tmp;
            }
            else {
                my $Timestamp = $Self-&gt;{TimeObject}-&gt;CurrentTimestamp();
                $Value .= '\'' . $Timestamp . '\'';
            }
        }
        else {
            $Value .= $Tmp;
        }
    }
    $SQL .= "($Key)\n    VALUES\n    ($Value)";
    return ($SQL);
}

sub _TypeTranslation {
    my ( $Self, $Tag ) = @_;

    if ( $Tag-&gt;{Type} =~ /^DATE$/i ) {
        $Tag-&gt;{Type} = 'DATETIME';
    }
    if ( $Tag-&gt;{Type} =~ /^VARCHAR$/i ) {
        if ( $Tag-&gt;{Size} &gt; 16777215 ) {
            $Tag-&gt;{Type} = 'LONGTEXT';
        }
        elsif ( $Tag-&gt;{Size} &gt; 65535 ) {
            $Tag-&gt;{Type} = 'MEDIUMTEXT';
        }
        elsif ( $Tag-&gt;{Size} &gt; 255 ) {
            $Tag-&gt;{Type} = 'TEXT';
        }
        else {
            $Tag-&gt;{Type} = 'VARCHAR (' . $Tag-&gt;{Size} . ')';
        }
    }
    if ( $Tag-&gt;{Type} =~ /^DECIMAL$/i ) {
        $Tag-&gt;{Type} = 'DECIMAL (' . $Tag-&gt;{Size} . ')';
    }
    return $Tag;
}

1;
</pre></body></html>