allow to set a custom name for the auto generated rows counter column
This commit is contained in:
parent
c56bae57ca
commit
d61fc31b5c
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2022, Tomasz Sowa
|
* Copyright (c) 2018-2023, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -350,19 +350,29 @@ void DbExpression::add_rows_counter_column(Model & model)
|
||||||
{
|
{
|
||||||
field_before();
|
field_before();
|
||||||
(*out_stream) << "COUNT(*) OVER() AS ";
|
(*out_stream) << "COUNT(*) OVER() AS ";
|
||||||
|
before_field_name();
|
||||||
|
|
||||||
pt::TextStream str;
|
if( model.model_env->rows_counter_column_name.empty() )
|
||||||
generate_rows_counter_column_name(*model.model_env, str);
|
|
||||||
|
|
||||||
if( !model.model_env->has_autogenerated_select )
|
|
||||||
{
|
{
|
||||||
str.to_str(model.model_env->rows_counter_column_name);
|
pt::TextStream str;
|
||||||
|
generate_rows_counter_column_name(*model.model_env, str);
|
||||||
|
esc(str, *out_stream);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* for autogenerated selects we don't have to copy the rows_counter_column_name
|
||||||
|
* because a field() method will use an index instead of this name
|
||||||
|
*/
|
||||||
|
if( !model.model_env->has_autogenerated_select )
|
||||||
|
{
|
||||||
|
str.to_str(model.model_env->rows_counter_column_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
esc(model.model_env->rows_counter_column_name, *out_stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
before_field_name();
|
|
||||||
esc(str, *out_stream);
|
|
||||||
after_field_name();
|
after_field_name();
|
||||||
|
|
||||||
field_after();
|
field_after();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
22
src/finder.h
22
src/finder.h
|
@ -63,6 +63,7 @@ public:
|
||||||
db_expression = nullptr;
|
db_expression = nullptr;
|
||||||
was_query_error = false;
|
was_query_error = false;
|
||||||
model_data = nullptr;
|
model_data = nullptr;
|
||||||
|
rows_counter_name = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +74,7 @@ public:
|
||||||
db_expression = nullptr;
|
db_expression = nullptr;
|
||||||
was_query_error = false;
|
was_query_error = false;
|
||||||
model_data = nullptr;
|
model_data = nullptr;
|
||||||
|
rows_counter_name = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Finder(ModelConnector & model_connector)
|
Finder(ModelConnector & model_connector)
|
||||||
|
@ -82,6 +84,7 @@ public:
|
||||||
db_expression = nullptr;
|
db_expression = nullptr;
|
||||||
was_query_error = false;
|
was_query_error = false;
|
||||||
model_data = nullptr;
|
model_data = nullptr;
|
||||||
|
rows_counter_name = nullptr;
|
||||||
set_out_stream();
|
set_out_stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +95,7 @@ public:
|
||||||
db_expression = nullptr;
|
db_expression = nullptr;
|
||||||
was_query_error = false;
|
was_query_error = false;
|
||||||
model_data = nullptr;
|
model_data = nullptr;
|
||||||
|
rows_counter_name = nullptr;
|
||||||
set_out_stream();
|
set_out_stream();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +106,7 @@ public:
|
||||||
db_expression = nullptr;
|
db_expression = nullptr;
|
||||||
was_query_error = false;
|
was_query_error = false;
|
||||||
model_data = nullptr;
|
model_data = nullptr;
|
||||||
|
rows_counter_name = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Finder(pt::TextStream & out_stream, ModelConnector * model_connector)
|
Finder(pt::TextStream & out_stream, ModelConnector * model_connector)
|
||||||
|
@ -111,6 +116,7 @@ public:
|
||||||
db_expression = nullptr;
|
db_expression = nullptr;
|
||||||
was_query_error = false;
|
was_query_error = false;
|
||||||
model_data = nullptr;
|
model_data = nullptr;
|
||||||
|
rows_counter_name = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Finder<ModelClass> & set_connector(ModelConnector * model_connector)
|
Finder<ModelClass> & set_connector(ModelConnector * model_connector)
|
||||||
|
@ -151,6 +157,17 @@ public:
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Finder<ModelClass> & set_rows_counter_name(const wchar_t * rows_counter_name)
|
||||||
|
{
|
||||||
|
this->rows_counter_name = rows_counter_name;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Finder<ModelClass> & set_rows_counter_name(const std::wstring & rows_counter_name)
|
||||||
|
{
|
||||||
|
this->rows_counter_name = &rows_counter_name;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
bool was_error()
|
bool was_error()
|
||||||
{
|
{
|
||||||
|
@ -1228,6 +1245,9 @@ protected:
|
||||||
model_env.finder_helper = &finder_helper;
|
model_env.finder_helper = &finder_helper;
|
||||||
model_env.model = &model;
|
model_env.model = &model;
|
||||||
|
|
||||||
|
if( rows_counter_name )
|
||||||
|
model_env.rows_counter_column_name = rows_counter_name;
|
||||||
|
|
||||||
model.model_env = &model_env;
|
model.model_env = &model_env;
|
||||||
model.table();
|
model.table();
|
||||||
model.model_env->add_table_name_to_finder_helper();
|
model.model_env->add_table_name_to_finder_helper();
|
||||||
|
@ -1340,7 +1360,7 @@ private:
|
||||||
FinderHelper finder_helper;
|
FinderHelper finder_helper;
|
||||||
ModelData * model_data;
|
ModelData * model_data;
|
||||||
bool use_table_prefix_for_fetching;
|
bool use_table_prefix_for_fetching;
|
||||||
|
const wchar_t * rows_counter_name;
|
||||||
|
|
||||||
|
|
||||||
void set_db_expression()
|
void set_db_expression()
|
||||||
|
|
Loading…
Reference in New Issue