added support for 'in()' statement in 'select'
git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1086 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -36,6 +36,7 @@
|
||||
#define headerfile_morm_baseexpression
|
||||
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include "textstream/textstream.h"
|
||||
#include "morm_types.h"
|
||||
#include "date/date.h"
|
||||
@@ -86,6 +87,24 @@ public:
|
||||
}
|
||||
|
||||
|
||||
template<typename FieldValue>
|
||||
void field_in(PT::TextStream & stream, const wchar_t * field_name, const std::set<FieldValue> & container)
|
||||
{
|
||||
field_in_generic<FieldValue, std::set<FieldValue>>(stream, field_name, container);
|
||||
}
|
||||
|
||||
template<typename FieldValue>
|
||||
void field_in(PT::TextStream & stream, const wchar_t * field_name, const std::list<FieldValue> & container)
|
||||
{
|
||||
field_in_generic<FieldValue, std::list<FieldValue>>(stream, field_name, container);
|
||||
}
|
||||
|
||||
template<typename FieldValue>
|
||||
void field_in(PT::TextStream & stream, const wchar_t * field_name, const std::vector<FieldValue> & container)
|
||||
{
|
||||
field_in_generic<FieldValue, std::vector<FieldValue>>(stream, field_name, container);
|
||||
}
|
||||
|
||||
template<typename ModelClass>
|
||||
void field_list(const wchar_t * field_name, const std::list<ModelClass> & field_value, bool insertable = true, bool updatable = true, bool is_primary_key = false)
|
||||
{
|
||||
@@ -114,6 +133,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename FieldValue>
|
||||
void field(PT::TextStream & stream, const wchar_t * field_name, const FieldValue & field_value, bool insertable = true, bool updatable = true, bool is_primary_key = false)
|
||||
{
|
||||
@@ -187,11 +207,15 @@ protected:
|
||||
template<typename FieldValue>
|
||||
void put_field_value(const FieldValue & field_value)
|
||||
{
|
||||
before_field_value(field_value);
|
||||
esc(field_value, *out_stream);
|
||||
after_field_value(field_value);
|
||||
if( out_stream )
|
||||
{
|
||||
before_field_value(field_value);
|
||||
esc(field_value, *out_stream);
|
||||
after_field_value(field_value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename ModelClass>
|
||||
void put_field_value_list(const std::list<ModelClass> & field_value)
|
||||
{
|
||||
@@ -225,6 +249,40 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// used in 'in()' statements, may should be renamed?
|
||||
template<typename FieldValue, typename Container>
|
||||
void field_in_generic(PT::TextStream & stream, const wchar_t * field_name, const Container & container)
|
||||
{
|
||||
// IMPROVE ME
|
||||
// what about if container is empty?
|
||||
// only 'in()' statement would be generated
|
||||
this->out_stream = &stream;
|
||||
|
||||
field_before();
|
||||
put_field_name(field_name);
|
||||
put_name_value_separator();
|
||||
|
||||
bool is_first = true;
|
||||
(*out_stream) << "(";
|
||||
|
||||
for(const FieldValue & v : container)
|
||||
{
|
||||
if( !is_first )
|
||||
{
|
||||
(*out_stream) << ",";
|
||||
}
|
||||
|
||||
put_field_value(v);
|
||||
is_first = false;
|
||||
}
|
||||
|
||||
(*out_stream) << ") ";
|
||||
field_after();
|
||||
this->out_stream = nullptr;
|
||||
}
|
||||
|
||||
|
||||
virtual void before_field_name();
|
||||
virtual void after_field_name();
|
||||
|
||||
|
Reference in New Issue
Block a user