add FT::date_only, FT::time_only and FT::no_time_zone flags
This commit is contained in:
parent
38e790c2ac
commit
0ce05850b3
|
@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018-2021, Tomasz Sowa
|
||||
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -39,11 +39,6 @@
|
|||
namespace morm
|
||||
{
|
||||
|
||||
void FlatExpression::esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type)
|
||||
{
|
||||
date.SerializeISO(stream);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018-2021, Tomasz Sowa
|
||||
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -45,7 +45,6 @@ class FlatExpression : public BaseExpression
|
|||
{
|
||||
public:
|
||||
|
||||
void esc(const pt::Date & date, pt::TextStream & stream, const FT & field_type);
|
||||
|
||||
|
||||
|
||||
|
|
20
src/ft.h
20
src/ft.h
|
@ -58,13 +58,16 @@ public:
|
|||
no_fetchable = 32, /* not supported yet */
|
||||
no_removable = 64,
|
||||
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,
|
||||
binary = 1024,
|
||||
json = 2048,
|
||||
space = 4096,
|
||||
pretty_print = 8192,
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
stream << " OFFSET " << (page_number*page_size) << " LIMIT " << page_size << " ";
|
||||
|
|
|
@ -45,8 +45,6 @@ class PostgreSQLExpression : public DbExpression
|
|||
{
|
||||
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);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue