fix: correctly use a table name when using Finder::use_table_prefix(true)
We cannot use aliases in the form of "tablename"."fieldname" - now it was changed to "tablename.fieldname". Sample how to get the id field, assuming the table name is 'mymodel'. mymodel = finder2. select(morm::Select::no_auto_generated_columns). use_table_prefix(true). raw("SELECT id AS \"mymodel.id\""). raw("FROM mymodel"). raw("WHERE id = 25"). get(); In addition, there was an error that the table name was not correctly set for the first object in the hierarchy - it was empty, e.g. ""."field_name"
This commit is contained in:
@@ -307,6 +307,10 @@ void BaseExpression::table_field_separator()
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::alias_names_separator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::before_schema_name()
|
||||
{
|
||||
@@ -338,6 +342,16 @@ void BaseExpression::after_field_name()
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::before_alias_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::after_alias_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::before_field_value(const std::wstring &, const FT & field_type, ModelEnv * model_env)
|
||||
{
|
||||
before_field_value_string(field_type, model_env);
|
||||
@@ -988,6 +1002,7 @@ void BaseExpression::put_table_and_field(const wchar_t * table_name, const wchar
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::put_table_and_field(const pt::WTextStream & table_name, const wchar_t * field_name, const FT & field_type)
|
||||
{
|
||||
if( out_stream )
|
||||
@@ -999,6 +1014,42 @@ void BaseExpression::put_table_and_field(const pt::WTextStream & table_name, con
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::put_alias(const pt::WTextStream & alias_name, int index)
|
||||
{
|
||||
if( out_stream )
|
||||
{
|
||||
before_alias_name();
|
||||
esc(alias_name, *out_stream);
|
||||
|
||||
if( index > 1 )
|
||||
{
|
||||
(*out_stream) << index;
|
||||
}
|
||||
|
||||
after_alias_name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::put_alias(const pt::WTextStream & alias_name_prefix, int index, const wchar_t * alias_name_postfix)
|
||||
{
|
||||
if( out_stream )
|
||||
{
|
||||
before_alias_name();
|
||||
esc(alias_name_prefix, *out_stream);
|
||||
|
||||
if( index > 1 )
|
||||
{
|
||||
(*out_stream) << index;
|
||||
}
|
||||
|
||||
alias_names_separator();
|
||||
esc(alias_name_postfix, *out_stream);
|
||||
after_alias_name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BaseExpression::put_string(const char * str, const FT & field_type, bool add_quotes)
|
||||
{
|
||||
@@ -1117,6 +1168,23 @@ void BaseExpression::table_and_field_to_stream(pt::TextStream & stream, const pt
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::alias_to_stream(pt::TextStream & stream, const pt::WTextStream & alias_name, int index)
|
||||
{
|
||||
this->out_stream = &stream;
|
||||
put_alias(alias_name, index);
|
||||
this->out_stream = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::alias_to_stream(pt::TextStream & stream, const pt::WTextStream & alias_name_prefix, int index, const wchar_t * alias_name_postfix)
|
||||
{
|
||||
this->out_stream = &stream;
|
||||
put_alias(alias_name_prefix, index, alias_name_postfix);
|
||||
this->out_stream = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void BaseExpression::string_to_stream(pt::TextStream & stream, const char * str, const FT & field_type, bool add_quotes)
|
||||
{
|
||||
|
Reference in New Issue
Block a user