sqlite2dbf 0.1.7 → 0.1.8
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.
- checksums.yaml +4 -4
- data/lib/argparser.rb +3 -4
- data/lib/constants.rb +1 -1
- data/lib/log.conf +1 -1
- data/lib/sqlite2dbf.rb +17 -9
- data/lib/translations +13 -6
- data/sqlite2dbf.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a174046549fd4651a2dcabcf6ab907d790f4b0ac
|
4
|
+
data.tar.gz: 24e59b0daac11a547ba42166bbca9c7390255e91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6928d69a1a10f29487437ea08fdba0fa8df2fd2a4be45295e31992a77d7f75773ac07d4d49c268055fac789d6fd7b54ccf957107ce005d461630aaf54e9a4018
|
7
|
+
data.tar.gz: 32a353698e77bc9a64773af5715053fb302190bf437ec640fb734f2d4c3cd1a645c7c28636a46039b84a51b4cb27c8925643d81b686f52f260403c59feb7244d
|
data/lib/argparser.rb
CHANGED
@@ -29,12 +29,10 @@ require_relative 'translating'
|
|
29
29
|
require_relative 'constants'
|
30
30
|
|
31
31
|
class ArgParser
|
32
|
-
include Logging
|
33
|
-
include Translating
|
34
32
|
|
35
33
|
self.extend(Logging)
|
36
34
|
self.extend(Translating)
|
37
|
-
@@log = init_logger(
|
35
|
+
@@log = init_logger()
|
38
36
|
|
39
37
|
# Returns a structure describing the options.
|
40
38
|
#
|
@@ -68,8 +66,9 @@ class ArgParser
|
|
68
66
|
options.datetime = list.gsub(/[,;]/, '').split
|
69
67
|
end
|
70
68
|
|
71
|
-
opts.on('-' << trl('o'), trl("--orig"), trl('Use the table-name as file-name for the DBF-result')) do
|
69
|
+
opts.on('-' << trl('o'), trl("--orig [PATH]"), trl('Use the table-name as file-name for the DBF-result, store output in PATH')) do |path|
|
72
70
|
options.table_name = true
|
71
|
+
options.out_dir = path
|
73
72
|
end
|
74
73
|
|
75
74
|
=begin
|
data/lib/constants.rb
CHANGED
data/lib/log.conf
CHANGED
data/lib/sqlite2dbf.rb
CHANGED
@@ -47,9 +47,13 @@ class SQLite2DBF
|
|
47
47
|
@time_fields = options.time ? options.time : []
|
48
48
|
|
49
49
|
if(options.source)
|
50
|
+
@dbf_path = nil
|
50
51
|
sqlite_file = options.source
|
51
52
|
dbf_file = options.target if options.target
|
52
|
-
|
53
|
+
if(options.table_name && options.out_dir)
|
54
|
+
@dbf_path = options.out_dir
|
55
|
+
dbf_file = :table
|
56
|
+
end
|
53
57
|
dbf_file ||= File.dirname(sqlite_file) << File::Separator << File.basename(sqlite_file, '.*')
|
54
58
|
msg = nil
|
55
59
|
|
@@ -82,7 +86,7 @@ class SQLite2DBF
|
|
82
86
|
|
83
87
|
def transform(sqlite_file, dbf_file)
|
84
88
|
# <------------ mapping SQLite-types to SHP/XBase ------------>
|
85
|
-
tmap = {'INT' => 1, 'TINYINT' => 1, 'SMALLINT' => 1, 'MEDIUMINT' => 1, 'BIGINT' => 1, 'UNSIGNED BIGINT' => 1, 'VARCHAR' => 0, 'CHARACTER' => 0, 'VARYING CHARACTER
|
89
|
+
tmap = {'INT' => 1, 'TINYINT' => 1, 'SMALLINT' => 1, 'MEDIUMINT' => 1, 'BIGINT' => 1, 'UNSIGNED BIGINT' => 1, 'VARCHAR' => 0, 'CHARACTER' => 0, 'VARYING CHARACTER' => 0, 'LONGVARCHAR' => 0, 'TEXT' => 0, 'BLOB' => 0, 'INTEGER' => 1, 'FLOAT' => 2, 'REAL' => 2, 'DOUBLE' => 2}
|
86
90
|
# -----------> in a way ... <--------------
|
87
91
|
|
88
92
|
begin
|
@@ -95,7 +99,7 @@ class SQLite2DBF
|
|
95
99
|
@log.debug(tn[0] << ': ' << table_info.join)
|
96
100
|
content = db.execute('select * from ' << tname )
|
97
101
|
if(:table == dbf_file)
|
98
|
-
dbf_name = tname << (content.empty? ? '_empty' : '')<< '.dbf'
|
102
|
+
dbf_name = @dbf_path << File::Separator << tname << (content.empty? ? '_empty' : '')<< '.dbf'
|
99
103
|
else
|
100
104
|
dbf_name = dbf_file.dup << num.to_s << (content.empty? ? '_empty' : '')<< '.dbf'
|
101
105
|
end
|
@@ -107,7 +111,9 @@ class SQLite2DBF
|
|
107
111
|
if( !@date_fields.include?(field_name) && !@time_fields.include?(field_name) )
|
108
112
|
@log.debug('field is ' << field.to_s)
|
109
113
|
# -----> determine the simple dbf data-type that has to do. <----
|
110
|
-
|
114
|
+
type_mapping = tmap.detect{|key, value| field['type'].upcase.start_with?(key) }
|
115
|
+
@log.debug('type_mapping is ' << type_mapping.to_s)
|
116
|
+
ftype = type_mapping[1] if type_mapping && type_mapping.respond_to?(:to_ary)
|
111
117
|
# <---- Yes. I know. ---->
|
112
118
|
end
|
113
119
|
|
@@ -122,21 +128,22 @@ class SQLite2DBF
|
|
122
128
|
@log.debug('field is ' << field_name << ', svalue is ' << svalue.to_s << ', type is ' << sql_type)
|
123
129
|
if(svalue && !svalue.to_s.empty?)
|
124
130
|
if( @date_fields.include?(field_name) )
|
125
|
-
conv_date = db.execute("select strftime('%Y
|
131
|
+
conv_date = db.execute("select strftime('%Y-%m-%d %H:%M:%S', " << svalue.to_s << ", 'unixepoch')").join
|
126
132
|
@log.debug('conv_date is ' << conv_date)
|
127
133
|
dbt.write_string_attribute(record_no, field_index, conv_date)
|
128
134
|
elsif( @time_fields.include?(field_name) )
|
129
|
-
conv_time = db.execute("select strftime('%
|
135
|
+
conv_time = db.execute("select strftime('%s', " << svalue.to_s << ", 'unixepoch')").join
|
130
136
|
@log.debug('conv_time is ' << conv_time)
|
131
137
|
dbt.write_string_attribute(record_no, field_index, conv_time)
|
132
138
|
|
133
139
|
else
|
134
|
-
|
135
|
-
|
140
|
+
type_mapping = tmap.detect{|key, value| sql_type.upcase.start_with?(key) }
|
141
|
+
ftype = type_mapping[1] if type_mapping && type_mapping.respond_to?(:to_ary)
|
136
142
|
begin
|
143
|
+
dbt.write_string_attribute(record_no, field_index, svalue ) if 0 == ftype
|
137
144
|
dbt.write_integer_attribute(record_no, field_index, svalue) if 1 == ftype
|
138
145
|
dbt.write_double_attribute(record_no, field_index, svalue) if 2 == ftype
|
139
|
-
rescue
|
146
|
+
rescue StandardError => ex
|
140
147
|
@log.error(trl("ERROR! cannot write value of type %s" %sql_type) << ': ' << ex.message )
|
141
148
|
end
|
142
149
|
end
|
@@ -148,6 +155,7 @@ class SQLite2DBF
|
|
148
155
|
dbt.close
|
149
156
|
end
|
150
157
|
end
|
158
|
+
puts trl('DONE. Bye.')
|
151
159
|
end
|
152
160
|
rescue SQLite3::Exception => er
|
153
161
|
@log.error trl("ERROR! Cannot read the source-file") << ' (' << sqlite_file << "): %s" %er.message << '.'
|
data/lib/translations
CHANGED
@@ -75,17 +75,17 @@ o:
|
|
75
75
|
de: t
|
76
76
|
fr: t
|
77
77
|
|
78
|
-
--orig:
|
79
|
-
de: --tab
|
80
|
-
fr: --tab
|
78
|
+
--orig [PATH]:
|
79
|
+
de: --tab [PFAD]
|
80
|
+
fr: --tab [RÉPERTOIRE]
|
81
81
|
|
82
82
|
Table-names:
|
83
83
|
de: Namen der Tabellen
|
84
84
|
fr: Noms des tableaux
|
85
85
|
|
86
|
-
Use the table-name as file-name for the DBF-result:
|
87
|
-
de: Tabellen-Namen als Dateinamen für die DBF-Ausgabe verwenden
|
88
|
-
fr: Utiliser les noms des tableaux comme noms des fichiers DBF
|
86
|
+
Use the table-name as file-name for the DBF-result, store output in PATH:
|
87
|
+
de: Tabellen-Namen als Dateinamen für die DBF-Ausgabe verwenden, Ausgabe in PFAD speichern
|
88
|
+
fr: Utiliser les noms des tableaux comme noms des fichiers DBF, écris fichier dans RÉPERTOIRE
|
89
89
|
|
90
90
|
ERROR! cannot write value of type INTEGER:
|
91
91
|
de: FEHLER! Kann INTEGER-Wert nicht schreiben
|
@@ -167,5 +167,12 @@ ERROR! Cannot read the source-file:
|
|
167
167
|
de: FEHLER! Kann die Quelldatei nicht lesen
|
168
168
|
fr: ERREUR ! Source inlisible
|
169
169
|
|
170
|
+
ERROR! cannot write value of type TEXT:
|
171
|
+
de: FEHLER! Kann einen Textwert nicht schreiben
|
172
|
+
fr: ERREUR ! Une valeur de type TEXT ne peut pas être écrit
|
173
|
+
|
174
|
+
DONE. Bye.:
|
175
|
+
de: Fertig. Tschüsie.
|
176
|
+
fr: Terminé. À plus.
|
170
177
|
|
171
178
|
# eof
|
data/sqlite2dbf.gemspec
CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.name = $APPNAME
|
4
4
|
s.version = $VERSION
|
5
5
|
s.date = $DATE
|
6
|
-
s.summary = "
|
6
|
+
s.summary = "Bug-fix: SQLite types are lower case or upper case. That is not a bug, but I thought they were always upper case. And there are null-types... non-types. Whatever."
|
7
7
|
s.description = "converts SQLite to DBase"
|
8
8
|
s.authors = $AUTHORS
|
9
9
|
s.email = $EMAIL
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlite2dbf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Uplawski <michael.uplawski@uplawski.eu>
|
@@ -51,5 +51,6 @@ rubyforge_project:
|
|
51
51
|
rubygems_version: 2.6.7
|
52
52
|
signing_key:
|
53
53
|
specification_version: 4
|
54
|
-
summary:
|
54
|
+
summary: 'Bug-fix: SQLite types are lower case or upper case. That is not a bug, but
|
55
|
+
I thought they were always upper case. And there are null-types... non-types. Whatever.'
|
55
56
|
test_files: []
|