summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2010-03-07 23:30:22 (GMT)
committerDavid A. Madore <david+git@madore.org>2010-03-07 23:30:22 (GMT)
commitb8e0d8ef0c8513c18b010218f704df10420d7726 (patch)
treee42f8bbd1246a0f60eef3f547ee3a056ff211ca8
parent30726d6fabbd3e683245391c6c0abb1d7b946899 (diff)
downloadblogengine-b8e0d8ef0c8513c18b010218f704df10420d7726.zip
blogengine-b8e0d8ef0c8513c18b010218f704df10420d7726.tar.gz
blogengine-b8e0d8ef0c8513c18b010218f704df10420d7726.tar.bz2
Add categories to entry database.
-rwxr-xr-xinsert-entries.pl13
-rw-r--r--weblog.sql7
2 files changed, 19 insertions, 1 deletions
diff --git a/insert-entries.pl b/insert-entries.pl
index 8e81893..427e8da 100755
--- a/insert-entries.pl
+++ b/insert-entries.pl
@@ -92,7 +92,7 @@ if ( defined($ARGV[0]) ) {
my $dbh = DBI->connect("dbi:Pg:dbname=$dbname", "", "", {AutoCommit=>1,RaiseError=>1,pg_enable_utf8=>1});
$dbh->do("SET TIME ZONE 0");
-my ($sth_check, $sth_insert, $sth_update);
+my ($sth_check, $sth_insert, $sth_update, $sth_clear_cat, $sth_set_cat);
$sth_check = $dbh->prepare("SELECT sha1 FROM entries WHERE id=?");
if ( $obtain_cdates ) {
$sth_insert = $dbh->prepare("INSERT INTO entries(id,edate,lang,title,content,sha1,cdate) VALUES (?,?,?,?,?,?,?)");
@@ -101,6 +101,8 @@ if ( $obtain_cdates ) {
$sth_insert = $dbh->prepare("INSERT INTO entries(id,edate,lang,title,content,sha1) VALUES (?,?,?,?,?,?)");
$sth_update = $dbh->prepare("UPDATE entries SET (edate,mdate,lang,title,content,sha1)=(?,DEFAULT,?,?,?,?) WHERE id=?");
}
+$sth_clear_cat = $dbh->prepare("DELETE FROM incat WHERE id=?");
+$sth_set_cat = $dbh->prepare("INSERT INTO incat(id,code) VALUES (?,?)");
sub get_node_lang {
my $node = shift;
@@ -119,6 +121,7 @@ my $entry_list = $xpc->findnodes("//weblog/entry");
foreach my $node ( $entry_list->get_nodelist ) {
my $id = $node->getAttribute("number")+0;
my $date = $node->getAttribute("date");
+ my $catlist = $node->getAttribute("cat");
my $lang = get_node_lang $node;
$node->setAttributeNS(XML_XML_NS, "lang", $lang) if defined($lang);
my $str = $node->serialize();
@@ -136,6 +139,7 @@ foreach my $node ( $entry_list->get_nodelist ) {
$cdate = "$date 12:00:00+00";
}
}
+ $dbh->{AutoCommit} = 0;
if ( $exists ) {
print STDERR "Updating entry $id\n";
if ( $obtain_cdates ) {
@@ -151,4 +155,11 @@ foreach my $node ( $entry_list->get_nodelist ) {
$sth_insert->execute($id, $date, $lang, $title, $str, $sha1);
}
}
+ $sth_clear_cat->execute($id);
+ if ( defined($catlist) ) {
+ foreach my $cat ( split(' ', $catlist) ) {
+ $sth_set_cat->execute($id,$cat);
+ }
+ }
+ $dbh->commit;
}
diff --git a/weblog.sql b/weblog.sql
index 603dab1..25f1680 100644
--- a/weblog.sql
+++ b/weblog.sql
@@ -10,3 +10,10 @@ CREATE TABLE entries (
sha1 text NOT NULL
) ;
CREATE INDEX entries_edate_key ON entries ( edate ) ;
+CREATE TABLE incat (
+ id integer NOT NULL ,
+ code text NOT NULL ,
+ FOREIGN KEY ( id ) REFERENCES entries ( id ) ON DELETE CASCADE
+) ;
+CREATE INDEX incat_id_key ON incat ( id ) ;
+CREATE INDEX incat_code_key ON incat ( code ) ;