add Model::field(...) methods with a pt::Stream argument
This commit is contained in:
parent
90b4d9af0b
commit
cd067ae5c3
|
@ -735,12 +735,22 @@ void BaseExpression::esc(const pt::Space & space, pt::Stream & stream, const FT
|
|||
void BaseExpression::esc(const pt::Stream & val, pt::Stream & stream, const FT & field_type, ModelEnv * model_env)
|
||||
{
|
||||
if( val.is_char_stream() )
|
||||
{
|
||||
if( field_type.is_hexadecimal() || field_type.is_binary() )
|
||||
{
|
||||
for(size_t i=0 ; i<val.size() ; ++i )
|
||||
{
|
||||
esc(val.get_char(i), stream, field_type, model_env);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// from utf8 to utf8 or from utf8 to wide
|
||||
pt::utf8_to_output_function_by_index(val, [&](int z) {
|
||||
esc(static_cast<char32_t>(z), stream, field_type, model_env);
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
if( val.is_wchar_stream() )
|
||||
{
|
||||
|
|
|
@ -366,12 +366,25 @@ public:
|
|||
void esc(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & val, pt::Stream & stream, const FT & field_type = FT::default_type, ModelEnv * model_env = nullptr)
|
||||
{
|
||||
if( val.is_char_stream() )
|
||||
{
|
||||
if( field_type.is_hexadecimal() || field_type.is_binary() )
|
||||
{
|
||||
typename pt::TextStreamBase<char_type, stack_size, heap_block_size>::const_iterator start = val.begin();
|
||||
typename pt::TextStreamBase<char_type, stack_size, heap_block_size>::const_iterator end = val.end();
|
||||
|
||||
for( ; start != end ; ++start )
|
||||
{
|
||||
esc(static_cast<char>(*start), stream, field_type, model_env);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// from utf8 to utf8 or from utf8 to wide
|
||||
pt::utf8_to_output_function(val, [&](int z) {
|
||||
esc(static_cast<char32_t>(z), stream, field_type, model_env);
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
if( val.is_wchar_stream() )
|
||||
{
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||
* Copyright (c) 2018-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -162,6 +162,11 @@ void Clearer::clear_value(pt::Space & field_value, const FT & field_type)
|
|||
field_value.clear();
|
||||
}
|
||||
|
||||
void Clearer::clear_value(pt::Stream & field_value, const FT & field_type)
|
||||
{
|
||||
field_value.clear();
|
||||
}
|
||||
|
||||
void Clearer::clear_model(Model & field_value, const FT & field_type)
|
||||
{
|
||||
field_value.clear();
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018-2022, Tomasz Sowa
|
||||
* Copyright (c) 2018-2024, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
@ -72,6 +72,7 @@ public:
|
|||
virtual void clear_value(long double & field_value, const FT & field_type);
|
||||
virtual void clear_value(pt::Date & field_value, const FT & field_type);
|
||||
virtual void clear_value(pt::Space & field_value, const FT & field_type);
|
||||
virtual void clear_value(pt::Stream & field_value, const FT & field_type);
|
||||
|
||||
virtual void clear_model(Model & field_value, const FT & field_type);
|
||||
|
||||
|
|
|
@ -568,6 +568,7 @@ const char * DbConnector::unescape_hex_char(const char * str, size_t len, unsign
|
|||
{
|
||||
unsigned int c;
|
||||
res = 0;
|
||||
bool was_log_printed = false;
|
||||
|
||||
for(size_t i = 0 ; i < len ; ++i)
|
||||
{
|
||||
|
@ -579,6 +580,13 @@ const char * DbConnector::unescape_hex_char(const char * str, size_t len, unsign
|
|||
else
|
||||
{
|
||||
c = 0;
|
||||
|
||||
if( log && !was_log_printed )
|
||||
{
|
||||
(*log) << pt::Log::log2 << "Morm: the hex string ended unexpectedly, filling the part of the the last character with zeroes"
|
||||
<< pt::Log::logend;
|
||||
was_log_printed = true;
|
||||
}
|
||||
}
|
||||
|
||||
res = (res << 4) | c;
|
||||
|
@ -640,6 +648,30 @@ void DbConnector::unescape_hex_string(const char * str, std::wstring & out)
|
|||
}
|
||||
|
||||
|
||||
void DbConnector::unescape_hex_string(const char * str, pt::Stream & out)
|
||||
{
|
||||
unsigned int c = 0;
|
||||
|
||||
if( out.is_char_stream() )
|
||||
{
|
||||
while( *str != 0 )
|
||||
{
|
||||
str = unescape_hex_char(str, sizeof(char) * 2, c);
|
||||
out << (char)c;
|
||||
}
|
||||
}
|
||||
else
|
||||
if( out.is_wchar_stream() )
|
||||
{
|
||||
while( *str != 0 )
|
||||
{
|
||||
str = unescape_hex_char(str, sizeof(wchar_t) * 2, c);
|
||||
out << (wchar_t)c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::unescape_bin_string(const char * str, std::string & out)
|
||||
{
|
||||
unescape_hex_string(str, out);
|
||||
|
@ -652,6 +684,11 @@ void DbConnector::unescape_bin_string(const char * str, std::wstring & out)
|
|||
}
|
||||
|
||||
|
||||
void DbConnector::unescape_bin_string(const char * str, pt::Stream & out)
|
||||
{
|
||||
unescape_hex_string(str, out);
|
||||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, char & field_value, const FT & field_type)
|
||||
{
|
||||
|
@ -922,6 +959,34 @@ void DbConnector::get_value(const char * value_str, pt::Space & field_value, con
|
|||
}
|
||||
|
||||
|
||||
void DbConnector::get_value(const char * value_str, pt::Stream & field_value, const FT & field_type)
|
||||
{
|
||||
if( field_type.is_hexadecimal() )
|
||||
{
|
||||
unescape_hex_string(value_str, field_value);
|
||||
}
|
||||
else
|
||||
if( field_type.is_binary() )
|
||||
{
|
||||
unescape_bin_string(value_str, field_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( field_type.use_utf8() )
|
||||
{
|
||||
pt::utf8_to_wide(value_str, field_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(size_t i=0 ; value_str[i] != 0 ; ++i)
|
||||
{
|
||||
field_value << static_cast<wchar_t>((unsigned char)value_str[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const char * DbConnector::query_last_sequence(const wchar_t * sequence_table_name)
|
||||
{
|
||||
return nullptr;
|
||||
|
|
|
@ -157,8 +157,9 @@ public:
|
|||
virtual void get_value(const char * value_str, long double & field_value, const FT & field_type = FT::default_type);
|
||||
virtual void get_value(const char * value_str, pt::Date & field_value, const FT & field_type = FT::default_type);
|
||||
virtual void get_value(const char * value_str, pt::Space & field_value, const FT & field_type = FT::default_type);
|
||||
virtual void get_value(const char * value_str, pt::Stream & field_value, const FT & field_type = FT::default_type);
|
||||
|
||||
|
||||
// add get_value for pt::TextStream and pt::WTextStream
|
||||
|
||||
template<typename FieldValue>
|
||||
bool get_last_sequence(const wchar_t * sequence_table_name, FieldValue & field_value)
|
||||
|
@ -205,9 +206,11 @@ protected:
|
|||
|
||||
virtual void unescape_hex_string(const char * str, std::string & out);
|
||||
virtual void unescape_hex_string(const char * str, std::wstring & out);
|
||||
virtual void unescape_hex_string(const char * str, pt::Stream & out);
|
||||
|
||||
virtual void unescape_bin_string(const char * str, std::string & out);
|
||||
virtual void unescape_bin_string(const char * str, std::wstring & out);
|
||||
virtual void unescape_bin_string(const char * str, pt::Stream & out);
|
||||
|
||||
virtual bool rollback_one_transaction(size_t index);
|
||||
virtual bool commit_one_transaction(size_t index);
|
||||
|
|
23
src/model.h
23
src/model.h
|
@ -475,6 +475,17 @@ protected:
|
|||
field_model(field_name, field_name, field_value, field_type);
|
||||
}
|
||||
|
||||
void field(const wchar_t * field_name, pt::Stream & field_value, const FT & field_type = FT::default_type)
|
||||
{
|
||||
field_generic(field_name, field_name, field_value, field_type);
|
||||
}
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
void field(const wchar_t * field_name, pt::TextStreamBase<char_type, stack_size, heap_block_size> & field_value, const FT & field_type = FT::default_type)
|
||||
{
|
||||
field_generic(field_name, field_name, field_value, field_type);
|
||||
}
|
||||
|
||||
template<typename ContainerItemType>
|
||||
void field(const wchar_t * field_name, std::list<ContainerItemType> & field_value, const FT & field_type = FT::default_type)
|
||||
{
|
||||
|
@ -605,6 +616,17 @@ protected:
|
|||
field_model(db_field_name, flat_field_name, field_value, field_type);
|
||||
}
|
||||
|
||||
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, pt::Stream & field_value, const FT & field_type = FT::default_type)
|
||||
{
|
||||
field_generic(db_field_name, flat_field_name, field_value, field_type);
|
||||
}
|
||||
|
||||
template<typename char_type, size_t stack_size, size_t heap_block_size>
|
||||
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, pt::TextStreamBase<char_type, stack_size, heap_block_size> & field_value, const FT & field_type = FT::default_type)
|
||||
{
|
||||
field_generic(db_field_name, flat_field_name, field_value, field_type);
|
||||
}
|
||||
|
||||
template<typename ContainerItemType>
|
||||
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, std::list<ContainerItemType> & field_value, const FT & field_type = FT::default_type)
|
||||
{
|
||||
|
@ -875,6 +897,7 @@ protected:
|
|||
}
|
||||
|
||||
|
||||
|
||||
void field_member_set_field_value(
|
||||
const wchar_t * db_field_name,
|
||||
const wchar_t * flat_field_name,
|
||||
|
|
|
@ -597,4 +597,17 @@ void PostgreSQLConnector::unescape_bin_string(const char * str, std::wstring & o
|
|||
}
|
||||
|
||||
|
||||
void PostgreSQLConnector::unescape_bin_string(const char * str, pt::Stream & out)
|
||||
{
|
||||
if( str[0]!='\\' || str[1]!='x' )
|
||||
{
|
||||
log_unsupported_bin_format();
|
||||
}
|
||||
else
|
||||
{
|
||||
DbConnector::unescape_bin_string(str + 2, out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -160,6 +160,7 @@ protected:
|
|||
|
||||
void unescape_bin_string(const char * str, std::string & out) override;
|
||||
void unescape_bin_string(const char * str, std::wstring & out) override;
|
||||
void unescape_bin_string(const char * str, pt::Stream & out) override;
|
||||
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue