0
sub connect_db {
       my $dbh = DBI->connect("dbi:SQLite:dbname=".setting('database')) or
               die $DBI::errstr;

       return $dbh;
}

sub init_db {
       my $db = connect_db();
       my $schema = read_file('./schema.sql');
       $db->do($schema) or die $db->errstr;
}


get '/' => sub {
       my $db = connect_db();
       my $sql = 'select id, title, text from entries order by id desc';
       my $sth = $db->prepare($sql) or die $db->errstr;
       $sth->execute or die $sth->errstr;
       template 'show_entries.tt', {
               'msg' => get_flash(),
               'add_entry_url' => uri_for('/add'),
               'entries' => $sth->fetchall_hashref('id'),
       };
};

Why after reboot system entries in database not saved ? Size databases not increment. why is this happening ?

Dima Candu
  • 25
  • 1
  • 6

1 Answers1

0

The sample script https://github.com/PerlDancer/dancer-tutorial/blob/master/dancr.pl, which you're probably using, is explicitly creating the database file in the default temporary directory:

set 'database' => File::Spec->catfile(File::Spec->tmpdir(), 'dancr.db');

Probably your system in configured to clean /tmp (or whatever the temporary directory is) after reboots, or maybe /tmp is located on a memory file system.

If you want a persistent database, then change the location of the database.

Slaven Rezic
  • 4,571
  • 14
  • 12
  • Then i have the following question, Why was it necessary to create a database use this code $ cat - | sqlite3 database create table if not exists entries ( id integer primary key autoincrement, title string not null, text string not null ); ^D – Dima Candu Sep 22 '13 at 19:09
  • This is a new question. – Slaven Rezic Sep 22 '13 at 19:14