sqlite2dbf 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45babe3b6624235add48f6c62c22a5aaccefc294
4
- data.tar.gz: bd7ed59177cb0fa945defa4e0413558bcdd5823b
3
+ metadata.gz: efa63f4b52e4fa86211371dce58db97f686647c0
4
+ data.tar.gz: 4ce02a2d7ddd94d3a2371cf05ad823f36c50cb63
5
5
  SHA512:
6
- metadata.gz: c7920489b4c73e5f1799c8cf5a695ad97cd30dfe294b68cf377d9e02e53df306277223197b3fc5a1b8c77008e6dea5140163b87f71cc9c4438f323f58816ce99
7
- data.tar.gz: 2dccbcbd83841acb53670181820f58f9cb1df999437f89d492894384a3a52a3dc5b64780097abddb0a4163100f6e1a612a3af7ad4247d8588d79036350397cc3
6
+ metadata.gz: 6c29cb8c99e820c288e115bb4e6e4582db95895323aed14d9d314447b05a2808484940fed2bdce53af4b6ac7a73ecfd6ecc8008348debf431a909cbccf94d8e5
7
+ data.tar.gz: 319f49362f9ecedb7e245a0efbbb01dc4efdab06f1798877ac92f1e2a0ca1a1b8d25f369cbdb53b4c95619501d6d0bc9807baddde25fd056ba2a11c0d33a570a
data/lib/argparser.rb CHANGED
@@ -34,27 +34,39 @@ class ArgParser
34
34
 
35
35
  self.extend(Logging)
36
36
  self.extend(Translating)
37
- @@log = init_logger()
37
+ @@log = init_logger(STDOUT, Logger::DEBUG)
38
38
 
39
39
  # Returns a structure describing the options.
40
40
  #
41
41
  def self.parse(args)
42
42
  # The options specified on the command line will be collected in <b>options</b>.
43
43
  # We set default values here.
44
+
44
45
  options = OpenStruct.new
45
46
  options.debug = false
47
+ options.table_name = false
46
48
 
47
49
  op = OptionParser.new do |opts|
48
50
  opts.banner = "\n" << trl("Usage") << ":\t" << $APPNAME.dup << ' ' << trl("-s [sqlite-file] [options]") << "\n\t" << trl("or %s [Common options]") %($APPNAME)
49
51
 
50
52
  opts.separator ""
51
53
  opts.separator trl("Specific options") << ':'
52
- opts.on('-' << trl("s"), '--' << trl("source/sqlite-file [FILE.sqlite]"), trl( "SQLite-file to read.")) do |source|
54
+
55
+ opts.on('-' << trl("s"), '--' << trl("source [FILE.sqlite]"), trl( "SQLite-file to read.")) do |source|
53
56
  options.source = source
54
57
  end
55
- opts.on('-' << trl("t"), '--' << trl("dBase-files [FILE(0...n).dbf]"), trl( "Name for the dBase-files (1 per table) to be written.")) do |target|
58
+
59
+ opts.on('-' << trl("t"), '--' << trl("target [FILE(0...n).dbf]"), trl( "Name for the dBase-files (1 per table) to be written.")) do |target|
56
60
  options.target = target
57
61
  end
62
+
63
+ opts.on('--' << trl("time [list]"), trl( "A list of space-separated fields (table-columns) which shall be handled as timestamp values.")) do |list|
64
+ options.time = list.gsub(/[,;]/, '').split
65
+ end
66
+
67
+ opts.on('--' << trl("dates [list]"), trl( "A list of space-separated fields (table-columns) which shall be handled as date-time values.")) do |list|
68
+ options.datetime = list.gsub(/[,;]/, '').split
69
+ end
58
70
 
59
71
  opts.on('-' << trl('o'), trl("--orig"), trl('Use the table-name as file-name for the DBF-result')) do
60
72
  options.table_name = true
@@ -83,6 +95,7 @@ end
83
95
  #
84
96
  opts.on_tail(trl("-d"), trl("--debug"), trl("Show debug-messages") ) do
85
97
  options.debug = true
98
+ @@log.level = Logger::DEBUG
86
99
  end
87
100
 
88
101
 
data/lib/constants.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  $APPNAME = 'sqlite2dbf'
2
- $VERSION = '0.1.6'
2
+ $VERSION = '0.1.7'
3
3
  $DATE = '2016-11-12'
4
4
  $AUTHORS = ["Michael Uplawski <michael.uplawski@uplawski.eu>"]
