Usunąłem zbędne pliki.
parent
8179e55fe0
commit
05e4f5b64a
|
@ -1,63 +0,0 @@
|
|||
#!/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;
|
||||
|
||||
while (($id[$i],$isbn[$i],$title[$i],$author[$i],$owner[$i],$state[$i],$type[$i])=$sth->fetchrow_array)
|
||||
{
|
||||
$result=$result.$id[$i].'|'.$isbn[$i].'|'.$title[$i].'|'.$author[$i].'|'.$owner[$i].'|'.$state[$i].'|'.$type[$i].'<br>'."\n";
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $result;
|
||||
};
|
||||
|
||||
get '/req/:book' => sub
|
||||
{
|
||||
my $id=params->{book};
|
||||
my $sth;
|
||||
|
||||
$sth=$dbh->prepare("select type from ksiazki where id=$id");
|
||||
$sth->execute();
|
||||
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;
|
Binary file not shown.
Binary file not shown.
|
@ -1,21 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use DBI;
|
||||
|
||||
my $dbfile = 'a.db';
|
||||
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
|
||||
|
||||
#$dbh->do("create table abc (int a)");
|
||||
#$dbh->do("insert into abc values (7)");
|
||||
#print $dbh->do("select * from abc");
|
||||
|
||||
|
||||
#my $sth = $dbh->prepare("select * from abc"); # prepare the query
|
||||
#$sth->execute(); # execute the query
|
||||
#my @row;
|
||||
#while (@row = $sth->fetchrow_array) { # retrieve one row
|
||||
# print join("\n", @row), "\n";
|
||||
#}
|
||||
|
||||
my $sth = $dbh->prepare ("update qwe set liczba=20 where id=2");
|
||||
$sth->execute();
|
Loading…
Reference in New Issue