diff options
Diffstat (limited to 'bin/app.pl')
-rwxr-xr-x | bin/app.pl | 21 |
1 files changed, 8 insertions, 13 deletions
@@ -13,13 +13,10 @@ my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", ""); get '/' => sub { - my $sth = $dbh->prepare("select * from ksiazki"); - $sth->execute(); - - my $i=0; + my $sth = $dbh->prepare("select * from ksiazki;") or die "Nie mozna spreparowac zapytania"; + $sth->execute() or die "Nie mozna wykonac zapytania"; + #my $sth=$dbh->do("select * from ksiazki"); my @result; - my $ii=0; - (@result)=@{$sth->fetchall_arrayref} or die "blad przy pobieraniu danych"; # |kolejne rekordy|kolejne pola rekordow @@ -35,13 +32,13 @@ get '/req/:book' => sub my $id=params->{book}; my $sth; - $sth=$dbh->prepare("select type from ksiazki where id=?"); - $sth->execute($id); - my $type = $sth->fetchrow_array; + $sth=$dbh->prepare("select type from ksiazki where id=?") or die "Nie mozna spreparowac zapytania"; + $sth->execute($id) or die "Nie mozna wykonac"; + my $type = $sth->fetchrow_array or die "Nie mozna pobrac danych"; if ($type == 1) { - $sth = $dbh->prepare("update ksiazki set state=not state where id=?"); - $sth->execute($id); + $sth = $dbh->prepare("update ksiazki set state=not state where id=?") or die "Nie mozna spreparowac zapytania"; + $sth->execute($id) or die "Nie mozna wykonac zapytania"; return 0; } elsif ($type == 0) @@ -54,7 +51,5 @@ get '/req/:book' => sub } }; -$sth->finish(); -$dbh->disconnect(); dance; |