15412b1135
Nalezy napisac mechanizm obslogujacy rezerwacje ksiazek.
58 lines
1.3 KiB
Perl
Executable file
58 lines
1.3 KiB
Perl
Executable file
#!/usr/bin/perl -w
|
|
#Skrypt nie dokonczony, nie dziala
|
|
|
|
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 = <STDIN>;
|
|
chomp $isbn;
|
|
print 'Podaj tytul:';
|
|
my $title = <STDIN>;
|
|
chomp $title;
|
|
$title='\''.$title.'\'';
|
|
print 'Podaj autora:';
|
|
my $author = <STDIN>;
|
|
chomp $author;
|
|
$author = '\''.$author.'\'';
|
|
print 'Podaj wlasciciela:';
|
|
my $owner = <STDIN>;
|
|
chomp $owner;
|
|
$owner = '\''.$owner.'\'';
|
|
print 'Czy ksiazke mozna pozyczac?:';
|
|
my $can_borrow = <STDIN>;
|
|
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 = <STDIN>;
|
|
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!';
|