add Finder::is_null() and is_not_null() methods

This commit is contained in:
Tomasz Sowa 2023-07-08 23:26:54 +02:00
parent 25a91168ac
commit e7c62e35dc
Signed by: tomasz.sowa
GPG Key ID: 662CC1438638588B
4 changed files with 102 additions and 4 deletions

View File

@ -787,13 +787,17 @@ protected:
template<typename FieldValue>
void put_field_name_and_value(const wchar_t * field_name, const FieldValue & field_value, void (Model::*getter_method)(pt::Stream &), const FT & field_type, ModelEnv * model_env)
{
bool allow_to_put_value = (get_output_type() != MORM_OUTPUT_TYPE_WHERE_IS_NULL && get_output_type() != MORM_OUTPUT_TYPE_WHERE_IS_NOT_NULL);
if( model_env && model_env->set_field_name_helper )
{
if( (size_t)model_env->field_index < model_env->set_field_name_helper->size() )
{
put_field_name_and_table_if_needed((*model_env->set_field_name_helper)[model_env->field_index], field_type, model_env);
put_name_value_separator();
put_field_value_or_null(field_value, getter_method, field_type, model_env);
if( allow_to_put_value )
put_field_value_or_null(field_value, getter_method, field_type, model_env);
}
model_env->field_index += 1;
@ -802,7 +806,9 @@ protected:
{
put_field_name_and_table_if_needed(field_name, field_type, model_env);
put_name_value_separator();
put_field_value_or_null(field_value, getter_method, field_type, model_env);
if( allow_to_put_value )
put_field_value_or_null(field_value, getter_method, field_type, model_env);
}
}

View File

@ -109,7 +109,9 @@ void DbExpression::field_before()
output_type == MORM_OUTPUT_TYPE_WHERE_NOT_EQ ||
output_type == MORM_OUTPUT_TYPE_WHERE_IN ||
output_type == MORM_OUTPUT_TYPE_WHERE_LIKE ||
output_type == MORM_OUTPUT_TYPE_WHERE_ILIKE )
output_type == MORM_OUTPUT_TYPE_WHERE_ILIKE ||
output_type == MORM_OUTPUT_TYPE_WHERE_IS_NULL ||
output_type == MORM_OUTPUT_TYPE_WHERE_IS_NOT_NULL )
{
int conjunction = MORM_CONJUNCTION_AND;
@ -181,6 +183,16 @@ void DbExpression::put_name_value_separator()
{
(*out_stream) << " ILIKE ";
}
else
if( output_type == MORM_OUTPUT_TYPE_WHERE_IS_NULL )
{
(*out_stream) << " IS NULL ";
}
else
if( output_type == MORM_OUTPUT_TYPE_WHERE_IS_NOT_NULL )
{
(*out_stream) << " IS NOT NULL ";
}
}

View File

@ -605,6 +605,84 @@ public:
}
Finder<ModelClass> & is_null(const wchar_t * field_name)
{
if( db_expression )
{
int ignored_value = 0;
db_expression->set_output_type(MORM_OUTPUT_TYPE_WHERE_IS_NULL);
db_expression->field_to_stream(*out_stream, field_name, ignored_value, FT::default_type, &model_env);
}
return *this;
}
Finder<ModelClass> & is_null(const wchar_t * table_name, const wchar_t * field_name)
{
if( db_expression )
{
int ignored_value = 0;
db_expression->set_output_type(MORM_OUTPUT_TYPE_WHERE_IS_NULL);
field_to_stream(table_name, 1, field_name, ignored_value);
}
return *this;
}
Finder<ModelClass> & is_null(const wchar_t * table_name, int table_index, const wchar_t * field_name)
{
if( db_expression )
{
int ignored_value = 0;
db_expression->set_output_type(MORM_OUTPUT_TYPE_WHERE_IS_NULL);
field_to_stream(table_name, table_index, field_name, ignored_value);
}
return *this;
}
Finder<ModelClass> & is_not_null(const wchar_t * field_name)
{
if( db_expression )
{
int ignored_value = 0;
db_expression->set_output_type(MORM_OUTPUT_TYPE_WHERE_IS_NOT_NULL);
db_expression->field_to_stream(*out_stream, field_name, ignored_value, FT::default_type, &model_env);
}
return *this;
}
Finder<ModelClass> & is_not_null(const wchar_t * table_name, const wchar_t * field_name)
{
if( db_expression )
{
int ignored_value = 0;
db_expression->set_output_type(MORM_OUTPUT_TYPE_WHERE_IS_NOT_NULL);
field_to_stream(table_name, 1, field_name, ignored_value);
}
return *this;
}
Finder<ModelClass> & is_not_null(const wchar_t * table_name, int table_index, const wchar_t * field_name)
{
if( db_expression )
{
int ignored_value = 0;
db_expression->set_output_type(MORM_OUTPUT_TYPE_WHERE_IS_NOT_NULL);
field_to_stream(table_name, table_index, field_name, ignored_value);
}
return *this;
}
/*
* page_number start from zero (it's a number of a page, not an offset)

View File

@ -101,8 +101,10 @@
#define MORM_OUTPUT_TYPE_WHERE_NOT_EQ 26
#define MORM_OUTPUT_TYPE_WHERE_LIKE 27
#define MORM_OUTPUT_TYPE_WHERE_ILIKE 28
#define MORM_OUTPUT_TYPE_WHERE_IS_NULL 29
#define MORM_OUTPUT_TYPE_WHERE_IS_NOT_NULL 30
#define MORM_OUTPUT_TYPE_FIELDS_RECURSIVE 29
#define MORM_OUTPUT_TYPE_FIELDS_RECURSIVE 31
#define MORM_CONJUNCTION_AND 1
#define MORM_CONJUNCTION_OR 2