# HG changeset patch # User Matti Hamalainen # Date 1370341379 -10800 # Node ID 089b59f940672d33980d673577cc618ffb58eaee # Parent 9f290e1ee738e15e8a5dd277addd6d59b52d68d0 Add creation and conversion utilities for SQLite3 format feeds databases. diff -r 9f290e1ee738 -r 089b59f94067 convert_feeds_db.tcl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/convert_feeds_db.tcl Tue Jun 04 13:22:59 2013 +0300 @@ -0,0 +1,67 @@ +#!/usr/bin/tclsh +# TCL script for converting Feed databases from +# flatfile format to SQLite3 database. +# +# Written by Matti 'ccr' Hamalainen +# (C) Copyright 2011 Tecnic Software productions (TNSP) +# +package require sqlite3 +source [file dirname [info script]]/util_convert.tcl + +### Check commandline arguments +if {$argc != 2} { + puts "Usage: $argv0 " + exit 0 +} + +set db_input [lindex $argv 0] +set db_output [lindex $argv 1] + +### Ask for confirmation +puts "Conversion of '$db_input' to SQLite database '$db_output'." +puts "NOTICE! This WILL destroy the current data in the target database!" + +if {![confirm_yesno "Proceed"]} { + exit 0 +} + +### Open flatfile for reading +if {[catch {set fd [open $db_input r]} uerrmsg]} { + puts "Could not open file '$db_input' for reading: $uerrmsg" + exit 1 +} + +### Open SQLite database, drop old tables, create new +open_db $db_output + +drop_table_feeds +create_table_feeds + + +### Convert data +puts -nonewline "Converting database, please wait " +set nline 0 +seek $fd 0 start + +while {![eof $fd]} { + incr nline + gets $fd uline + set items [split $uline "½"] + if {[llength $items] == 4} { + set sql "INSERT INTO feed_data (feed,utime,url,title) VALUES ('[lescape $items 1]', [lindex $items 0], '[lescape $items 2]', '[lescape $items 3]')" + if {[catch {dbh eval $sql} uerrmsg]} { + puts "\nError ($nline): $uerrmsg on:\n$sql" + exit 15 + } + } + + if {[expr $nline % 10] == 1} { + puts -nonewline "." + flush stdout + } +} + +dbh close +close $fd + +puts "DONE." diff -r 9f290e1ee738 -r 089b59f94067 create_feeds_db.tcl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/create_feeds_db.tcl Tue Jun 04 13:22:59 2013 +0300 @@ -0,0 +1,45 @@ +#!/usr/bin/tclsh +# TCL script for creating (empty) Feeds SQLite3 database +# +# Written by Matti 'ccr' Hamalainen +# (C) Copyright 2013 Tecnic Software productions (TNSP) +# +package require sqlite3 +source [file dirname [info script]]/util_convert.tcl + +### Check commandline arguments +if {$argc < 1} { + puts "Creates tables for Feeds target SQLite3 file" + puts "Usage: $argv0 \[-drop\]" + puts "" + puts "-drop option will drop any existing Feeds tables." + exit 0 +} + +set db_drop 0 +set db_output [lindex $argv 0] +if {$argc >= 2 && [lindex $argv 1] == "-drop"} { + set db_drop 1 +} + +### Open database +open_db $db_output + +if {$db_drop} { + puts "WARNING! Dropping old tables Feeds requested!" + puts "All data in those tables will be permanently lost!" + + if {![confirm_yesno "Proceed"]} { + puts "Aborting procedure." + dbh close + exit 0 + } + + drop_table_feeds +} + +create_table_feeds + +dbh close + +puts "DONE."