Skip to content

Commit b82f223

Browse files
authored
Merge pull request #1417 from joto/fix-empty-str-to-real-conv
Fix empty string to real number conversion from Lua to Pg
2 parents 497476d + e940cc6 commit b82f223

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/output-flex.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ void write_integer(db_copy_mgr_t<db_deleter_by_type_and_id_t> *copy_mgr,
302302
static void write_double(db_copy_mgr_t<db_deleter_by_type_and_id_t> *copy_mgr,
303303
flex_table_column_t const &column, char const *str)
304304
{
305+
if (*str == '\0') {
306+
write_null(copy_mgr, column);
307+
return;
308+
}
309+
305310
char *end = nullptr;
306311
double const value = std::strtod(str, &end);
307312

tests/data/test_output_flex_types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ function osm2pgsql.process_node(object)
119119
tint2 = n,
120120
tint4 = n,
121121
tint8 = n,
122+
treal = n,
122123
}
123124
end
124125
return

tests/test-output-flex-types.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ TEST_CASE("type string (with invalid number)")
176176
CHECK(7 == conn.get_count("nodes"));
177177

178178
// clang-format off
179-
CHECK(1 == conn.get_count("nodes", "ttext = '' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL"));
180-
CHECK(1 == conn.get_count("nodes", "ttext = 'abc' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL"));
181-
CHECK(1 == conn.get_count("nodes", "ttext = '0a' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL"));
182-
CHECK(1 == conn.get_count("nodes", "ttext = '0xa' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL"));
183-
CHECK(1 == conn.get_count("nodes", "ttext = '--1' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL"));
184-
CHECK(1 == conn.get_count("nodes", "ttext = '1foo' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL"));
185-
CHECK(1 == conn.get_count("nodes", "ttext = '1.2' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL"));
179+
CHECK(1 == conn.get_count("nodes", "ttext = '' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL AND treal IS NULL"));
180+
CHECK(1 == conn.get_count("nodes", "ttext = 'abc' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL AND treal IS NULL"));
181+
CHECK(1 == conn.get_count("nodes", "ttext = '0a' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL AND treal IS NULL"));
182+
CHECK(1 == conn.get_count("nodes", "ttext = '0xa' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL AND abs(treal - 10) < 0.0000001"));
183+
CHECK(1 == conn.get_count("nodes", "ttext = '--1' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL AND treal IS NULL"));
184+
CHECK(1 == conn.get_count("nodes", "ttext = '1foo' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL AND treal IS NULL"));
185+
CHECK(1 == conn.get_count("nodes", "ttext = '1.2' AND tint2 IS NULL AND tint4 IS NULL AND tint8 IS NULL AND abs(treal - 1.2) < 0.0000001"));
186186
// clang-format on
187187
}
188188

0 commit comments

Comments
 (0)