| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | # | ||
| 4 | # This script was initialy used to fill the db | ||
| 5 | # used by the test with test data. | ||
| 6 | # | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use warnings; | ||
| 10 | |||
| 11 | use DBI; | ||
| 12 | |||
| 13 | my $db = '../t/lexicon.db'; | ||
| 14 | |||
| 15 | die "SQLite database $db not found: $!" unless -f $db; | ||
| 16 | |||
| 17 | my $dbh = DBI->connect("dbi:SQLite:dbname=$db", "", "", { AutoCommit => 1, PrintError => 0, }); | ||
| 18 | |||
| 19 | my @lexicon = ( | ||
| 20 | { id => 1, lex => '*', lang => 'de', lex_key => 'Hello World!', lex_value => 'Hallo Welt!', }, | ||
| 21 | { id => 2, lex => '*', lang => 'en', lex_key => 'Hello World!', lex_value => 'Hello World!', }, | ||
| 22 | { id => 3, lex => '*', lang => 'de', lex_key => 'This is a [_1].', lex_value => 'Dies ist ein [_1].', }, | ||
| 23 | { id => 4, lex => '*', lang => 'en', lex_key => 'This is a [_1].', lex_value => 'This is a [_1].', }, | ||
| 24 | { id => 5, lex => 'foo', lang => 'de', lex_key => 'Lex Foo', lex_value => 'Lexikon "foo", de', }, | ||
| 25 | { id => 6, lex => 'foo', lang => 'en', lex_key => 'Lex Foo', lex_value => 'Lexicon "foo", en', }, | ||
| 26 | ); | ||
| 27 | |||
| 28 | $dbh->do("DELETE FROM `lexicon`;"); | ||
| 29 | |||
| 30 | foreach (@lexicon) { | ||
| 31 | $dbh->do( "INSERT INTO `lexicon` (`id`, `lang`, `lex`, `lex_key`, `lex_value`) VALUES ('" | ||
| 32 | . $_->{id} . "', '" | ||
| 33 | . $_->{lang} . "', '" | ||
| 34 | . $_->{lex} . "', '" | ||
| 35 | . $_->{lex_key} . "', '" | ||
| 36 | . $_->{lex_value} | ||
| 37 | . "');"); | ||
| 38 | |||
| 39 | if ($dbh->err()) { die "$DBI::errstr\n"; } | ||
| 40 | } | ||
| 41 | |||
| 42 | $dbh->disconnect(); |