add more Finder::esc(...) and raw(...) methods

This commit is contained in:
Tomasz Sowa 2022-12-02 13:26:30 +01:00
parent 2ac8769d3a
commit dfc631dd06
3 changed files with 113 additions and 34 deletions

View File

@ -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) 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;
}

View File

@ -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 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::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_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 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 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 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::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 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<typename StringType> template<typename StringOrStreamType>
void put_string_generic(const StringType & str, const FT & field_type, bool add_quotes) void put_string_generic(const StringOrStreamType & str, const FT & field_type, bool add_quotes)
{ {
if( out_stream ) if( out_stream )
{ {

View File

@ -605,52 +605,43 @@ public:
Finder<ModelClass> & raw(const char * sql, bool add_spaces = true) Finder<ModelClass> & raw(const char * sql, bool add_spaces = true)
{ {
if( out_stream ) return raw_generic(sql, add_spaces);
{ }
if( add_spaces )
(*out_stream) << ' ';
(*out_stream) << sql;
if( add_spaces ) Finder<ModelClass> & raw(const wchar_t * sql, bool add_spaces = true)
(*out_stream) << ' '; {
} return raw_generic(sql, add_spaces);
}
return *this;
Finder<ModelClass> & raw(const std::string & sql, bool add_spaces = true)
{
return raw_generic(sql, add_spaces);
}
Finder<ModelClass> & raw(const std::wstring & sql, bool add_spaces = true)
{
return raw_generic(sql, add_spaces);
} }
Finder<ModelClass> & raw(const pt::TextStream & sql, bool add_spaces = true) Finder<ModelClass> & raw(const pt::TextStream & sql, bool add_spaces = true)
{ {
if( out_stream ) return raw_generic(sql, add_spaces);
{
if( add_spaces )
(*out_stream) << ' ';
(*out_stream) << sql;
if( add_spaces )
(*out_stream) << ' ';
}
return *this;
} }
Finder<ModelClass> & raw(long val, bool add_spaces = true) Finder<ModelClass> & raw(const pt::WTextStream & sql, bool add_spaces = true)
{ {
if( out_stream ) return raw_generic(sql, add_spaces);
{ }
if( add_spaces )
(*out_stream) << ' ';
(*out_stream) << val;
if( add_spaces ) Finder<ModelClass> & raw(long sql, bool add_spaces = true)
(*out_stream) << ' '; {
} return raw_generic(sql, add_spaces);
return *this;
} }
@ -698,6 +689,27 @@ public:
} }
Finder<ModelClass> & 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<ModelClass> & 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<ModelClass> get_cursor() Cursor<ModelClass> get_cursor()
{ {
@ -990,6 +1002,42 @@ private:
} }
} }
template<typename FieldValue>
Finder<ModelClass> & 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<typename FieldValue>
Finder<ModelClass> & 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 } // namespace