diff --git a/src/baseexpression.cpp b/src/baseexpression.cpp index c3b5a5a..2838309 100644 --- a/src/baseexpression.cpp +++ b/src/baseexpression.cpp @@ -963,6 +963,18 @@ void BaseExpression::put_string(const std::wstring & str, const FT & field_type, } +void BaseExpression::put_stream(const pt::TextStream & str, const FT & field_type, bool add_quotes) +{ + put_string_generic(str, field_type, add_quotes); +} + + +void BaseExpression::put_stream(const pt::WTextStream & 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) { @@ -1077,6 +1089,21 @@ void BaseExpression::string_to_stream(pt::TextStream & stream, const std::wstrin } +void BaseExpression::stream_to_stream(pt::TextStream & stream_out, const pt::TextStream & stream_in, const FT & field_type, bool add_quotes) +{ + this->out_stream = &stream_out; + put_stream(stream_in, field_type, add_quotes); + this->out_stream = nullptr; +} + + +void BaseExpression::stream_to_stream(pt::TextStream & stream_out, const pt::WTextStream & stream_in, const FT & field_type, bool add_quotes) +{ + this->out_stream = &stream_out; + put_stream(stream_in, field_type, add_quotes); + this->out_stream = nullptr; +} + diff --git a/src/baseexpression.h b/src/baseexpression.h index 773cfdf..bdd839c 100644 --- a/src/baseexpression.h +++ b/src/baseexpression.h @@ -266,6 +266,8 @@ public: 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 put_stream(const pt::TextStream & str, const FT & field_type, bool add_quotes = false); + virtual void put_stream(const pt::WTextStream & 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); @@ -282,6 +284,8 @@ public: 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); + virtual void stream_to_stream(pt::TextStream & stream_out, const pt::TextStream & stream_in, const FT & field_type, bool add_quotes = false); + virtual void stream_to_stream(pt::TextStream & stream_out, const pt::WTextStream & stream_in, const FT & field_type, bool add_quotes = false); @@ -304,8 +308,8 @@ public: } } - template - void put_string_generic(const StringType & str, const FT & field_type, bool add_quotes) + template + void put_string_generic(const StringOrStreamType & str, const FT & field_type, bool add_quotes) { if( out_stream ) { diff --git a/src/finder.h b/src/finder.h index 41e701e..2201431 100644 --- a/src/finder.h +++ b/src/finder.h @@ -605,52 +605,43 @@ public: Finder & raw(const char * sql, bool add_spaces = true) { - if( out_stream ) - { - if( add_spaces ) - (*out_stream) << ' '; + return raw_generic(sql, add_spaces); + } - (*out_stream) << sql; - if( add_spaces ) - (*out_stream) << ' '; - } + Finder & raw(const wchar_t * sql, bool add_spaces = true) + { + return raw_generic(sql, add_spaces); + } - return *this; + + Finder & raw(const std::string & sql, bool add_spaces = true) + { + return raw_generic(sql, add_spaces); + } + + + Finder & raw(const std::wstring & sql, bool add_spaces = true) + { + return raw_generic(sql, add_spaces); } Finder & raw(const pt::TextStream & sql, bool add_spaces = true) { - if( out_stream ) - { - if( add_spaces ) - (*out_stream) << ' '; - - (*out_stream) << sql; - - if( add_spaces ) - (*out_stream) << ' '; - } - - return *this; + return raw_generic(sql, add_spaces); } - Finder & raw(long val, bool add_spaces = true) + Finder & raw(const pt::WTextStream & sql, bool add_spaces = true) { - if( out_stream ) - { - if( add_spaces ) - (*out_stream) << ' '; + return raw_generic(sql, add_spaces); + } - (*out_stream) << val; - if( add_spaces ) - (*out_stream) << ' '; - } - - return *this; + Finder & raw(long sql, bool add_spaces = true) + { + return raw_generic(sql, add_spaces); } @@ -698,6 +689,27 @@ public: } + Finder & esc(const pt::TextStream & str, bool add_quotes = true, const FT & field_type = morm::FT::default_type) + { + if( out_stream && db_expression ) + { + db_expression->stream_to_stream(*out_stream, str, field_type, add_quotes); + } + + return *this; + } + + + Finder & esc(const pt::WTextStream & str, bool add_quotes = true, const FT & field_type = morm::FT::default_type) + { + if( out_stream && db_expression ) + { + db_expression->stream_to_stream(*out_stream, str, field_type, add_quotes); + } + + return *this; + } + Cursor get_cursor() { @@ -990,6 +1002,42 @@ private: } } + + template + Finder & raw_generic(const FieldValue * sql, bool add_spaces = true) + { + if( out_stream ) + { + if( add_spaces ) + (*out_stream) << ' '; + + (*out_stream) << sql; + + if( add_spaces ) + (*out_stream) << ' '; + } + + return *this; + } + + + template + Finder & raw_generic(const FieldValue & sql, bool add_spaces = true) + { + if( out_stream ) + { + if( add_spaces ) + (*out_stream) << ' '; + + (*out_stream) << sql; + + if( add_spaces ) + (*out_stream) << ' '; + } + + return *this; + } + }; } // namespace