morm/src/modelenv.h

247 lines
6.0 KiB
C++

/*
* This file is a part of morm
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2019-2022, Tomasz Sowa
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef headerfile_morm_src_modelenv
#define headerfile_morm_src_modelenv
#include "modeldata.h"
#include "cursorhelper.h"
#include "finderhelper.h"
#include "fieldvaluehelper.h"
#include "morm_types.h"
#include "wrapper.h"
#include "select.h"
#ifdef MORM_HAS_EZC_LIBRARY
#include "funinfo.h"
#endif
namespace morm
{
class Model;
class ModelContainerWrapper;
class ModelEnv
{
public:
// global objects to the whole models tree
// (values are copied to child models)
ModelData * model_data;
FinderHelper * finder_helper;
CursorHelper * cursor_helper;
int model_work_mode;
int model_work_submode;
bool dump_mode;
pt::WTextStream schema_name;
pt::WTextStream table_name;
int table_index;
/*
* optional additional table name
* used in eq(), neq(), ... methods in Finder
*/
const wchar_t * table2_name;
int table2_index;
int field_index;
bool was_primary_key_read;
bool has_primary_key_set;
std::vector<const wchar_t *> * set_field_name_helper;
std::vector<FieldValueHelper> * field_value_helper_tab;
/*
* used when putting a specific field's value to a stream
*/
const wchar_t * db_field_name;
const wchar_t * flat_field_name;
Model * model;
Model * child_model;
pt::Stream * stream;
bool was_field_found; // used only in MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM
Wrapper wrapper;
#ifdef MORM_HAS_EZC_LIBRARY
void * ezc_fun_info;
bool ezc_fun_result;
const std::type_info * ezc_fun_info_typeinfo;
#endif
bool status;
bool has_autogenerated_select;
Select select_flags;
size_t rows_counter;
std::wstring rows_counter_column_name;
bool use_escaping_for_like; // escaping % and _ characters for LIKE or ILIKE statements
bool add_prefix_percent; // add a percent sign before a string value (used mainly in LIKE or ILIKE)
bool add_postfix_percent; // add a percent sign after a string value (used mainly in LIKE or ILIKE)
ModelEnv()
{
clear();
}
~ModelEnv()
{
}
ModelEnv(const ModelEnv & e)
{
operator=(e);
}
ModelEnv & operator=(const ModelEnv & e)
{
copy_global_objects(e);
table_index = e.table_index;
table2_index = e.table2_index;
set_field_name_helper = e.set_field_name_helper;
field_value_helper_tab = e.field_value_helper_tab;
field_index = e.field_index;
was_primary_key_read = e.was_primary_key_read;
has_primary_key_set = e.has_primary_key_set;
db_field_name = e.db_field_name;
flat_field_name = e.flat_field_name;
model = e.model;
child_model = e.child_model;
stream = e.stream;
was_field_found = e.was_field_found;
wrapper = e.wrapper;
status = e.status;
has_autogenerated_select = e.has_autogenerated_select;
select_flags = e.select_flags;
rows_counter = e.rows_counter;
rows_counter_column_name = e.rows_counter_column_name;
use_escaping_for_like = e.use_escaping_for_like;
add_prefix_percent = e.add_prefix_percent;
add_postfix_percent = e.add_postfix_percent;
#ifdef MORM_HAS_EZC_LIBRARY
ezc_fun_info = e.ezc_fun_info;
ezc_fun_result = e.ezc_fun_result;
ezc_fun_info_typeinfo = e.ezc_fun_info_typeinfo;
#endif
// schema_name and table_name don't have to be copied
table2_name = nullptr;
return *this;
}
void copy_global_objects(const ModelEnv & e)
{
model_data = e.model_data;
finder_helper = e.finder_helper;
cursor_helper = e.cursor_helper;
model_work_mode = e.model_work_mode;
model_work_submode = e.model_work_submode;
dump_mode = e.dump_mode;
}
void clear()
{
model_data = nullptr;
finder_helper = nullptr;
cursor_helper = nullptr;
model_work_mode = MORM_MODEL_WORK_MODE_NONE;
model_work_submode = MORM_MODEL_WORK_SUBMODE_NONE;
dump_mode = false;
schema_name.clear();
table_name.clear();
table2_name = nullptr;
table_index = 0;
table2_index = 0;
set_field_name_helper = nullptr;
field_value_helper_tab = nullptr;
field_index = 0;
was_primary_key_read = false;
has_primary_key_set = false;
db_field_name = nullptr;
flat_field_name = nullptr;
model = nullptr;
child_model = nullptr;
stream = nullptr;
was_field_found = false;
wrapper.clear();
status = true;
has_autogenerated_select = false;
select_flags = Select::default_type;
rows_counter = 0;
rows_counter_column_name.clear();
use_escaping_for_like = false;
add_prefix_percent = false;
add_postfix_percent = false;
#ifdef MORM_HAS_EZC_LIBRARY
ezc_fun_info = nullptr;
ezc_fun_result = false;
ezc_fun_info_typeinfo = nullptr;
#endif
}
void add_table_name_to_finder_helper()
{
if( finder_helper )
{
table_index = finder_helper->add_join_table(table_name);
}
else
{
table_index = 0;
}
}
};
}
#endif