Code

Updated buttons
[gosa.git] / gosa-si / modules / DBmysql.pm
index 6d5648d9e00472fa20d2077a86178f536662c1fc..7a7f67f7e36c5c7c9738fafeeef1cfb017809181 100644 (file)
@@ -11,9 +11,13 @@ my $col_names = {};
 
 sub new {
     my $class = shift;
+    my $database = shift;
+    my $host = shift;
+    my $username = shift;
+    my $password = shift;
 
     my $self = {dbh=>undef};
-    my $dbh = DBI->connect("dbi:mysql:database=$main::mysql_database;host=$main::mysql_host", $main::mysql_username, $main::mysql_password,{ RaiseError => 1, AutoCommit => 1 });
+    my $dbh = DBI->connect("dbi:mysql:database=$database;host=$host", $username, $password,{ RaiseError => 1, AutoCommit => 1 });
                $dbh->{mysql_auto_reconnect} = 1;
     $self->{dbh} = $dbh;
     bless($self,$class);
@@ -33,7 +37,7 @@ sub create_table {
        if($recreate_table) {
                $self->{dbh}->do("DROP TABLE $table_name");
        }
-       my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )"; 
+       my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string ) ENGINE=INNODB"; 
        # &main::daemon_log("DEBUG: $sql_statement");
        eval {
                $self->{dbh}->do($sql_statement);
@@ -249,26 +253,26 @@ sub exec_statement {
        my @db_answer;
 
        # print STDERR Dumper($sql_statement);
-       eval {
+#      eval {
                if($sql_statement =~ /^SELECT/i) {
-                       $sth = $self->{dbh}->prepare($sql_statement) or &main::daemon_log("ERROR: Preparation of statement '$sql_statement' failed!", 1);
-                       $sth->execute or &main::daemon_log("ERROR: Execution of statement '$sql_statement' failed!", 1);
+                       $sth = $self->{dbh}->prepare($sql_statement) or &main::daemon_log("ERROR: Preparation of statement '$sql_statement' failed!", 1);
+                       $sth->execute or &main::daemon_log("ERROR: Execution of statement '$sql_statement' failed!", 1);
                        if($sth->rows > 0) {
-                               @db_answer = @{ $sth->fetchall_arrayref() } or &main::daemon_log("ERROR: Fetch() failed!", 1);
+                               @db_answer = @{ $sth->fetchall_arrayref() } or &main::daemon_log("ERROR: Fetch() failed!", 1);
                                # print STDERR Dumper(@db_answer);
                        }
-                       $sth->finish or &main::daemon_log("ERROR: Finishing the statement handle failed!", 1);
+                       $sth->finish or &main::daemon_log("ERROR: Finishing the statement handle failed!", 1);
                } else {
                        $self->{dbh}->do($sql_statement);
                }
-       };
-       if($@) {
-               &main::daemon_log("ERROR: $sql_statement failed with '$@'", 1);
-       }
+#      };
+#      if($@) {
+#              &main::daemon_log("0 ERROR: '$sql_statement' failed with '$@'", 1);
+#      }
        # TODO : maybe an error handling and an erro feedback to invoking function
        my $error = $self->{dbh}->err;
        if ($error) {
-               &main::daemon_log("ERROR: ".@$self->{dbh}->errstr, 1);
+               &main::daemon_log("ERROR: ".@$self->{dbh}->errstr, 1);
        }
 
        return \@db_answer;