diff options
author | -m <example.com> | 2013-03-19 19:52:26 +0100 |
---|---|---|
committer | -m <example.com> | 2013-03-19 19:52:26 +0100 |
commit | ebd870b596a67a55ef3411765fd69504d95fad09 (patch) | |
tree | 96deed663f473f212fad4a0ef78bb8adc1b289ef /bin/app.pl | |
download | Biblioteka-ebd870b596a67a55ef3411765fd69504d95fad09.tar.gz Biblioteka-ebd870b596a67a55ef3411765fd69504d95fad09.tar.bz2 Biblioteka-ebd870b596a67a55ef3411765fd69504d95fad09.tar.xz Biblioteka-ebd870b596a67a55ef3411765fd69504d95fad09.zip |
initial version
Diffstat (limited to 'bin/app.pl')
-rwxr-xr-x | bin/app.pl | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/bin/app.pl b/bin/app.pl new file mode 100755 index 0000000..8a5045b --- /dev/null +++ b/bin/app.pl @@ -0,0 +1,66 @@ +#!/usr/bin/env perl +use warnings; +use strict; +use Dancer; +use DBI; + +#Struktura bazy +#id, int; isbn, int; tytul, string; autor, string; owner, string; state, bool (czy pozyczona, 0=dostepna, 1=wzieta); type, bool (mozna brac ze soba? 1=tak, 0=nie) + +my $dbfile = 'ksiazki.db'; +my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", ""); + +get '/' => sub +{ + my $sth = $dbh->prepare("select * from ksiazki"); + $sth->execute(); + + my @id; + my @isbn; + my @title; + my @author; + my @owner; + my @state; + my @type; + + #my $result=''; #Poniewaz trzeba zwrocic string, wartosci kolejno pobierane z bazy, + #beda dodawane do zmiennej ze stringiem, na razie pustym + my $i=0; + my @result; + my $ii=0; + + (@result)=@{$sth->fetchall_arrayref} or die "blad przy pobieraniu danych"; + + # |kolejne rekordy|kolejne pola rekordow + #return ${$result[2]}[4]; + template 'a.tt', + { + 'table' => \@result + } +}; + +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; + if ($type == 1) + { + $sth = $dbh->prepare("update ksiazki set state=not state where id=?"); + $sth->execute($id); + return 0; + } + elsif ($type == 0) + { + return 1; + } + else #Stalo sie cos dziwnego... + { + return "OMGLOLWTF"; + } +}; + +dance; |