add possibility of calculating how many rows there were before LIMIT was applied
The Finder has get_rows_counter() method which returns how many rows there were before LIMIT clause was applied. The select(...) method should be called with Select::with_rows_counter flag in such a case. while here: - change the semantic of Finder, now the select(...) method takes a morm::Select flags, and we have such flags: - Select::no_auto_generated_columns - do not generate columns from models - with_rows_counter - add an additional column for the rows counter - remove Finder::prepare_to_select() - now use select(...) with no_auto_generated_columns flag
This commit is contained in:
@@ -934,6 +934,7 @@ void Model::map_values_from_query()
|
||||
model_env->was_primary_key_read = false; // whether or not there was at least one column with primary_key flag
|
||||
model_env->has_primary_key_set = true; // whether all primary_columns were different than null
|
||||
fields();
|
||||
map_additional_columns_from_query();
|
||||
model_env->model_work_mode = MORM_MODEL_WORK_MODE_NONE;
|
||||
|
||||
if( model_env->was_primary_key_read && model_env->has_primary_key_set )
|
||||
@@ -950,6 +951,40 @@ void Model::map_values_from_query()
|
||||
}
|
||||
|
||||
|
||||
void Model::map_additional_columns_from_query()
|
||||
{
|
||||
if( model_env )
|
||||
{
|
||||
if( model_env->select_flags.is_with_rows_counter() )
|
||||
{
|
||||
map_rows_counter_from_query();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Model::map_rows_counter_from_query()
|
||||
{
|
||||
if( model_env && model_env->cursor_helper )
|
||||
{
|
||||
/*
|
||||
* take the value only from the first row, the value should be the same on every row
|
||||
*/
|
||||
if( model_env->cursor_helper->current_row == 0 )
|
||||
{
|
||||
field(model_env->rows_counter_column_name.c_str(), L"", model_env->rows_counter);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( model_env->cursor_helper && model_env->cursor_helper->has_autogenerated_select )
|
||||
{
|
||||
model_env->cursor_helper->current_column += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Model::clear()
|
||||
{
|
||||
|
Reference in New Issue
Block a user