summaryrefslogtreecommitdiff
path: root/DBI_sqlite_alternative.pm
diff options
context:
space:
mode:
authoryo mama <pepper@scannerjammer.com>2015-03-23 15:57:09 -0700
committeryo mama <pepper@scannerjammer.com>2015-03-23 15:57:09 -0700
commit00c7f6129f87d77788aa92e08dd77b7b473f9a71 (patch)
tree476e7f456fb3138d17927ce0ff3fea7b1a8f0060 /DBI_sqlite_alternative.pm
parent1cc8609a5976d3f394ac0f36fd1322ee8e6e4eea (diff)
moved things around
Diffstat (limited to 'DBI_sqlite_alternative.pm')
-rwxr-xr-xDBI_sqlite_alternative.pm59
1 files changed, 0 insertions, 59 deletions
diff --git a/DBI_sqlite_alternative.pm b/DBI_sqlite_alternative.pm
deleted file mode 100755
index 83c9d41..0000000
--- a/DBI_sqlite_alternative.pm
+++ /dev/null
@@ -1,59 +0,0 @@
-package journal_database;
-use DBD::SQLite;
-use DBI;
-use Data::Dumper;
-my $dbh = DBI->connect("dbi:SQLite:dbname=journals.db","","");
-
-
-CREATE TABLE journals(
- id INTEGER PRIMARY KEY NOT NULL, --optional
- date INTEGER NOT NULL,
- fulltext TEXT,
- image_url TEXT
-);
-
-sub remove_from_db{
- my $id_to_remove = shift;
- my $sth = $dbh->prepare(
- "DELETE FROM journals ".
- "WHERE id=$id_to_remove;"
- );
- $sth->execute();
-}
-sub get_entry_by_date {
- my $date_int = shift;
- my $sth = $dbh->prepare(
- "SELECT *".
- "FROM journals ".
- "WHERE `date`=? "
- );
- $sth->execute($date_int);
- return $sth->fetchrow_hashref();
-}
-
-sub add_journal_entry{
- my $entry = shift;
- my $sqlCmd = "insert into journals values (?,?,?,?);" ;
-# ."on duplicate key update ".
-# "id = ?,".
-# "date = ?,".
-# "fulltext = ?,".
-# "image_url = ?,".
-# ";";
- my $sth = $dbh->do($sqlCmd,
- undef,
- $entry->{id},
- $entry->{date} || time(),
- $entry->{fulltext},
- $entry->{image_url}
- );
- }
-
- my $entry = {};
- $entry->{id} = '12';
- $entry->{date} = '123432';
- $entry->{fulltext} = 'this is a test of the fulltext';
- $entry->{image_url} = 'this is a test of the image url';
- add_journal_entry($entry);
- print Dumper get_entry_by_date(123432);
- remove_from_db(12);