diff --git a/src/baseexpression.h b/src/baseexpression.h index c94cfee..6f8e343 100644 --- a/src/baseexpression.h +++ b/src/baseexpression.h @@ -787,13 +787,17 @@ protected: template 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); } } diff --git a/src/dbexpression.cpp b/src/dbexpression.cpp index d836129..8aa08a7 100644 --- a/src/dbexpression.cpp +++ b/src/dbexpression.cpp @@ -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 "; + } } diff --git a/src/finder.h b/src/finder.h index 45fb539..c7ccad6 100644 --- a/src/finder.h +++ b/src/finder.h @@ -605,6 +605,84 @@ public: } + Finder & 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 & 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 & 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 & 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 & 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 & 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) diff --git a/src/morm_types.h b/src/morm_types.h index bf436a8..5e5482c 100644 --- a/src/morm_types.h +++ b/src/morm_types.h @@ -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