in BaseExpression: changed the way how field names are escaped:
methods removed: virtual void before_field_name(); virtual void after_field_name(); methods added: virtual void before_short_field_name(); virtual void after_short_field_name(); they are used for escaping column names in a case when using short form - just only column_name e.g.: [before_short_field_name]column_name[after_short_field_name] methods added: virtual void before_first_part_long_field_name(); virtual void after_first_part_long_field_name(); virtual void before_second_part_long_field_name(); virtual void after_second_part_long_field_name(); they are used for escaping column names in a case when using long form: table_name.column_name e.g.: [before_first_part_long_field_name]table_name[after_first_part_long_field_name].[before_second_part_long_field_name]column_name[after_second_part_long_field_name] methods added: virtual void esc(wchar_t val, PT::TextStream & stream);
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018-2019, Tomasz Sowa
|
||||
* Copyright (c) 2018-2021, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -204,37 +204,75 @@ bool BaseExpression::is_long_table_name(const PT::TextStream & table_name)
|
||||
}
|
||||
|
||||
|
||||
bool BaseExpression::need_to_add_field_prefix(const wchar_t * field_name)
|
||||
{
|
||||
return !is_long_field_name(field_name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BaseExpression::put_field_name(const wchar_t * field_name, ModelEnv * model_env)
|
||||
{
|
||||
before_field_name();
|
||||
|
||||
if( use_prefix && model_env )
|
||||
{
|
||||
if( need_to_add_field_prefix(field_name) )
|
||||
{
|
||||
esc(model_env->table_name_short, *out_stream);
|
||||
|
||||
if( model_env->table_index > 1 )
|
||||
{
|
||||
(*out_stream) << model_env->table_index;
|
||||
}
|
||||
|
||||
(*out_stream) << '.';
|
||||
}
|
||||
}
|
||||
|
||||
esc(field_name, *out_stream);
|
||||
after_field_name();
|
||||
if( is_long_field_name(field_name) )
|
||||
put_long_field_name(field_name);
|
||||
else
|
||||
put_short_field_name(field_name, model_env);
|
||||
}
|
||||
|
||||
|
||||
const wchar_t * BaseExpression::put_long_part_field_name(const wchar_t * field_name)
|
||||
{
|
||||
while( *field_name != 0 && *field_name != '.' )
|
||||
{
|
||||
esc(*field_name, *out_stream);
|
||||
field_name += 1;
|
||||
}
|
||||
|
||||
return field_name;
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::put_long_field_name(const wchar_t * field_name)
|
||||
{
|
||||
before_first_part_long_field_name();
|
||||
field_name = put_long_part_field_name(field_name);
|
||||
after_first_part_long_field_name();
|
||||
|
||||
if( *field_name == '.' )
|
||||
{
|
||||
field_name += 1;
|
||||
(*out_stream) << '.';
|
||||
|
||||
before_second_part_long_field_name();
|
||||
field_name = put_long_part_field_name(field_name);
|
||||
after_second_part_long_field_name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::put_short_field_name(const wchar_t * field_name, ModelEnv * model_env)
|
||||
{
|
||||
if( use_prefix && model_env )
|
||||
{
|
||||
before_first_part_long_field_name();
|
||||
esc(model_env->table_name_short, *out_stream);
|
||||
|
||||
if( model_env->table_index > 1 )
|
||||
{
|
||||
(*out_stream) << model_env->table_index;
|
||||
}
|
||||
|
||||
after_first_part_long_field_name();
|
||||
|
||||
(*out_stream) << '.';
|
||||
|
||||
before_second_part_long_field_name();
|
||||
esc(field_name, *out_stream);
|
||||
after_second_part_long_field_name();
|
||||
}
|
||||
else
|
||||
{
|
||||
before_short_field_name();
|
||||
esc(field_name, *out_stream);
|
||||
after_short_field_name();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BaseExpression::save_foreign_key(const wchar_t * field_name, ModelEnv * model_env)
|
||||
{
|
||||
PT::TextStream str;
|
||||
@@ -253,16 +291,37 @@ void BaseExpression::save_foreign_key(const wchar_t * field_name, ModelEnv * mod
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::before_field_name()
|
||||
void BaseExpression::before_short_field_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::after_field_name()
|
||||
void BaseExpression::after_short_field_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::before_first_part_long_field_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::after_first_part_long_field_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::before_second_part_long_field_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::after_second_part_long_field_name()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BaseExpression::before_field_value(const std::wstring &)
|
||||
{
|
||||
}
|
||||
@@ -330,6 +389,19 @@ void BaseExpression::esc(unsigned char val, PT::TextStream & stream)
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::esc(wchar_t val, PT::TextStream & stream)
|
||||
{
|
||||
char utf8_buf[10];
|
||||
|
||||
size_t utf8_len = PT::IntToUTF8((int)val, utf8_buf, sizeof(utf8_buf));
|
||||
|
||||
for(size_t a = 0 ; a < utf8_len ; ++a)
|
||||
{
|
||||
esc(utf8_buf[a], stream);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BaseExpression::esc(const std::wstring & val, PT::TextStream & stream)
|
||||
{
|
||||
char utf8_buf[10];
|
||||
|
Reference in New Issue
Block a user