added get_vector() methods to Finder and Cursor
bool get_vector(std::vector<ModelClass> & result, bool clear_list = true); std::vector<ModelClass> get_vector();
This commit is contained in:
parent
c18bb48cc8
commit
b672b67e5c
78
src/cursor.h
78
src/cursor.h
|
@ -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
|
||||
|
@ -246,7 +246,57 @@ public:
|
|||
}
|
||||
|
||||
|
||||
|
||||
virtual bool get_list(std::list<ModelClass> & result, bool clear_list = true)
|
||||
{
|
||||
return get_list_generic(result, clear_list);
|
||||
}
|
||||
|
||||
|
||||
virtual std::list<ModelClass> get_list()
|
||||
{
|
||||
std::list<ModelClass> result;
|
||||
|
||||
get_list(result, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
virtual bool get_vector(std::vector<ModelClass> & result, bool clear_list = true)
|
||||
{
|
||||
if( query_result && query_result->has_db_result() && result.capacity() < query_result->result_rows )
|
||||
{
|
||||
result.reserve(query_result->result_rows);
|
||||
}
|
||||
|
||||
return get_list_generic(result, clear_list);
|
||||
}
|
||||
|
||||
virtual std::vector<ModelClass> get_vector()
|
||||
{
|
||||
std::vector<ModelClass> result;
|
||||
|
||||
get_vector(result, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
ModelConnector * model_connector;
|
||||
ModelData * model_data;
|
||||
bool has_autogenerated_select;
|
||||
bool use_table_prefix_for_fetching;
|
||||
CursorHelper cursor_helper;
|
||||
FinderHelper finder_helper; // may CursorHelper and FinderHelper should be one class?
|
||||
QueryResult * query_result;
|
||||
bool select_status;
|
||||
|
||||
|
||||
|
||||
template<typename ContainerType>
|
||||
bool get_list_generic(ContainerType & result, bool clear_list = true)
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
|
@ -289,32 +339,6 @@ public:
|
|||
}
|
||||
|
||||
|
||||
virtual std::list<ModelClass> get_list()
|
||||
{
|
||||
std::list<ModelClass> result;
|
||||
|
||||
get_list(result, false);
|
||||
return std::move(result);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
ModelConnector * model_connector;
|
||||
ModelData * model_data;
|
||||
bool has_autogenerated_select;
|
||||
bool use_table_prefix_for_fetching;
|
||||
CursorHelper cursor_helper;
|
||||
FinderHelper finder_helper; // may CursorHelper and FinderHelper should be one class?
|
||||
QueryResult * query_result;
|
||||
bool select_status;
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename ContainerType>
|
||||
bool add_models_to_list(ContainerType & result)
|
||||
{
|
||||
|
|
17
src/finder.h
17
src/finder.h
|
@ -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
|
||||
|
@ -562,6 +562,21 @@ public:
|
|||
}
|
||||
|
||||
|
||||
bool get_vector(std::vector<ModelClass> & result, bool clear_vector = true)
|
||||
{
|
||||
Cursor<ModelClass> cursor = get_cursor();
|
||||
return cursor.get_vector(result, clear_vector);
|
||||
}
|
||||
|
||||
|
||||
std::vector<ModelClass> get_vector()
|
||||
{
|
||||
std::vector<ModelClass> result;
|
||||
|
||||
get_vector(result, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
|
Loading…
Reference in New Issue