blob: a7364dbd7816743ed1d2656bc607fdfdf4c1f569 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#!/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 = <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!';
|