some work in branches/join_models
git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1190 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
6d9b9045fe
commit
34ddf11351
|
@ -152,6 +152,9 @@ public:
|
|||
{
|
||||
try
|
||||
{
|
||||
if( model_data )
|
||||
model_data->current_column = 0;
|
||||
|
||||
result.model_data = model_data;
|
||||
result.before_select();
|
||||
res = select_status;
|
||||
|
@ -283,6 +286,9 @@ protected:
|
|||
|
||||
try
|
||||
{
|
||||
if( model_data )
|
||||
model_data->current_column = 0;
|
||||
|
||||
added_model.set_connector(model_connector);
|
||||
added_model.clear();
|
||||
added_model.set_save_mode(Model::DO_UPDATE_ON_SAVE); // IMPROVE ME check if there is a primary key
|
||||
|
|
|
@ -250,6 +250,7 @@ public:
|
|||
}
|
||||
|
||||
model_data->prepare_to_new_select();
|
||||
model_data->has_autogenerated_select = true;
|
||||
|
||||
if( model_connector && out_stream )
|
||||
{
|
||||
|
|
29
src/model.h
29
src/model.h
|
@ -683,12 +683,15 @@ protected:
|
|||
{
|
||||
if( !is_empty_field(db_field_name) )
|
||||
{
|
||||
get_value_by_field_name(db_field_name, field_value);
|
||||
|
||||
if( model_data )
|
||||
if( model_data && model_data->has_autogenerated_select )
|
||||
{
|
||||
get_value_by_field_index(model_data->current_column, field_value);
|
||||
model_data->current_column += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
get_value_by_field_name(db_field_name, field_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -978,6 +981,26 @@ protected:
|
|||
}
|
||||
|
||||
|
||||
template<typename FieldValue>
|
||||
void get_value_by_field_index(int field_index, FieldValue & field_value)
|
||||
{
|
||||
if( query_result )
|
||||
{
|
||||
const char * val_str = query_result->get_field_string_value(field_index);
|
||||
|
||||
if( val_str )
|
||||
{
|
||||
DbConnector * db_connector = model_connector->get_db_connector();
|
||||
|
||||
if( db_connector )
|
||||
{
|
||||
db_connector->get_value(val_str, field_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename FieldValue>
|
||||
void get_value_by_field_name(const wchar_t * field_name, FieldValue & field_value)
|
||||
{
|
||||
|
|
|
@ -53,6 +53,9 @@ public:
|
|||
{
|
||||
}
|
||||
|
||||
bool has_autogenerated_select;
|
||||
|
||||
|
||||
PT::TextStream morm_finder_join_tables;
|
||||
std::list<std::string> morm_foreign_keys;
|
||||
int morm_current_max_column;
|
||||
|
@ -65,6 +68,8 @@ public:
|
|||
|
||||
virtual void prepare_to_new_select()
|
||||
{
|
||||
has_autogenerated_select = false;
|
||||
|
||||
morm_current_max_column = 1;
|
||||
morm_finder_join_tables.clear();
|
||||
morm_table_join_map.clear();
|
||||
|
|
|
@ -115,6 +115,7 @@ bool PostgreSQLConnector::do_query(const char * query_str, PostgreSQLQueryResult
|
|||
{
|
||||
psql_result->psql_status = PQresultStatus(psql_result->psql_result);
|
||||
psql_result->result_rows = static_cast<size_t>(PQntuples(psql_result->psql_result));
|
||||
psql_result->result_cols = static_cast<size_t>(PQnfields(psql_result->psql_result));
|
||||
}
|
||||
|
||||
if( !psql_result->psql_result || psql_result->psql_status == PGRES_FATAL_ERROR )
|
||||
|
|
|
@ -67,6 +67,23 @@ bool PostgreSQLQueryResult::has_db_result()
|
|||
}
|
||||
|
||||
|
||||
const char * PostgreSQLQueryResult::get_field_string_value(int column_index)
|
||||
{
|
||||
const char * value_str = nullptr;
|
||||
|
||||
if( column_index >= 0 && (size_t)column_index < result_cols )
|
||||
{
|
||||
if( cur_row < result_rows )
|
||||
{
|
||||
value_str = PQgetvalue(psql_result, cur_row, column_index);
|
||||
}
|
||||
}
|
||||
|
||||
return value_str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char * PostgreSQLQueryResult::get_field_string_value(const char * column_name)
|
||||
{
|
||||
const char * value_str = nullptr;
|
||||
|
|
|
@ -57,6 +57,7 @@ struct PostgreSQLQueryResult : public QueryResult
|
|||
|
||||
virtual bool has_db_result();
|
||||
|
||||
const char * get_field_string_value(int column_index);
|
||||
const char * get_field_string_value(const char * column_name);
|
||||
int get_column_index(const char * column_name);
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ QueryResult::~QueryResult()
|
|||
void QueryResult::clear()
|
||||
{
|
||||
result_rows = 0;
|
||||
result_cols = 0;
|
||||
cur_row = 0;
|
||||
status = false;
|
||||
error_msg.clear();
|
||||
|
@ -70,6 +71,12 @@ bool QueryResult::has_db_result()
|
|||
}
|
||||
|
||||
|
||||
const char * QueryResult::get_field_string_value(int column_index)
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
const char * QueryResult::get_field_string_value(const char * column_name)
|
||||
{
|
||||
return nullptr;
|
||||
|
|
|
@ -45,6 +45,7 @@ struct QueryResult
|
|||
{
|
||||
bool status;
|
||||
size_t result_rows; // how many rows in the result query
|
||||
size_t result_cols; // how many columns in the result query
|
||||
size_t cur_row; // used for reading
|
||||
std::wstring error_msg;
|
||||
|
||||
|
@ -57,6 +58,7 @@ struct QueryResult
|
|||
virtual void clear();
|
||||
virtual bool has_db_result();
|
||||
|
||||
virtual const char * get_field_string_value(int column_index);
|
||||
virtual const char * get_field_string_value(const char * column_name);
|
||||
virtual const char * get_field_string_value(const wchar_t * field_name);
|
||||
|
||||
|
|
Loading…
Reference in New Issue