This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/senddatatodb.pl

39 lines
1.1 KiB
Perl
Raw Normal View History

2016-08-12 16:10:42 +00:00
#!/usr/bin/env perl
use Mojolicious::Lite;
# connect to database
use DBI;
my $dbh = DBI->connect("dbi:SQLite:dbname=foodloop.db") or die "Could not connect";
2016-08-12 16:10:42 +00:00
# shortcut for use in template
helper db => sub { $dbh };
# setup base route
#any '/' => 'index';
2016-08-12 16:10:42 +00:00
my $insert;
while (1) {
# create insert statement
$insert = eval { $dbh->prepare('INSERT INTO foodloop (user, company, currency, filename) VALUES (?,?,?,?)') };
2016-08-12 16:10:42 +00:00
# break out of loop if statement prepared
last if $insert;
# if statement didn't prepare, assume its because the table doesn't exist
warn "Creating table 'foodloop'\n";
$dbh->do('CREATE TABLE foodloop (user varchar(255), company varchar(255), currency int, filename varchar(255));');
}
# setup route which receives data and returns to /
post '/' => sub {
my $self = shift;
my $user = $self->param('user');
my $company = $self->param('company');
my $currency = $self->param('currency');
my $file = $self->req->upload('file');
$insert->execute($user, $company, $currency, $file->filename);
2016-08-12 16:10:42 +00:00
$self->render(text => 'It did not kaboom!');
};
app->start;