From a1b3b0140fd6e2f9fad346bf70ff839ee051f2c3 Mon Sep 17 00:00:00 2001 From: VaclavT Date: Tue, 31 Aug 2021 18:58:46 +0200 Subject: [PATCH] date printed with time now --- Readme.md | 5 ++++- row.cpp | 18 ++++++++++++++---- settings.cpp | 3 ++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index b0d6821..89ebd20 100644 --- a/Readme.md +++ b/Readme.md @@ -1,5 +1,6 @@ - ### TODO +- escape " in save csv +- is null | is not null - coalesce, date functions now, add_date; string functions rtrim, ltrim, rpad, lpad; math function round - add pipe | concatenation @@ -9,6 +10,8 @@ - support for joining - add count min and max functions, eg aggregate functions +- use string_to_double and string_to_long (from Table) everywhere - add const wherever should be +- use static methods where posible - PERF in Row::Row(const Row &other), could be more efficient (memory and cpu) - use references where pointer cannot be nullptr diff --git a/row.cpp b/row.cpp index 7325bef..89e0cd8 100644 --- a/row.cpp +++ b/row.cpp @@ -133,7 +133,7 @@ void Row::setColumnValue(ColDefNode *col_def, ValueNode *col_value) { else if (col_def->type == ColumnType::varchar_type) setStringColumnValue(col_def->order, col_value->getStringValue()); else if (col_def->type == ColumnType::date_type) - setIntColumnValue(col_def->order, col_value->getDateValue()); + setDateColumnValue(col_def->order, col_value->getDateValue()); else if (col_def->type == ColumnType::bool_type) setBoolColumnValue(col_def->order, col_value->getBooleanValue()); else @@ -169,9 +169,19 @@ void Row::print(const std::vector &col_defs) { int Row::print_get_column_size(const ColDefNode &col_def) { - int col_size = col_def.type == ColumnType::varchar_type ? col_def.length : - col_def.type == ColumnType::float_type ? 16 : 10; - return col_size; + switch (col_def.type) { + case ColumnType::varchar_type: + return col_def.length; + break; + case ColumnType::date_type: + return 19; + break; + case ColumnType::float_type: + return 16; + break; + default: + return 10; + } } } // namespace diff --git a/settings.cpp b/settings.cpp index 6a72a5e..4f23916 100644 --- a/settings.cpp +++ b/settings.cpp @@ -6,7 +6,7 @@ namespace usql { std::vector> Settings::m_settings = - { std::make_pair("DATE_FORMAT", "%Y-%m-%d"), + { std::make_pair("DATE_FORMAT", "%Y-%m-%d %H:%M:%S"), std::make_pair("BOOL_TRUE_LITERAL", "Y"), std::make_pair("BOOL_FALSE_LITERAL", "N"), std::make_pair("DOUBLE_FORMAT", "%.2f") }; @@ -21,6 +21,7 @@ std::string Settings::date_to_string(long date) { return ::date_to_string(date, get_setting("DATE_FORMAT")); } + std::string Settings::double_to_string(double d) { char buffer[32]; int r, buf_size = 32;