5
5
  $EMAIL = 'michael.uplawski@uplawski.eu'
data/lib/log.conf CHANGED
@@ -45,6 +45,7 @@ unknown = Logger::UNKNOWN
45
45
  # :HtmlBuilder => [info, 'C:\temp\htmlbuilder.log']
46
46
  # :HtmlBuilder => [debug, '/tmp/htmlbuilder.log'],
47
47
 
48
+ :ArgParser => debug,
48
49
  :SQLite2DBF => info,
49
50
 
50
51
  # And ignore the remainder, too.
data/lib/sqlite2dbf.rb CHANGED
@@ -43,6 +43,9 @@ class SQLite2DBF
43
43
  @log.level = level
44
44
  @log.debug('options are: ' << options.to_s)
45
45
 
46
+ @date_fields = options.datetime ? options.datetime : []
47
+ @time_fields = options.time ? options.time : []
48
+
46
49
  if(options.source)
47
50
  sqlite_file = options.source
48
51
  dbf_file = options.target if options.target
@@ -79,7 +82,7 @@ class SQLite2DBF
79
82
 
80
83
  def transform(sqlite_file, dbf_file)
81
84
  # <------------ mapping SQLite-types to SHP/XBase ------------>
82
- tmap = {'INT' => 1, 'TINYINT' => 1, 'SMALLINT' => 1, 'MEDIUMINT' => 1, 'BIGINT' => 1, 'UNSIGNED BIGINT' => 1, 'VARCHAR' => 0, 'CHARACTER' => 0, 'VARYING CHARACTER(255)' => 0, 'LONGVARCHAR' => 0, 'TEXT' => 0, 'INTEGER' => 1, 'FLOAT' => 2, 'REAL' => 2, 'DOUBLE' => 2}
85
+ tmap = {'INT' => 1, 'TINYINT' => 1, 'SMALLINT' => 1, 'MEDIUMINT' => 1, 'BIGINT' => 1, 'UNSIGNED BIGINT' => 1, 'VARCHAR' => 0, 'CHARACTER' => 0, 'VARYING CHARACTER(255)' => 0, 'LONGVARCHAR' => 0, 'TEXT' => 0, 'BLOB' => 0, 'INTEGER' => 1, 'FLOAT' => 2, 'REAL' => 2, 'DOUBLE' => 2}
83
86
  # -----------> in a way ... <--------------
84
87
 
85
88
  begin
@@ -100,29 +103,45 @@ class SQLite2DBF
100
103
  dbt = SHP::DBF.create(dbf_name)
101
104
  table_info.each_with_index do |field, index|
102
105
  ftype = 0
103
- # -----> determine the simple dbf data-type that has to do. <----
104
- sql_type = tmap.keys.detect {|kt| field['type'].start_with?(kt) }
105
- ftype ||= tmap[sql_type]
106
- # <---- Yes. I know. ---->
106
+ field_name = field['name']
107
+ if( !@date_fields.include?(field_name) && !@time_fields.include?(field_name) )
108
+ @log.debug('field is ' << field.to_s)
109
+ # -----> determine the simple dbf data-type that has to do. <----
110
+ ftype = tmap.detect{|key, value| field['type'].start_with?(key) }[1]
111
+ # <---- Yes. I know. ---->
112
+ end
107
113
 
108
- dbt.add_field(field['name'], ftype, 200, 0)
114
+ dbt.add_field(field_name, ftype, 200, 0)
109
115
  end
110
116
 
111
117
  content.each_with_index do |row, record_no|
112
118
  @log.debug('row is ' << row.to_s)
113
119
  row.each_with_index do |svalue, field_index|
