summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
author-m <example.com>2013-03-19 19:52:26 +0100
committer-m <example.com>2013-03-19 19:52:26 +0100
commitebd870b596a67a55ef3411765fd69504d95fad09 (patch)
tree96deed663f473f212fad4a0ef78bb8adc1b289ef /bin
downloadBiblioteka-ebd870b596a67a55ef3411765fd69504d95fad09.tar.gz
Biblioteka-ebd870b596a67a55ef3411765fd69504d95fad09.tar.bz2
Biblioteka-ebd870b596a67a55ef3411765fd69504d95fad09.tar.xz
Biblioteka-ebd870b596a67a55ef3411765fd69504d95fad09.zip
initial version
Diffstat (limited to 'bin')
-rw-r--r--bin/.add_book.pl.swpbin0 -> 12288 bytes
-rw-r--r--bin/.app.pl.swpbin0 -> 12288 bytes
-rw-r--r--bin/a.dbbin0 -> 3072 bytes
-rwxr-xr-xbin/add_book.pl15
-rwxr-xr-xbin/app.pl66
-rwxr-xr-xbin/app.pl.backup63
-rw-r--r--bin/ksiazki.dbbin0 -> 3072 bytes
-rw-r--r--bin/ksiazki.db.backupbin0 -> 2048 bytes
-rw-r--r--bin/ksiazki.db.backup1bin0 -> 2048 bytes
-rwxr-xr-xbin/test_sql.pl21
10 files changed, 165 insertions, 0 deletions
diff --git a/bin/.add_book.pl.swp b/bin/.add_book.pl.swp
new file mode 100644
index 0000000..328055c
--- /dev/null
+++ b/bin/.add_book.pl.swp
Binary files differ
diff --git a/bin/.app.pl.swp b/bin/.app.pl.swp
new file mode 100644
index 0000000..66f43e2
--- /dev/null
+++ b/bin/.app.pl.swp
Binary files differ
diff --git a/bin/a.db b/bin/a.db
new file mode 100644
index 0000000..3b19ecf
--- /dev/null
+++ b/bin/a.db
Binary files differ
diff --git a/bin/add_book.pl b/bin/add_book.pl
new file mode 100755
index 0000000..13cf934
--- /dev/null
+++ b/bin/add_book.pl
@@ -0,0 +1,15 @@
+#!/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];
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;
diff --git a/bin/app.pl.backup b/bin/app.pl.backup
new file mode 100755
index 0000000..f0df067
--- /dev/null
+++ b/bin/app.pl.backup
@@ -0,0 +1,63 @@
+#!/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;
diff --git a/bin/ksiazki.db b/bin/ksiazki.db
new file mode 100644
index 0000000..ff6d6ee
--- /dev/null
+++ b/bin/ksiazki.db
Binary files differ
diff --git a/bin/ksiazki.db.backup b/bin/ksiazki.db.backup
new file mode 100644
index 0000000..a4d24f2
--- /dev/null
+++ b/bin/ksiazki.db.backup
Binary files differ
diff --git a/bin/ksiazki.db.backup1 b/bin/ksiazki.db.backup1
new file mode 100644
index 0000000..f6880b5
--- /dev/null
+++ b/bin/ksiazki.db.backup1
Binary files differ
diff --git a/bin/test_sql.pl b/bin/test_sql.pl
new file mode 100755
index 0000000..5c4b2a3
--- /dev/null
+++ b/bin/test_sql.pl
@@ -0,0 +1,21 @@
+#!/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();