#!/usr/bin/perl -w use warnings; use strict; use strict 'vars'; use DBI; my $dbfile = 'ksiazki.db'; my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", ""); my $sth=$dbh->prepare("select * from ksiazki where id=(select max(id) from ksiazki)"); $sth->execute; (my @dupa)=$sth->fetchall_arrayref; my $max_id = ${$dupa[0]}[0][0]; my $id=$max_id+1; #Nowe id tworzymy, biorac stare najwieksze i dodajac 1 print 'Podaj isbn:'; my $isbn = ; chomp $isbn; print 'Podaj tytul:'; my $title = ; chomp $title; $title='\''.$title.'\''; print 'Podaj autora:'; my $author = ; chomp $author; $author = '\''.$author.'\''; print 'Podaj wlasciciela:'; my $owner = ; chomp $owner; $owner = '\''.$owner.'\''; print 'Czy ksiazke mozna pozyczac?:'; my $can_borrow = ; chomp $can_borrow; while (1) { if ($can_borrow eq 'Tak') { $can_borrow = 1; last; } elsif ($can_borrow eq 'Nie') { $can_borrow = 0; last; } else { print 'Odpowiedz Tak lub Nie!'; $can_borrow = ; chomp $can_borrow; } } $sth=$dbh->prepare("insert into ksiazki values($id,$isbn,$title,$author,$owner,1,$can_borrow)"); #Zakladamy, ze dodawana ksiazka jest na miejscu, #wiec zamiast sie o to pytac, wpisuje, ze jest. $sth->execute or die 'Blad przy pisaniu do bazy!';