From 2ac8769d3a988de9209576b493a6f05c9c277866 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Fri, 2 Dec 2022 11:45:19 +0100 Subject: [PATCH] add Finder::esc(...) methods --- src/baseexpression.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++ src/baseexpression.h | 49 ++++++++++++++++++++++++++++++++++ src/finder.h | 45 +++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) diff --git a/src/baseexpression.cpp b/src/baseexpression.cpp index 7d3c1e0..c3b5a5a 100644 --- a/src/baseexpression.cpp +++ b/src/baseexpression.cpp @@ -939,6 +939,31 @@ void BaseExpression::put_table_and_field(const pt::WTextStream & table_name, con +void BaseExpression::put_string(const char * str, const FT & field_type, bool add_quotes) +{ + put_string_generic(str, field_type, add_quotes); +} + + +void BaseExpression::put_string(const wchar_t * str, const FT & field_type, bool add_quotes) +{ + put_string_generic(str, field_type, add_quotes); +} + + +void BaseExpression::put_string(const std::string & str, const FT & field_type, bool add_quotes) +{ + put_string_generic(str, field_type, add_quotes); +} + + +void BaseExpression::put_string(const std::wstring & str, const FT & field_type, bool add_quotes) +{ + put_string_generic(str, field_type, add_quotes); +} + + + void BaseExpression::schema_table_to_stream(pt::TextStream & stream, const wchar_t * schema_name, const wchar_t * table_name) { this->out_stream = &stream; @@ -1020,6 +1045,41 @@ void BaseExpression::table_and_field_to_stream(pt::TextStream & stream, const pt +void BaseExpression::string_to_stream(pt::TextStream & stream, const char * str, const FT & field_type, bool add_quotes) +{ + this->out_stream = &stream; + put_string(str, field_type, add_quotes); + this->out_stream = nullptr; +} + + +void BaseExpression::string_to_stream(pt::TextStream & stream, const wchar_t * str, const FT & field_type, bool add_quotes) +{ + this->out_stream = &stream; + put_string(str, field_type, add_quotes); + this->out_stream = nullptr; +} + + +void BaseExpression::string_to_stream(pt::TextStream & stream, const std::string & str, const FT & field_type, bool add_quotes) +{ + this->out_stream = &stream; + put_string(str, field_type, add_quotes); + this->out_stream = nullptr; +} + + +void BaseExpression::string_to_stream(pt::TextStream & stream, const std::wstring & str, const FT & field_type, bool add_quotes) +{ + this->out_stream = &stream; + put_string(str, field_type, add_quotes); + this->out_stream = nullptr; +} + + + + + bool BaseExpression::is_empty_field(const wchar_t * value) { return (!value || *value == '\0'); diff --git a/src/baseexpression.h b/src/baseexpression.h index 41e69cd..773cfdf 100644 --- a/src/baseexpression.h +++ b/src/baseexpression.h @@ -262,6 +262,11 @@ public: virtual void put_table_and_field(const wchar_t * table_name, const wchar_t * field_name, const FT & field_type); virtual void put_table_and_field(const pt::WTextStream & table_name, const wchar_t * field_name, const FT & field_type); + virtual void put_string(const char * str, const FT & field_type, bool add_quotes = false); + virtual void put_string(const wchar_t * str, const FT & field_type, bool add_quotes = false); + virtual void put_string(const std::string & str, const FT & field_type, bool add_quotes = false); + virtual void put_string(const std::wstring & str, const FT & field_type, bool add_quotes = false); + virtual void schema_table_to_stream(pt::TextStream & stream, const wchar_t * schema_name, const wchar_t * table_name); virtual void schema_table_to_stream(pt::TextStream & stream, const pt::WTextStream & schema_name, const pt::WTextStream & table_name); virtual void table_to_stream(pt::TextStream & stream, const wchar_t * table_name); @@ -273,6 +278,50 @@ public: virtual void table_and_field_to_stream(pt::TextStream & stream, const wchar_t * table_name, const wchar_t * field_name, const FT & field_type); virtual void table_and_field_to_stream(pt::TextStream & stream, const pt::WTextStream & table_name, const wchar_t * field_name, const FT & field_type); + virtual void string_to_stream(pt::TextStream & stream, const char * str, const FT & field_type, bool add_quotes = false); + virtual void string_to_stream(pt::TextStream & stream, const wchar_t * str, const FT & field_type, bool add_quotes = false); + virtual void string_to_stream(pt::TextStream & stream, const std::string & str, const FT & field_type, bool add_quotes = false); + virtual void string_to_stream(pt::TextStream & stream, const std::wstring & str, const FT & field_type, bool add_quotes = false); + + + + template + void put_string_generic(const StringType * str, const FT & field_type, bool add_quotes) + { + if( out_stream ) + { + if( add_quotes ) + { + before_field_value_string(field_type); + } + + esc(str, *out_stream, field_type); + + if( add_quotes ) + { + after_field_value_string(field_type); + } + } + } + + template + void put_string_generic(const StringType & str, const FT & field_type, bool add_quotes) + { + if( out_stream ) + { + if( add_quotes ) + { + before_field_value_string(field_type); + } + + esc(str, *out_stream, field_type); + + if( add_quotes ) + { + after_field_value_string(field_type); + } + } + } /* * IMPLEMENT ME diff --git a/src/finder.h b/src/finder.h index 0088889..41e701e 100644 --- a/src/finder.h +++ b/src/finder.h @@ -654,6 +654,51 @@ public: } + Finder & esc(const char * str, bool add_quotes = true, const FT & field_type = morm::FT::default_type) + { + if( out_stream && db_expression ) + { + db_expression->string_to_stream(*out_stream, str, field_type, add_quotes); + } + + return *this; + } + + + Finder & esc(const wchar_t * str, bool add_quotes = true, const FT & field_type = morm::FT::default_type) + { + if( out_stream && db_expression ) + { + db_expression->string_to_stream(*out_stream, str, field_type, add_quotes); + } + + return *this; + } + + + Finder & esc(const std::string & str, bool add_quotes = true, const FT & field_type = morm::FT::default_type) + { + if( out_stream && db_expression ) + { + db_expression->string_to_stream(*out_stream, str, field_type, add_quotes); + } + + return *this; + } + + + Finder & esc(const std::wstring & str, bool add_quotes = true, const FT & field_type = morm::FT::default_type) + { + if( out_stream && db_expression ) + { + db_expression->string_to_stream(*out_stream, str, field_type, add_quotes); + } + + return *this; + } + + + Cursor get_cursor() { Cursor cursor;