added: to Model::to_text() methods added dump_mode (bool) parameter

an additional field (model_save_mode) is printed
changed: if there is no an object the Cursor returns a Model with DO_NOTHING_ON_SAVE flag now
         (DO_INSERT_ON_SAVE was beforehand)
fixed:   when reading a result from db: for auto generated select there should be used
         get_value_by_field_index() method instead of get_value_by_field_name() 
changed: flat string (json) is generated only if a model has DO_INSERT_ON_SAVE
         or DO_UPDATE_ON_SAVE or is dump_mode turn on
         




git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1208 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2019-09-13 18:17:02 +00:00
parent c133e949ce
commit 057d879b4c
9 changed files with 81 additions and 31 deletions

View File

@@ -58,7 +58,7 @@ public:
enum SaveMode
{
DO_INSERT_ON_SAVE,
DO_INSERT_ON_SAVE = 0,
DO_UPDATE_ON_SAVE,
DO_DELETE_ON_SAVE,
DO_NOTHING_ON_SAVE,
@@ -99,13 +99,13 @@ public:
*/
virtual void table_name(PT::TextStream & stream);
virtual void to_text(PT::TextStream & stream, ModelData * model_data, bool clear_stream = true);
virtual void to_text(PT::TextStream & stream, ModelData & model_data, bool clear_stream = true);
virtual void to_text(PT::TextStream & stream, bool clear_stream = true);
virtual void to_text(PT::TextStream & stream, ModelData * model_data, bool clear_stream = true, bool dump_mode = false);
virtual void to_text(PT::TextStream & stream, ModelData & model_data, bool clear_stream = true, bool dump_mode = false);
virtual void to_text(PT::TextStream & stream, bool clear_stream = true, bool dump_mode = false);
virtual void to_text(std::string & str, ModelData * model_data, bool clear_string = true);
virtual void to_text(std::string & str, ModelData & model_data, bool clear_string = true);
virtual void to_text(std::string & str, bool clear_string = true);
virtual void to_text(std::string & str, ModelData * model_data, bool clear_string = true, bool dump_mode = false);
virtual void to_text(std::string & str, ModelData & model_data, bool clear_string = true, bool dump_mode = false);
virtual void to_text(std::string & str, bool clear_string = true, bool dump_mode = false);
virtual std::string to_text();
virtual std::string to_string();
@@ -775,7 +775,7 @@ protected:
{
if( !is_empty_field(db_field_name) )
{
if( model_env->model_data && model_env->cursor_helper && model_env->cursor_helper->has_autogenerated_select )
if( model_env->cursor_helper && model_env->cursor_helper->has_autogenerated_select )
{
get_value_by_field_index(model_env->cursor_helper->current_column, field_value);
model_env->cursor_helper->current_column += 1;
@@ -853,7 +853,9 @@ protected:
}
else
{
map_fields();
ModelEnv * old_model_env = field_model.model_env;
map_fields(); // map_fields() will set field_model.model_env to null
field_model.model_env = old_model_env;
model_env->finder_helper->join_tables_str << " ON " << model_env->table_name_short << '.';
@@ -885,8 +887,11 @@ protected:
if( flat_expression && !is_empty_field(flat_field_name) )
{
field_model.model_env->model_connector_mode = MORM_MODEL_CONNECTOR_MODE_GENERATING_FLAT_STRING;
flat_expression->field_model(flat_field_name, field_model, insertable, updatable, false, model_env);
if( model_env->dump_mode || field_model.save_mode == DO_INSERT_ON_SAVE || field_model.save_mode == DO_UPDATE_ON_SAVE )
{
field_model.model_env->model_connector_mode = MORM_MODEL_CONNECTOR_MODE_GENERATING_FLAT_STRING;
flat_expression->field_model(flat_field_name, field_model, insertable, updatable, false, model_env);
}
}
}
}
@@ -1268,6 +1273,21 @@ protected:
{
if( model_env->cursor_helper && model_env->cursor_helper->query_result )
{
// std::wstring table_field_name;
// CHECK what about escaping field names here?
/*
* FIX ME
* we need the table name with correct prefix (index)
*
*/
// model_env->table_name.to_string(table_field_name);
//
//
// table_field_name += '.';
// table_field_name += field_name;
const char * val_str = model_env->cursor_helper->query_result->get_field_string_value(field_name);
if( val_str )