annotate convert_urllog_db.tcl @ 22:7feaff7cc22e

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 05 Sep 2011 18:37:33 +0300
parents 06f5e5b25930
children 9ba859d9f931
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #!/usr/bin/tclsh
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
2 # TCL script for converting URLLog v1.x flat file
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
3 # format database to SQLite3 database.
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
4 #
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
5 # Written by Matti 'ccr' Hamalainen <ccr@tnsp.org>
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
6 # (C) Copyright 2011 Tecnic Software productions (TNSP)
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
7 #
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 package require sqlite3
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
10 ### Check commandline arguments
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
11 if {$argc != 2} {
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
12 puts "Usage: $argv0 <input_flat_file_db> <output_sqlite_db_file>"
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
13 exit 0
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
14 }
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
15
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
16 set db_input [lindex $argv 0]
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
17 set db_output [lindex $argv 1]
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
18 set db_table "urls"
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
21 ### Ask for confirmation
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
22 puts "Conversion of '$db_input' to SQLite database '$db_output', to table '$db_table'."
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
23 puts "NOTICE! This WILL destroy the current data in table '$db_table'!"
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
24
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
25 puts -nonewline "Proceed \[y/N\]? "
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
26 flush stdout
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
27 set response [gets stdin]
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
28 if {[string tolower $response] != "y"} {
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
29 puts "OK, aborting."
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
30 exit 0
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
31 }
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
32
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
33 ### Helper functions
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 proc escape { str } {
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 return [string map {' ''} $str]
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 proc lescape { lst pos } {
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 return [escape [lindex $lst $pos]]
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 }
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
43 ### Open flatfile for reading
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
44 if {[catch {set fd [open $db_input r]} uerrmsg]} {
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
45 puts "Could not open '$db_input' for reading: $uerrmsg"
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 exit 1
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 }
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
49 ### Open SQLite database
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
50 if {[catch {sqlite3 urldb $db_output} uerrmsg]} {
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
51 puts "Could not open SQLite3 database '$db_output': $uerrmsg"
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 exit 2
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 }
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
55 ### Drop old table
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
56 puts "Dropping current '$db_table' table."
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
57 if {[catch {urldb eval {DROP TABLE $db_table}} uerrmsg]} {
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
58 puts "Dropping table resulted in error (ignored): $uerrmsg"
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
59 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
60
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
61 ### Create new
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
62 puts "Creating new table '$db_table'."
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
63 if {[catch {urldb eval "CREATE TABLE $db_table (id INTEGER PRIMARY KEY AUTOINCREMENT, utime INT, url VARCHAR(2048), user VARCHAR(32), host VARCHAR(256), chan VARCHAR(32))}} uerrmsg]" {
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
64 puts "Error creating table! $uerrmsg"
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
65 exit 3
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
66 }
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
68 ### Detect URL database version
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
69 puts -nonewline "Detecting database version: "
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 set nline 0
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
71 set minentries 9999
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
72 set maxentries 0
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
73 while {![eof $fd]} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
74 incr nline
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
75 set line [gets $fd]
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
76 if {$line != ""} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
77 set items [split $line " "]
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
78 set tmp [llength $items]
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
79 if {$tmp > $maxentries} { set maxentries $tmp }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
80 if {$tmp < $minentries} { set minentries $tmp }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
81 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
82 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
83
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
84 if {$maxentries != 5 || $maxentries != $minentries} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
85 puts "old / variable"
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
86 } else {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
87 puts "new"
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
88 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
89
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
90 ### Show some information
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
91 puts "Database contains $nline records, with $minentries / $maxentries entries."
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
92
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
93
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
94 ### Begin conversion
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
95 puts -nonewline "Converting database, please wait ... round #1 "
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
96 set nline 0
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
97 seek $fd 0 start
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 while {![eof $fd]} {
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 incr nline
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 set line [gets $fd]
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 set items [split $line " "]
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 if {$line != ""} {
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 set host [lindex $items 3]
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 if {[regexp {^\((.+)\)$} $host ures uhost]} {
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 set host $uhost
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
107 set uid [lindex $items 4]
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
108 if {$uid != ""} {
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
109 set sql "INSERT INTO $db_table (id,utime,url,user,host) VALUES ($uid, [lindex $items 1], '[lescape $items 0]', '[lescape $items 2]', '[escape $host]')"
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
110 if {[catch {urldb eval $sql} uerrmsg]} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
111 puts "\nError ($nline): $uerrmsg on:\n$sql"
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
112 exit 15
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
113 }
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 if {[expr $nline % 10] == 1} {
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 puts -nonewline "."
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 flush stdout
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 }
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 }
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
121 puts "OK"
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
122
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
123 puts -nonewline "\nRound #2 "
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
124 set nline 0
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
125 seek $fd 0 start
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
126 while {![eof $fd]} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
127 incr nline
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
128 set line [gets $fd]
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
129 set items [split $line " "]
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
130 if {$line != ""} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
131 set host [lindex $items 3]
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
132 if {[regexp {^\((.+)\)$} $host ures uhost]} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
133 set host $uhost
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
134 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
135 set uid [lindex $items 4]
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
136 if {$uid == ""} {
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
137 set sql "INSERT INTO $db_table (utime,url,user,host) VALUES ([lindex $items 1], '[lescape $items 0]', '[lescape $items 2]', '[escape $host]')"
11
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
138 if {[catch {urldb eval $sql} uerrmsg]} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
139 puts "\nError ($nline): $uerrmsg on:\n$sql"
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
140 exit 15
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
141 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
142 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
143 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
144 if {[expr $nline % 10] == 1} {
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
145 puts -nonewline "."
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
146 flush stdout
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
147 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
148 }
06f5e5b25930 Make the database conversion 2-staged to support old format flatfile database inputs. Add detection for old format.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
149
10
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 urldb close
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 close $fd
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
fbf718c24de4 Add script for converting URLLog text database to SQLite.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 puts "OK"
22
7feaff7cc22e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
154 puts "New SQLite3 database is in file '$db_output'"