athena 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to athena version 0.1.4
5
+ This documentation refers to athena version 0.1.5
6
6
 
7
7
 
8
8
  == DESCRIPTION
data/example/config.yaml CHANGED
@@ -70,3 +70,12 @@
70
70
  - "0370"
71
71
  - "0100"
72
72
  :string: "ort2sb=%s (HSTZusatz=%s [Untertitstab=%s] / VerfAnsetz=%s)"
73
+ :dump-my:
74
+ :object: [ObjID, Bla, Blub]
75
+ :fooobject: [ObjID, attr1ID, attr3ID, Foo]
76
+ :barobject: [ObjID, attr4ID, Bar]
77
+ :attr1: [ObjID, attr1ID, Val]
78
+ :attr2: [ObjID, attr2ID, Val]
79
+ :attr3: [attr3ID, Val]
80
+ :attr4: [attr4ID, Val]
81
+ :dump-pg:
@@ -0,0 +1,202 @@
1
+ -- MySQL dump 10.13 Distrib 5.1.54, for debian-linux-gnu (x86_64)
2
+ --
3
+ -- Host: localhost Database: flattendb_temp_1310038141_10671
4
+ -- ------------------------------------------------------
5
+ -- Server version 5.1.54-1ubuntu4
6
+
7
+ /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
8
+ /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
9
+ /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
10
+ /*!40101 SET NAMES utf8 */;
11
+ /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
12
+ /*!40103 SET TIME_ZONE='+00:00' */;
13
+ /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
14
+ /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
15
+ /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
16
+ /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
17
+
18
+ --
19
+ -- Table structure for table `attr1`
20
+ --
21
+
22
+ DROP TABLE IF EXISTS `attr1`;
23
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
24
+ /*!40101 SET character_set_client = utf8 */;
25
+ CREATE TABLE `attr1` (
26
+ `ObjID` int(11) NOT NULL,
27
+ `attr1ID` int(11) NOT NULL,
28
+ `Val` int(11) NOT NULL,
29
+ PRIMARY KEY (`attr1ID`)
30
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
31
+ /*!40101 SET character_set_client = @saved_cs_client */;
32
+
33
+ --
34
+ -- Dumping data for table `attr1`
35
+ --
36
+
37
+ LOCK TABLES `attr1` WRITE;
38
+ /*!40000 ALTER TABLE `attr1` DISABLE KEYS */;
39
+ INSERT INTO `attr1` VALUES (1,1,3),(2,2,2),(3,3,1);
40
+ /*!40000 ALTER TABLE `attr1` ENABLE KEYS */;
41
+ UNLOCK TABLES;
42
+
43
+ --
44
+ -- Table structure for table `attr2`
45
+ --
46
+
47
+ DROP TABLE IF EXISTS `attr2`;
48
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
49
+ /*!40101 SET character_set_client = utf8 */;
50
+ CREATE TABLE `attr2` (
51
+ `ObjID` int(11) NOT NULL,
52
+ `attr2ID` int(11) NOT NULL,
53
+ `Val` int(11) NOT NULL,
54
+ PRIMARY KEY (`attr2ID`)
55
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
56
+ /*!40101 SET character_set_client = @saved_cs_client */;
57
+
58
+ --
59
+ -- Dumping data for table `attr2`
60
+ --
61
+
62
+ LOCK TABLES `attr2` WRITE;
63
+ /*!40000 ALTER TABLE `attr2` DISABLE KEYS */;
64
+ INSERT INTO `attr2` VALUES (1,3,4),(2,2,5),(3,1,6);
65
+ /*!40000 ALTER TABLE `attr2` ENABLE KEYS */;
66
+ UNLOCK TABLES;
67
+
68
+ --
69
+ -- Table structure for table `attr3`
70
+ --
71
+
72
+ DROP TABLE IF EXISTS `attr3`;
73
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
74
+ /*!40101 SET character_set_client = utf8 */;
75
+ CREATE TABLE `attr3` (
76
+ `attr3ID` int(11) NOT NULL,
77
+ `Val` int(11) NOT NULL,
78
+ PRIMARY KEY (`attr3ID`)
79
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
80
+ /*!40101 SET character_set_client = @saved_cs_client */;
81
+
82
+ --
83
+ -- Dumping data for table `attr3`
84
+ --
85
+
86
+ LOCK TABLES `attr3` WRITE;
87
+ /*!40000 ALTER TABLE `attr3` DISABLE KEYS */;
88
+ INSERT INTO `attr3` VALUES (1,0),(2,8),(3,7);
89
+ /*!40000 ALTER TABLE `attr3` ENABLE KEYS */;
90
+ UNLOCK TABLES;
91
+
92
+ --
93
+ -- Table structure for table `attr4`
94
+ --
95
+
96
+ DROP TABLE IF EXISTS `attr4`;
97
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
98
+ /*!40101 SET character_set_client = utf8 */;
99
+ CREATE TABLE `attr4` (
100
+ `attr4ID` int(11) NOT NULL,
101
+ `Val` int(11) NOT NULL,
102
+ PRIMARY KEY (`attr4ID`)
103
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
104
+ /*!40101 SET character_set_client = @saved_cs_client */;
105
+
106
+ --
107
+ -- Dumping data for table `attr4`
108
+ --
109
+
110
+ LOCK TABLES `attr4` WRITE;
111
+ /*!40000 ALTER TABLE `attr4` DISABLE KEYS */;
112
+ INSERT INTO `attr4` VALUES (1,0),(2,0),(3,9);
113
+ /*!40000 ALTER TABLE `attr4` ENABLE KEYS */;
114
+ UNLOCK TABLES;
115
+
116
+ --
117
+ -- Table structure for table `barobject`
118
+ --
119
+
120
+ DROP TABLE IF EXISTS `barobject`;
121
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
122
+ /*!40101 SET character_set_client = utf8 */;
123
+ CREATE TABLE `barobject` (
124
+ `ObjID` int(11) NOT NULL,
125
+ `attr4ID` int(11) NOT NULL,
126
+ `Bar` int(11) NOT NULL,
127
+ PRIMARY KEY (`ObjID`)
128
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
129
+ /*!40101 SET character_set_client = @saved_cs_client */;
130
+
131
+ --
132
+ -- Dumping data for table `barobject`
133
+ --
134
+
135
+ LOCK TABLES `barobject` WRITE;
136
+ /*!40000 ALTER TABLE `barobject` DISABLE KEYS */;
137
+ INSERT INTO `barobject` VALUES (1,2,1002),(2,1,1200),(3,3,1000);
138
+ /*!40000 ALTER TABLE `barobject` ENABLE KEYS */;
139
+ UNLOCK TABLES;
140
+
141
+ --
142
+ -- Table structure for table `fooobject`
143
+ --
144
+
145
+ DROP TABLE IF EXISTS `fooobject`;
146
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
147
+ /*!40101 SET character_set_client = utf8 */;
148
+ CREATE TABLE `fooobject` (
149
+ `ObjID` int(11) NOT NULL,
150
+ `attr1ID` int(11) NOT NULL,
151
+ `attr3ID` int(11) NOT NULL,
152
+ `Foo` int(11) NOT NULL,
153
+ PRIMARY KEY (`ObjID`)
154
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
155
+ /*!40101 SET character_set_client = @saved_cs_client */;
156
+
157
+ --
158
+ -- Dumping data for table `fooobject`
159
+ --
160
+
161
+ LOCK TABLES `fooobject` WRITE;
162
+ /*!40000 ALTER TABLE `fooobject` DISABLE KEYS */;
163
+ INSERT INTO `fooobject` VALUES (1,1,2,112),(2,2,1,122);
164
+ INSERT INTO `fooobject` VALUES (3,3,3,111);
165
+ /*!40000 ALTER TABLE `fooobject` ENABLE KEYS */;
166
+ UNLOCK TABLES;
167
+
168
+ --
169
+ -- Table structure for table `object`
170
+ --
171
+
172
+ DROP TABLE IF EXISTS `object`;
173
+ /*!40101 SET @saved_cs_client = @@character_set_client */;
174
+ /*!40101 SET character_set_client = utf8 */;
175
+ CREATE TABLE `object` (
176
+ `ObjID` int(11) NOT NULL,
177
+ `Bla` int(11) NOT NULL,
178
+ `Blub` varchar(50) DEFAULT NULL,
179
+ PRIMARY KEY (`ObjID`)
180
+ ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
181
+ /*!40101 SET character_set_client = @saved_cs_client */;
182
+
183
+ --
184
+ -- Dumping data for table `object`
185
+ --
186
+
187
+ LOCK TABLES `object` WRITE;
188
+ /*!40000 ALTER TABLE `object` DISABLE KEYS */;
189
+ INSERT INTO `object` VALUES (1,12,NULL),(2,12,'h),(i'),(30,1,'h\'o');
190
+ /*!40000 ALTER TABLE `object` ENABLE KEYS */;
191
+ UNLOCK TABLES;
192
+ /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
193
+
194
+ /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
195
+ /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
196
+ /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
197
+ /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
198
+ /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
199
+ /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
200
+ /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
201
+
202
+ -- Dump completed on 2011-07-07 13:31:05
@@ -0,0 +1,163 @@
1
+ --
2
+ -- PostgreSQL database cluster dump
3
+ --
4
+
5
+ SET client_encoding = 'UTF8';
6
+ SET standard_conforming_strings = off;
7
+ SET escape_string_warning = off;
8
+
9
+ --
10
+ -- PostgreSQL database dump
11
+ --
12
+
13
+ SET statement_timeout = 0;
14
+ SET client_encoding = 'UTF8';
15
+ SET standard_conforming_strings = off;
16
+ SET check_function_bodies = false;
17
+ SET client_min_messages = warning;
18
+ SET escape_string_warning = off;
19
+
20
+ SET search_path = public, pg_catalog;
21
+
22
+ SET default_tablespace = '';
23
+
24
+ SET default_with_oids = false;
25
+
26
+ --
27
+ -- Name: attr1; Type: TABLE; Schema: public; Owner: bla; Tablespace:
28
+ --
29
+
30
+ CREATE TABLE attr1 (
31
+ ObjID integer NOT NULL,
32
+ attr1ID integer NOT NULL,
33
+ Val integer NOT NULL
34
+ );
35
+
36
+ --
37
+ -- Data for Name: attr1; Type: TABLE DATA; Schema: public; Owner: bla
38
+ --
39
+
40
+ COPY attr1 (ObjID, attr1ID, Val) FROM stdin;
41
+ 1 1 3
42
+ 2 2 2
43
+ 3 3 1
44
+ \.
45
+
46
+ --
47
+ -- Name: attr2; Type: TABLE; Schema: public; Owner: bla; Tablespace:
48
+ --
49
+
50
+ CREATE TABLE attr2 (
51
+ ObjID integer NOT NULL,
52
+ attr2ID integer NOT NULL,
53
+ Val integer NOT NULL
54
+ );
55
+
56
+ --
57
+ -- Data for Name: attr2; Type: TABLE DATA; Schema: public; Owner: bla
58
+ --
59
+
60
+ COPY attr2 (ObjID, attr2ID, Val) FROM stdin;
61
+ 1 3 4
62
+ 2 2 5
63
+ 3 1 6
64
+ \.
65
+
66
+ --
67
+ -- Name: attr3; Type: TABLE; Schema: public; Owner: bla; Tablespace:
68
+ --
69
+
70
+ CREATE TABLE attr3 (
71
+ attr3ID integer NOT NULL,
72
+ Val integer NOT NULL
73
+ );
74
+
75
+ --
76
+ -- Data for Name: attr3; Type: TABLE DATA; Schema: public; Owner: bla
77
+ --
78
+
79
+ COPY attr3 (attr3ID, Val) FROM stdin;
80
+ 1 0
81
+ 2 8
82
+ 3 7
83
+ \.
84
+
85
+ --
86
+ -- Name: attr4; Type: TABLE; Schema: public; Owner: bla; Tablespace:
87
+ --
88
+
89
+ CREATE TABLE attr4 (
90
+ attr4ID integer NOT NULL,
91
+ Val integer NOT NULL
92
+ );
93
+
94
+ --
95
+ -- Data for Name: attr4; Type: TABLE DATA; Schema: public; Owner: bla
96
+ --
97
+
98
+ COPY attr4 (attr4ID, Val) FROM stdin;
99
+ 1 0
100
+ 2 0
101
+ 3 9
102
+ \.
103
+
104
+ --
105
+ -- Name: barobject; Type: TABLE; Schema: public; Owner: bla; Tablespace:
106
+ --
107
+
108
+ CREATE TABLE barobject (
109
+ ObjID integer NOT NULL,
110
+ attr4ID integer NOT NULL,
111
+ Bar integer NOT NULL
112
+ );
113
+
114
+ --
115
+ -- Data for Name: barobject; Type: TABLE DATA; Schema: public; Owner: bla
116
+ --
117
+
118
+ COPY barobject (ObjID, attr4ID, Bar) FROM stdin;
119
+ 1 2 1002
120
+ 2 1 1200
121
+ 3 3 1000
122
+ \.
123
+
124
+ --
125
+ -- Name: fooobject; Type: TABLE; Schema: public; Owner: bla; Tablespace:
126
+ --
127
+
128
+ CREATE TABLE fooobject (
129
+ ObjID integer NOT NULL,
130
+ attr1ID integer NOT NULL,
131
+ attr3ID integer NOT NULL,
132
+ Foo integer NOT NULL
133
+ );
134
+
135
+ --
136
+ -- Data for Name: fooobject; Type: TABLE DATA; Schema: public; Owner: bla
137
+ --
138
+
139
+ COPY fooobject (ObjID, attr1ID, attr3ID, Foo) FROM stdin;
140
+ 1 1 2 112
141
+ 2 2 1 122
142
+ 3 3 3 111
143
+ \.
144
+
145
+ --
146
+ -- Name: object; Type: TABLE; Schema: public; Owner: bla; Tablespace:
147
+ --
148
+
149
+ CREATE TABLE object (
150
+ ObjID integer NOT NULL,
151
+ Bla integer NOT NULL,
152
+ Blub character varying(50) DEFAULT NULL
153
+ );
154
+
155
+ --
156
+ -- Data for Name: object; Type: TABLE DATA; Schema: public; Owner: bla
157
+ --
158
+
159
+ COPY object (ObjID, Bla, Blub) FROM stdin;
160
+ 1 12 NULL
161
+ 2 12 h) (i
162
+ 3 1 h'o
163
+ \.
@@ -44,12 +44,12 @@ module Athena
44
44
 
45
45
  register_format :in do
46
46
 
47
- attr_reader :record_element, :config, :parser, :match_all_query
47
+ attr_reader :record_element, :config, :match_all_query
48
48
 
49
49
  def initialize(parser)
50
- config = parser.config.dup
50
+ @config = parser.config.dup
51
51
 
52
- case @record_element = config.delete(:__record_element)
52
+ case @record_element = @config.delete(:__record_element)
53
53
  when String
54
54
  # fine!
55
55
  when nil
@@ -57,9 +57,6 @@ module Athena
57
57
  else
58
58
  raise IllegalRecordElementError, "illegal record element #{@record_element.inspect}"
59
59
  end
60
-
61
- @config = config
62
- @parser = parser
63
60
  end
64
61
 
65
62
  end if Object.const_defined?(:Ferret)
@@ -35,12 +35,12 @@ module Athena
35
35
 
36
36
  register_format :in do
37
37
 
38
- attr_reader :record_element, :config, :parser
38
+ attr_reader :record_element, :config
39
39
 
40
40
  def initialize(parser)
41
- config = parser.config.dup
41
+ @config = parser.config.dup
42
42
 
43
- case @record_element = config.delete(:__record_element)
43
+ case @record_element = @config.delete(:__record_element)
44
44
  when String
45
45
  # fine!
46
46
  when nil
@@ -48,9 +48,6 @@ module Athena
48
48
  else
49
49
  raise IllegalRecordElementError, "illegal record element #{@record_element.inspect}"
50
50
  end
51
-
52
- @config = config
53
- @parser = parser
54
51
  end
55
52
 
56
53
  end
@@ -0,0 +1,249 @@
1
+ #--
2
+ ###############################################################################
3
+ # #
4
+ # A component of athena, the database file converter. #
5
+ # #
6
+ # Copyright (C) 2007-2011 University of Cologne, #
7
+ # Albertus-Magnus-Platz, #
8
+ # 50923 Cologne, Germany #
9
+ # #
10
+ # Authors: #
11
+ # Jens Wille <jens.wille@uni-koeln.de> #
12
+ # #
13
+ # athena is free software; you can redistribute it and/or modify it under the #
14
+ # terms of the GNU Affero General Public License as published by the Free #
15
+ # Software Foundation; either version 3 of the License, or (at your option) #
16
+ # any later version. #
17
+ # #
18
+ # athena is distributed in the hope that it will be useful, but WITHOUT ANY #
19
+ # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
20
+ # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for #
21
+ # more details. #
22
+ # #
23
+ # You should have received a copy of the GNU Affero General Public License #
24
+ # along with athena. If not, see <http://www.gnu.org/licenses/>. #
25
+ # #
26
+ ###############################################################################
27
+ #++
28
+
29
+ require 'strscan'
30
+
31
+ module Athena
32
+ module Formats
33
+
34
+ class MYSQL < Base
35
+
36
+ register_format :in do
37
+
38
+ attr_reader :record_element, :config, :sql_parser
39
+
40
+ def initialize(parser)
41
+ @config = parser.config.dup
42
+
43
+ case @record_element = @config.delete(:__record_element)
44
+ when String, nil
45
+ # fine!
46
+ else
47
+ raise IllegalRecordElementError, "illegal record element #{@record_element.inspect}"
48
+ end
49
+
50
+ @sql_parser = SQLParser.new
51
+ end
52
+
53
+ end
54
+
55
+ def parse(source, &block)
56
+ columns, table, num = Hash.new { |h, k| h[k] = [] }, nil, 0
57
+
58
+ source.each { |line|
59
+ case line = line.chomp
60
+ when /\ACREATE\s+TABLE\s+`(.+?)`/i
61
+ table = $1
62
+ when /\A\s+`(.+?)`/i
63
+ columns[table] << $1 if table
64
+ when /\A\).*;\z/
65
+ table = nil
66
+ when /\AINSERT\s+INTO\s+`(.+?)`\s+VALUES\s*(.*);\z/i
67
+ _columns = columns[$1]
68
+ next if _columns.empty?
69
+
70
+ sql_parser.parse($2) { |row|
71
+ Record.new(nil, block) { |record|
72
+ row.each_with_index { |value, index|
73
+ column = _columns[index] or next
74
+
75
+ if column == record_element
76
+ record.instance_variable_set(:@id, value)
77
+ end
78
+
79
+ record.update(column, value.to_s, config[column])
80
+ }
81
+ }
82
+
83
+ num += 1
84
+ }
85
+ end
86
+ }
87
+
88
+ num
89
+ end
90
+
91
+ class SQLParser
92
+
93
+ AST = Struct.new(:value)
94
+
95
+ def self.parse(input)
96
+ new.parse(input)
97
+ end
98
+
99
+ def parse(input)
100
+ @input = StringScanner.new(input)
101
+
102
+ rows, block_given = [], block_given?
103
+
104
+ while result = parse_row
105
+ row = result.value
106
+ block_given ? yield(row) : rows << row
107
+ break unless @input.scan(/,/)
108
+ end
109
+
110
+ @input.scan(/;/) # optional
111
+
112
+ error('Unexpected data') unless @input.eos?
113
+
114
+ rows unless block_given
115
+ end
116
+
117
+ private
118
+
119
+ def parse_row
120
+ return unless @input.scan(/\(/)
121
+
122
+ row = []
123
+
124
+ while result = parse_value
125
+ row << result.value
126
+ break unless @input.scan(/,/)
127
+ end
128
+
129
+ error('Unclosed row') unless @input.scan(/\)/)
130
+
131
+ AST.new(row)
132
+ end
133
+
134
+ def parse_value
135
+ parse_string ||
136
+ parse_number ||
137
+ parse_keyword
138
+ end
139
+
140
+ def parse_string
141
+ return unless @input.scan(/'/)
142
+
143
+ string = ''
144
+
145
+ while contents = parse_string_content || parse_string_escape
146
+ string << contents.value
147
+ end
148
+
149
+ error('Unclosed string') unless @input.scan(/'/)
150
+
151
+ AST.new(string)
152
+ end
153
+
154
+ def parse_string_content
155
+ if @input.scan(/[^\\']+/)
156
+ AST.new(@input.matched)
157
+ end
158
+ end
159
+
160
+ def parse_string_escape
161
+ if @input.scan(/\\['\\]|''/)
162
+ AST.new(@input.matched[-1, 1])
163
+ end
164
+ end
165
+
166
+ def parse_number
167
+ if @input.scan(/-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/)
168
+ AST.new(eval(@input.matched))
169
+ end
170
+ end
171
+
172
+ def parse_keyword
173
+ if @input.scan(/null/i)
174
+ AST.new(nil)
175
+ end
176
+ end
177
+
178
+ def error(message)
179
+ if @input.eos?
180
+ raise "Unexpected end of input (#{message})."
181
+ else
182
+ raise "#{message} at #{@input.pos}: #{@input.peek(8).inspect}"
183
+ end
184
+ end
185
+
186
+ end
187
+
188
+ end
189
+
190
+ class PGSQL < Base
191
+
192
+ register_format :in do
193
+
194
+ attr_reader :record_element, :config
195
+
196
+ def initialize(parser)
197
+ @config = parser.config.dup
198
+
199
+ case @record_element = @config.delete(:__record_element)
200
+ when String, nil
201
+ # fine!
202
+ else
203
+ raise IllegalRecordElementError, "illegal record element #{@record_element.inspect}"
204
+ end
205
+ end
206
+
207
+ end
208
+
209
+ def parse(source, &block)
210
+ columns, table, num = Hash.new { |h, k| h[k] = [] }, nil, 0
211
+
212
+ source.each { |line|
213
+ case line = line.chomp
214
+ when /\ACOPY\s+(\S+)\s+\((.+?)\)\s+FROM\s+stdin;\z/i
215
+ columns[table = $1] = $2.split(/\s*,\s*/)
216
+ when /\A\\\.\z/
217
+ table = nil
218
+ else
219
+ next unless table
220
+
221
+ cols = columns[table]
222
+ next if cols.empty?
223
+
224
+ Record.new(nil, block) { |record|
225
+ line.split(/\t/).each_with_index { |value, index|
226
+ column = cols[index] or next
227
+
228
+ if column == record_element
229
+ record.instance_variable_set(:@id, value)
230
+ end
231
+
232
+ record.update(column, value, config[column])
233
+ }
234
+ }
235
+
236
+ num += 1
237
+ end
238
+ }
239
+
240
+ num
241
+ end
242
+
243
+ end
244
+
245
+ MySQL = MYSQL
246
+ PgSQL = PGSQL
247
+
248
+ end
249
+ end
@@ -4,7 +4,7 @@ module Athena
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- TINY = 4
7
+ TINY = 5
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: athena
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jens Wille
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-29 00:00:00 Z
18
+ date: 2011-07-12 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: builder
@@ -78,6 +78,7 @@ files:
78
78
  - lib/athena/formats/lingo.rb
79
79
  - lib/athena/formats/ferret.rb
80
80
  - lib/athena/formats/dbm.rb
81
+ - lib/athena/formats/sql.rb
81
82
  - lib/athena/formats/sisis.rb
82
83
  - lib/athena/version.rb
83
84
  - lib/athena/parser.rb
@@ -88,7 +89,9 @@ files:
88
89
  - ChangeLog
89
90
  - Rakefile
90
91
  - COPYING
92
+ - example/dump-my.sql
91
93
  - example/config.yaml
94
+ - example/dump-pg.sql
92
95
  - example/example.xml
93
96
  - example/sisis-ex.txt
94
97
  homepage: http://prometheus.rubyforge.org/athena
@@ -96,14 +99,14 @@ licenses: []
96
99
 
97
100
  post_install_message:
98
101
  rdoc_options:
99
- - --line-numbers
100
- - --main
101
- - README
102
102
  - --charset
103
103
  - UTF-8
104
- - --all
105
104
  - --title
106
- - athena Application documentation (v0.1.4)
105
+ - athena Application documentation (v0.1.5)
106
+ - --main
107
+ - README
108
+ - --line-numbers
109
+ - --all
107
110
  require_paths:
108
111
  - lib
109
112
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -127,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
130
  requirements: []
128
131
 
129
132
  rubyforge_project: prometheus
130
- rubygems_version: 1.7.2
133
+ rubygems_version: 1.8.5
131
134
  signing_key:
132
135
  specification_version: 3
133
136
  summary: Convert database files to various formats.