add FT::date_only, FT::time_only and FT::no_time_zone flags

This commit is contained in:
Tomasz Sowa 2022-10-22 16:29:40 +02:00
parent 38e790c2ac
commit 0ce05850b3
7 changed files with 55 additions and 19 deletions

View File

@ -602,7 +602,26 @@ void BaseExpression::esc(long double val, pt::TextStream & stream, const FT & fi
void BaseExpression::esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type) void BaseExpression::esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type)
{ {
stream << date; if( field_type.is_date_only() )
{
date.SerializeYearMonthDay(stream, false);
}
else
if( field_type.is_time_only() )
{
date.SerializeHourMinSec(stream);
}
else
{
if( field_type.is_no_time_zone() )
{
date.Serialize(stream);
}
else
{
date.SerializeISO(stream);
}
}
} }

View File

@ -850,7 +850,20 @@ void DbConnector::get_value(const char * value_str, long double & field_value, c
void DbConnector::get_value(const char * value_str, pt::Date & field_value, const FT & field_type) void DbConnector::get_value(const char * value_str, pt::Date & field_value, const FT & field_type)
{ {
// IMPROVE ME give some log if parsing failed // IMPROVE ME give some log if parsing failed
field_value.Parse(value_str);
if( field_type.is_date_only() )
{
field_value.ParseDayMonthYear(value_str);
}
else
if( field_type.is_time_only() )
{
field_value.ParseHourMinSec(value_str);
}
else
{
field_value.Parse(value_str, !field_type.is_no_time_zone());
}
} }

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2018-2021, Tomasz Sowa * Copyright (c) 2018-2022, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -39,11 +39,6 @@
namespace morm namespace morm
{ {
void FlatExpression::esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type)
{
date.SerializeISO(stream);
}
} }

View File

@ -5,7 +5,7 @@
*/ */
/* /*
* Copyright (c) 2018-2021, Tomasz Sowa * Copyright (c) 2018-2022, Tomasz Sowa
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,7 +45,6 @@ class FlatExpression : public BaseExpression
{ {
public: public:
void esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type);

View File

@ -58,13 +58,16 @@ public:
no_fetchable = 32, /* not supported yet */ no_fetchable = 32, /* not supported yet */
no_removable = 64, no_removable = 64,
raw_field_name = 128, raw_field_name = 128,
dont_use_utf8 = 256, /* used only with wchar_t and std::wstring, ignored if binary or hexadecimal flags are used */ dont_use_utf8 = 256, /* used only with wchar_t and std::wstring, ignored if a binary or a hexadecimal flags are used */
hexadecimal = 512, hexadecimal = 512,
binary = 1024, binary = 1024,
json = 2048, json = 2048,
space = 4096, space = 4096,
pretty_print = 8192, pretty_print = 8192,
numeric = 16384, numeric = 16384,
date_only = 32768, /* use only year, month and day from pt::Date, no_time_zone flag is not used here */
time_only = 65536, /* use only hour, min, sec from pt::Date, no_time_zone flag is not used here */
no_time_zone = 131072, /* no time zone, used only with pt::Date */
}; };
/* /*
@ -194,6 +197,21 @@ public:
return is_flag_set(numeric); return is_flag_set(numeric);
} }
bool is_date_only() const
{
return is_flag_set(date_only);
}
bool is_time_only() const
{
return is_flag_set(time_only);
}
bool is_no_time_zone() const
{
return is_flag_set(no_time_zone);
}
}; };
} }

View File

@ -92,12 +92,6 @@ bool PostgreSQLExpression::esc_char(wchar_t val, pt::TextStream & stream)
} }
void PostgreSQLExpression::esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type)
{
stream << date << "+00";
}
DbExpression & PostgreSQLExpression::page(pt::TextStream & stream, size_t page_number, size_t page_size) DbExpression & PostgreSQLExpression::page(pt::TextStream & stream, size_t page_number, size_t page_size)
{ {
stream << " OFFSET " << (page_number*page_size) << " LIMIT " << page_size << " "; stream << " OFFSET " << (page_number*page_size) << " LIMIT " << page_size << " ";

View File

@ -45,8 +45,6 @@ class PostgreSQLExpression : public DbExpression
{ {
public: public:
void esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type);
DbExpression & page(pt::TextStream & stream, size_t page_number, size_t page_size); DbExpression & page(pt::TextStream & stream, size_t page_number, size_t page_size);