From ab265f85673b2eaa1f9de108ad962dba602b71de Mon Sep 17 00:00:00 2001 From: Stefan Suhren Date: Fri, 8 Jan 2016 18:17:14 +0100 Subject: Make errors more descriptive --- Aufgabe7/db-passwd-create.pl | 4 ++-- Aufgabe7/db-passwd-fill-table.pl | 6 +++--- Aufgabe7/db-passwd-read-table.pl | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'Aufgabe7') diff --git a/Aufgabe7/db-passwd-create.pl b/Aufgabe7/db-passwd-create.pl index 0c9c470..5a43831 100644 --- a/Aufgabe7/db-passwd-create.pl +++ b/Aufgabe7/db-passwd-create.pl @@ -28,7 +28,7 @@ use DBI; # Get database config my %dbconf = do 'dbinc.pl'; -my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}) or die 'DB not accessible'; +my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}, {RaiseError=>1}) or die 'DB not accessible'; #Create DB $dbhandle->do("CREATE TABLE stsuh_passwort @@ -43,6 +43,6 @@ $dbhandle->do("CREATE TABLE stsuh_passwort commandinterpreter CHAR(255), PRIMARY KEY (nr) ) -") or die 'Could not create database'; +") or die $dbhandle->errstr; $dbhandle->disconnect; diff --git a/Aufgabe7/db-passwd-fill-table.pl b/Aufgabe7/db-passwd-fill-table.pl index c33f89a..0b79693 100644 --- a/Aufgabe7/db-passwd-fill-table.pl +++ b/Aufgabe7/db-passwd-fill-table.pl @@ -28,9 +28,9 @@ use DBI; # Get database config my %dbconf = do 'dbinc.pl'; -my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}) or die 'DB not accessible'; +my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}, {RaiseError=>1}) or die 'DB not accessible'; -my $passwdInsertSth = $dbhandle->prepare("INSERT INTO stsuh_passwort (loginname, password, uid, gid, comment, homedir, commandinterpreter) VALUES (?, ?, ?, ?, ?, ?, ?)") or die 'Preparation failed'; +my $passwdInsertSth = $dbhandle->prepare("INSERT INTO stsuh_passwort (loginname, password, uid, gid, comment, homedir, commandinterpreter) VALUES (?, ?, ?, ?, ?, ?, ?)") or die $dbhandle->errstr; my $passwdFile_file_name = 'passwd'; # input file name @@ -43,7 +43,7 @@ while (<$passwdFile>) chomp @passwdLine; - $passwdInsertSth->execute(@passwdLine) or die 'Execution failed'; + $passwdInsertSth->execute(@passwdLine) or die $dbhandle->errstr; } close $passwdFile diff --git a/Aufgabe7/db-passwd-read-table.pl b/Aufgabe7/db-passwd-read-table.pl index 8e06a80..e7290b8 100644 --- a/Aufgabe7/db-passwd-read-table.pl +++ b/Aufgabe7/db-passwd-read-table.pl @@ -28,9 +28,9 @@ use DBI; # Get database config my %dbconf = do 'dbinc.pl'; -my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}) or die 'DB not accessible'; +my $dbhandle = DBI->connect("DBI:mysql:host=$dbconf{dbhost};database=$dbconf{dbdatabase}", $dbconf{dbuser}, $dbconf{dbpasswd}, {RaiseError=>1}) or die 'DB not accessible'; -my $passwdArray = $dbhandle->selectall_arrayref("SELECT * FROM stsuh_passwort"); +my $passwdArray = $dbhandle->selectall_arrayref("SELECT * FROM stsuh_passwort") or die $dbhandle->errstr; printf ("%-4s | %-13s | %-8s | %-6s | %-6s | %-35s | %-25s | %-20s\n", "nr", "loginname", "password", "uid", "gid", "comment", "homedir", "commandinterpreter"); printf ('%1$s'x140 . "\n", "-"); -- cgit v1.2.3-70-g09d2