fix: correctly escape a pt::Stream in Finder from like() and similar methods

while here:
- in Finder: use pt::Stream and pt::TextStreamBase<> instead of pt::TextStream and pt::WTextStream
- add Finder::raw(...) methods with short int, int, long long and integer unsigned types
This commit is contained in:
2024-05-31 00:31:30 +02:00
parent 9a3f6a6e36
commit 6fb7e29867
5 changed files with 229 additions and 106 deletions

View File

@@ -249,8 +249,13 @@ public:
virtual void put_string(const wchar_t * str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void put_string(const std::string & str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void put_string(const std::wstring & str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void put_stream(const pt::TextStream & str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void put_stream(const pt::WTextStream & str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void put_stream(const pt::Stream & str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
template<typename char_type, size_t stack_size, size_t heap_block_size>
void put_stream(const pt::TextStreamBase<char_type, stack_size, heap_block_size> & str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr)
{
put_string_generic(str, field_type, add_quotes, model_env);
}
virtual void schema_table_to_stream(pt::Stream & stream, const wchar_t * schema_name, const wchar_t * table_name);
virtual void schema_table_to_stream(pt::Stream & stream, const pt::WTextStream & schema_name, const pt::WTextStream & table_name);
@@ -269,8 +274,16 @@ public:
virtual void string_to_stream(pt::Stream & stream, const wchar_t * str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void string_to_stream(pt::Stream & stream, const std::string & str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void string_to_stream(pt::Stream & stream, const std::wstring & str, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void stream_to_stream(pt::Stream & stream_out, const pt::TextStream & stream_in, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void stream_to_stream(pt::Stream & stream_out, const pt::WTextStream & stream_in, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
virtual void stream_to_stream(pt::Stream & stream_out, const pt::Stream & stream_in, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr);
template<typename char_type, size_t stack_size, size_t heap_block_size>
void stream_to_stream(pt::Stream & stream_out, const pt::TextStreamBase<char_type, stack_size, heap_block_size> & stream_in, const FT & field_type, bool add_quotes = false, ModelEnv * model_env = nullptr)
{
this->out_stream = &stream_out;
put_stream(stream_in, field_type, add_quotes, model_env);
this->out_stream = nullptr;
}
@@ -344,10 +357,35 @@ public:
virtual void esc(long double val, pt::Stream & stream, const FT & field_type = FT::default_type, ModelEnv * model_env = nullptr);
virtual void esc(const pt::Date & date, pt::Stream & stream, const FT & field_type = FT::default_type, ModelEnv * model_env = nullptr);
virtual void esc(const pt::TextStream & val, pt::Stream & stream, const FT & field_type = FT::default_type, ModelEnv * model_env = nullptr);
virtual void esc(const pt::WTextStream & val, pt::Stream & stream, const FT & field_type = FT::default_type, ModelEnv * model_env = nullptr);
virtual void esc(const pt::Space & space, pt::Stream & stream, const FT & field_type = FT::default_type, ModelEnv * model_env = nullptr);
virtual void esc(const pt::Stream & val, pt::Stream & stream, const FT & field_type = FT::default_type, ModelEnv * model_env = nullptr);
template<typename char_type, size_t stack_size, size_t heap_block_size>
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() )
{
// from utf8 to utf8 or from utf8 to wide
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();
pt::utf8_to_output_function(start, end, [&](int z) {
esc(static_cast<wchar_t>(z), stream, field_type, model_env);
});
}
else
if( val.is_wchar_stream() )
{
// from wide to wide or from wide to utf8
typename pt::TextStreamBase<char_type, stack_size, heap_block_size>::const_iterator i = val.begin();
typename pt::TextStreamBase<char_type, stack_size, heap_block_size>::const_iterator end = val.end();
for(; i != end ; ++i)
{
esc(*i, stream, field_type, model_env);
}
}
}
protected:
@@ -643,15 +681,34 @@ protected:
virtual void after_field_value(const pt::Space &, const FT & field_type, ModelEnv * model_env);
template<typename FieldValue>
void before_field_value(const FieldValue &, const FT & field_type, ModelEnv * model_env)
void before_field_value(const FieldValue & field_value, const FT & field_type, ModelEnv * model_env)
{
if constexpr ( std::is_base_of<pt::Stream, FieldValue>() )
{
before_field_value_string(field_type, model_env);
}
else
{
before_field_value_generic();
}
}
template<typename FieldValue>
void after_field_value(const FieldValue &, const FT & field_type, ModelEnv * model_env)
{
if constexpr ( std::is_base_of<pt::Stream, FieldValue>() )
{
after_field_value_string(field_type, model_env);
}
else
{
after_field_value_generic();
}
}
virtual void before_field_value_generic();
virtual void after_field_value_generic();
virtual void put_name_value_separator();