escape table names in Finder (select sql statement)

WIP: #2
This commit is contained in:
Tomasz Sowa 2021-04-30 01:23:22 +02:00
parent c87afb40d2
commit 2afe111c57
3 changed files with 82 additions and 8 deletions

View File

@ -121,6 +121,8 @@ public:
}
template<typename FieldValue>
void put_field_value_or_null(const FieldValue & field_value, FT field_type, ModelEnv * model_env)
{
@ -218,6 +220,69 @@ public:
}
void table_to_stream(PT::TextStream & stream, const wchar_t * schema_name, const wchar_t * table_name, ModelEnv * model_env)
{
this->out_stream = &stream;
//table(table_name, model_env);
before_first_part_long_field_name();
esc(schema_name, *out_stream);
after_first_part_long_field_name();
(*out_stream) << '.';
before_second_part_long_field_name();
esc(table_name, *out_stream);
after_second_part_long_field_name();
this->out_stream = nullptr;
}
void table_to_stream(PT::TextStream & stream, const PT::WTextStream & schema_name, const PT::WTextStream & table_name, ModelEnv * model_env)
{
this->out_stream = &stream;
//table(table_name, model_env);
before_first_part_long_field_name();
esc(schema_name, *out_stream);
after_first_part_long_field_name();
(*out_stream) << '.';
before_second_part_long_field_name();
esc(table_name, *out_stream);
after_second_part_long_field_name();
this->out_stream = nullptr;
}
void table_to_stream(PT::TextStream & stream, const wchar_t * table_name, ModelEnv * model_env)
{
this->out_stream = &stream;
//table(table_name, model_env);
if( is_long_field_name(table_name) )
put_long_field_name(table_name);
else
put_short_field_name(table_name, model_env);
this->out_stream = nullptr;
}
void table_to_stream(PT::TextStream & stream, const PT::WTextStream & table_name, ModelEnv * model_env)
{
this->out_stream = &stream;
//table(table_name, model_env);
before_short_field_name();
esc(table_name, *out_stream);
after_short_field_name();
this->out_stream = nullptr;
}
/*
* IMPLEMENT ME
* esc for: signed char, wchar_t, char16_t, char32_t

View File

@ -240,14 +240,21 @@ public:
if( !model.model_env->schema_name.empty() )
{
(*out_stream) << model.model_env->schema_name << ".";
db_expression->table_to_stream(*out_stream, model.model_env->schema_name, model.model_env->table_name, &model_env);
}
else
{
db_expression->table_to_stream(*out_stream, model.model_env->table_name, &model_env);
}
// IMPROVEME escape table name
(*out_stream) << model.model_env->table_name << " AS ";
(*out_stream) << model.model_env->table_name;
(*out_stream) << " ";
(*out_stream) << finder_helper.join_tables_str;
(*out_stream) << " AS ";
db_expression->table_to_stream(*out_stream, model.model_env->table_name, &model_env);
if( !finder_helper.join_tables_str.empty() )
{
(*out_stream) << " ";
(*out_stream) << finder_helper.join_tables_str;
}
}
return *this;

View File

@ -53,23 +53,25 @@ void PostgreSQLExpression::after_short_field_name()
void PostgreSQLExpression::before_first_part_long_field_name()
{
(*out_stream) << '"';
}
void PostgreSQLExpression::after_first_part_long_field_name()
{
(*out_stream) << '"';
}
void PostgreSQLExpression::before_second_part_long_field_name()
{
before_short_field_name();
(*out_stream) << '"';
}
void PostgreSQLExpression::after_second_part_long_field_name()
{
after_short_field_name();
(*out_stream) << '"';
}