114
- type = table_info[field_index]['type']
115
- @log.debug('field is ' << table_info[field_index]['name'] << ', svalue is ' << svalue.to_s << ', type is ' << type)
116
- if(svalue)
117
- dbt.write_string_attribute(record_no, field_index, svalue ) if 'TEXT' == type
118
- begin
119
- dbt.write_integer_attribute(record_no, field_index, svalue) if 'INTEGER' == type
120
- dbt.write_double_attribute(record_no, field_index, svalue) if 'FLOAT' == type
121
- rescue RangeError => ex
122
- @log.error(trl("ERROR! cannot write value of type %s" %type) << ': ' << ex.message )
120
+ sql_type = table_info[field_index]['type']
121
+ field_name = table_info[field_index]['name']
122
+ @log.debug('field is ' << field_name << ', svalue is ' << svalue.to_s << ', type is ' << sql_type)
123
+ if(svalue && !svalue.to_s.empty?)
124
+ if( @date_fields.include?(field_name) )
125
+ conv_date = db.execute("select strftime('%Y%m%d %H%M%S', " << svalue.to_s << ", 'unixepoch')").join
126
+ @log.debug('conv_date is ' << conv_date)
127
+ dbt.write_string_attribute(record_no, field_index, conv_date)
128
+ elsif( @time_fields.include?(field_name) )
129
+ conv_time = db.execute("select strftime('%H%M%S', " << svalue.to_s << ", 'unixepoch')").join
130
+ @log.debug('conv_time is ' << conv_time)
131
+ dbt.write_string_attribute(record_no, field_index, conv_time)
132
+
133
+ else
134
+ ftype = tmap.detect{|key, value| sql_type.start_with?(key) }[1]
135
+ dbt.write_string_attribute(record_no, field_index, svalue ) if 0 == ftype
136
+ begin
137
+ dbt.write_integer_attribute(record_no, field_index, svalue) if 1 == ftype
138
+ dbt.write_double_attribute(record_no, field_index, svalue) if 2 == ftype
139
+ rescue RangeError => ex
140
+ @log.error(trl("ERROR! cannot write value of type %s" %sql_type) << ': ' << ex.message )
141
+ end
123
142
  end
124
143
  else
125
- dbt.write_null_attribute(record_no, field_index) if (!svalue || type.empty?)
144
+ dbt.write_null_attribute(record_no, field_index) if (!svalue || sql_type.empty?)
126
145
  end
127
146
  end
128
147
  end
data/lib/translations CHANGED
@@ -39,14 +39,32 @@ Specific options:
39
39
  de: Spezielle Optionen
40
40
  fr: Options spécifiques
41
41
 
42
+ #program argument --time
43
+ time [list]:
44
+ de: zeit [Liste]
45
+ fr: temps [liste]
46
+
47
+ A list of space-separated fields (table-columns) which shall be handled as timestamp values.:
48
+ de: Eine Liste von Feldern (Tabellenspalten), die als Zeitstempel behandelt werden sollen.
49
+ fr: Une liste de champs (colonnes), qui seront traités comme estampes chronologiques.
50
+
51
+ # program argument --dates
52
+ dates [list]:
53
+ de: daten [liste]
54
+ fr: dates [liste]
55
+
56
+ A list of space-separated fields (table-columns) which shall be handled as date-time values.:
57
+ de: Eine Liste von Feldern (Tabellenspalten), die als Datums/Zeit-Werte behandelt werden sollen.
58
+ fr: Une liste de champs (colonnes), qui seront traités comme dates et temps.
59
+
42
60
  # program argument -s (source)
43
61
  s:
44
62
  de: q
45
63
  fr: s
46
64
 
47
- source/sqlite-file [FILE.sqlite]:
48
- de: quelle (SQLite) [Datei.sqlite]
49
- fr: source (SQLite) [Fichier.sqlite]
65
+ source [FILE.sqlite]:
66
+ de: quelle [Datei.sqlite]
67
+ fr: source [Fichier.sqlite]
50
68
 
51
69
  SQLite-file to read.:
52
70
  de: SQLite Datei, die gelesen wird.
@@ -78,9 +96,9 @@ t:
78
96
  de: z
79
97
  fr: c
80
98
 
81
- dBase-files [FILE(0...n).dbf]:
82
- de: dBase Dateien [Datei(0...n).dbf]
83
- fr: cible Fichier dBase [Fichier(0...n).dbf]
99
+ target [FILE(0...n).dbf]:
100
+ de: ziel [Datei(0...n).dbf]
101
+ fr: cible dBase [Fichier(0...n).dbf]
84
102
 
85
103
  Name for the dBase-files (1 per table) to be written.:
86
104
  de: Name der dBase-Dateien (1 pro Tabelle), die geschrieben werden.
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 = "missing files added."
6
+ s.summary = "Parameter --dates added for a list of datetime and time fields, Blob as text"
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.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Uplawski <michael.uplawski@uplawski.eu>
@@ -51,5 +51,5 @@ rubyforge_project:
51
51
  rubygems_version: 2.6.7
52
52
  signing_key:
53
53
  specification_version: 4
54
- summary: missing files added.
54
+ summary: Parameter --dates added for a list of datetime and time fields, Blob as text
55
55
  test_files: []