fixed: get_value_by_field_name() is able to correctly take values when

we do not use auto generated 'select' and when we are using prefixes for columns



git-svn-id: svn://ttmath.org/publicrep/morm/trunk@1209 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2019-09-17 17:55:39 +00:00
parent 057d879b4c
commit afce2234c3
12 changed files with 200 additions and 63 deletions

View File

@@ -47,7 +47,6 @@
#include "modelenv.h"
namespace morm
{
@@ -1002,12 +1001,26 @@ protected:
{
if( !is_empty_field(db_field_name) )
{
// we need to test if the object is actually defined, test nulls on primary key?
DbExpression * db_expression = db_connector->get_expression();
field_model.before_select();
field_model.set_save_mode(Model::DO_UPDATE_ON_SAVE); // IMPROVE ME check if there is a primary key
field_model.map_values_from_query();
field_model.after_select();
if( db_expression )
{
if( model_env->cursor_helper &&
!model_env->cursor_helper->has_autogenerated_select &&
model_env->cursor_helper->use_table_prefix_for_fetching_values )
{
field_model.prepare_table_names();
}
// IMPROVE ME
// we need to test if the object is actually defined, test nulls on primary key?
// or check every field whether is it null?
field_model.before_select();
field_model.set_save_mode(Model::DO_UPDATE_ON_SAVE); // IMPROVE ME check if there is a primary key
field_model.map_values_from_query();
field_model.after_select();
}
}
}
}
@@ -1271,33 +1284,39 @@ protected:
template<typename FieldValue>
void get_value_by_field_name(const wchar_t * field_name, FieldValue & field_value)
{
if( model_env->cursor_helper && model_env->cursor_helper->query_result )
DbConnector * db_connector = model_connector->get_db_connector();
if( db_connector && model_env->cursor_helper && model_env->cursor_helper->query_result )
{
// std::wstring table_field_name;
const char * val_str = nullptr;
// CHECK what about escaping field names here?
if( model_env->cursor_helper->use_table_prefix_for_fetching_values && model_env->finder_helper )
{
// 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;
std::wstring table_field_name;
PT::TextStream table_field_name_str;
const char * val_str = model_env->cursor_helper->query_result->get_field_string_value(field_name);
table_field_name_str = model_env->table_name_short;
if( model_env->table_index > 1 )
{
table_field_name_str << model_env->table_index;
}
table_field_name_str << '.';
table_field_name_str << field_name;
table_field_name_str.to_string(table_field_name);
val_str = model_env->cursor_helper->query_result->get_field_string_value(table_field_name.c_str());
}
else
{
val_str = model_env->cursor_helper->query_result->get_field_string_value(field_name);
}
if( val_str )
{
DbConnector * db_connector = model_connector->get_db_connector();
if( db_connector )
{
db_connector->get_value(val_str, field_value);
}
db_connector->get_value(val_str, field_value);
}
}
}
@@ -1455,6 +1474,7 @@ protected:
virtual bool is_empty_field(const wchar_t * value);
virtual bool is_the_same_field(const wchar_t * field1, const wchar_t * field2);
virtual void prepare_table_names(bool prepare_table_index = true);
template<typename ModelClass> friend class Finder;
template<typename ModelClass> friend class Cursor;