From 2533b18cfdf37dc134863ef6b962b16411876cc7 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Mon, 17 Jun 2019 10:59:39 +0000 Subject: [PATCH] fixed: in cursor in add_models_to_list(): added_model.model_env should be set after added_model.clear() fixed: when generating: insert, update or remove statements we have used prefixes for columns but the table name was not set in ModelEnv (now we do not use prefixes in such statements) changed: log_queries field moved from PostgreSQLConnector to DbConnector git-svn-id: svn://ttmath.org/publicrep/morm/branches/join_models@1195 e52654a7-88a9-db11-a3e9-0013d4bc506e --- src/cursor.h | 5 +++-- src/dbconnector.cpp | 15 +++++++++++---- src/dbconnector.h | 10 +++++++++- src/dbexpression.cpp | 14 +++++++------- src/postgresqlconnector.cpp | 7 +------ src/postgresqlconnector.h | 5 +---- 6 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/cursor.h b/src/cursor.h index 17c1052..e167330 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -302,8 +302,6 @@ protected: ModelClass & added_model = result.back(); ModelEnv model_env_local; - added_model.model_env = &model_env_local; - added_model.model_env->cursor_helper = &cursor_helper; try { @@ -313,6 +311,9 @@ protected: added_model.set_connector(model_connector); added_model.clear(); + + added_model.model_env = &model_env_local; + added_model.model_env->cursor_helper = &cursor_helper; added_model.set_save_mode(Model::DO_UPDATE_ON_SAVE); // IMPROVE ME check if there is a primary key added_model.model_env->model_data = model_data; added_model.before_select(); diff --git a/src/dbconnector.cpp b/src/dbconnector.cpp index 9654b8a..5ec5569 100644 --- a/src/dbconnector.cpp +++ b/src/dbconnector.cpp @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018, Tomasz Sowa + * Copyright (c) 2018-2019, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ DbConnector::DbConnector() db_expression = nullptr; expression_allocated = false; log = nullptr; + log_queries = false; } DbConnector::DbConnector(const DbConnector &) @@ -70,12 +71,18 @@ void DbConnector::set_logger(PT::Log * log) this->log = log; } + void DbConnector::set_logger(PT::Log & log) { this->log = &log; } +void DbConnector::set_log_queries(bool log_queries) +{ + this->log_queries = log_queries; +} + bool DbConnector::query(const PT::TextStream & stream, QueryResult & query_result) { @@ -173,7 +180,7 @@ void DbConnector::generate_insert_query(PT::TextStream & stream, Model & model) if( db_expression ) { db_expression->clear(); - db_expression->allow_to_use_prefix(true); + db_expression->allow_to_use_prefix(false); stream << "insert into "; model.table_name(stream); @@ -198,7 +205,7 @@ void DbConnector::generate_update_query(PT::TextStream & stream, Model & model) if( db_expression ) { db_expression->clear(); - db_expression->allow_to_use_prefix(true); + db_expression->allow_to_use_prefix(false); stream << "update "; model.table_name(stream); @@ -223,7 +230,7 @@ void DbConnector::generate_remove_query(PT::TextStream & stream, Model & model) if( db_expression ) { db_expression->clear(); - db_expression->allow_to_use_prefix(true); + db_expression->allow_to_use_prefix(false); stream << "delete from "; model.table_name(stream); diff --git a/src/dbconnector.h b/src/dbconnector.h index e2f58e1..7e2753d 100644 --- a/src/dbconnector.h +++ b/src/dbconnector.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018, Tomasz Sowa + * Copyright (c) 2018-2019, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -57,6 +57,8 @@ public: virtual void set_logger(PT::Log * log); virtual void set_logger(PT::Log & log); + virtual void set_log_queries(bool log_queries); + DbExpression * get_expression(); //virtual void clear_last_query_result(); @@ -115,6 +117,11 @@ public: if( val_str ) { get_value(val_str, field_value); + + if( log && log_queries ) + { + (*log) << PT::Log::log3 << "Morm: sequence value: " << field_value << PT::Log::logend; + } } } @@ -124,6 +131,7 @@ protected: DbExpression * db_expression; bool expression_allocated; PT::Log * log; + bool log_queries; virtual void allocate_default_expression() = 0; diff --git a/src/dbexpression.cpp b/src/dbexpression.cpp index f65e48e..c489b7f 100644 --- a/src/dbexpression.cpp +++ b/src/dbexpression.cpp @@ -96,7 +96,7 @@ void DbExpression::field_before() output_type == MORM_OUTPUT_TYPE_DB_UPDATE || output_type == MORM_OUTPUT_TYPE_SELECT_COLUMNS ) { - (*out_stream) << ","; + (*out_stream) << ", "; } else if( output_type == MORM_OUTPUT_TYPE_DB_PRIMARY_KEY ) @@ -137,32 +137,32 @@ void DbExpression::put_name_value_separator() output_type == MORM_OUTPUT_TYPE_WHERE_EQ || output_type == MORM_OUTPUT_TYPE_DB_UPDATE) { - (*out_stream) << " = "; + (*out_stream) << "="; } else if( output_type == MORM_OUTPUT_TYPE_WHERE_NOT_EQ ) { - (*out_stream) << " <> "; + (*out_stream) << "<>"; } else if( output_type == MORM_OUTPUT_TYPE_WHERE_LT ) { - (*out_stream) << " < "; + (*out_stream) << "<"; } else if( output_type == MORM_OUTPUT_TYPE_WHERE_GT ) { - (*out_stream) << " > "; + (*out_stream) << ">"; } else if( output_type == MORM_OUTPUT_TYPE_WHERE_LE ) { - (*out_stream) << " <= "; + (*out_stream) << "<="; } else if( output_type == MORM_OUTPUT_TYPE_WHERE_GE ) { - (*out_stream) << " >= "; + (*out_stream) << ">="; } else if( output_type == MORM_OUTPUT_TYPE_WHERE_IN ) diff --git a/src/postgresqlconnector.cpp b/src/postgresqlconnector.cpp index b3fb529..bad375d 100644 --- a/src/postgresqlconnector.cpp +++ b/src/postgresqlconnector.cpp @@ -47,7 +47,6 @@ namespace morm PostgreSQLConnector::PostgreSQLConnector() { pg_conn = nullptr; - log_queries = false; } @@ -77,10 +76,6 @@ void PostgreSQLConnector::allocate_default_expression() -void PostgreSQLConnector::set_log_queries(bool log_queries) -{ - this->log_queries = log_queries; -} QueryResult * PostgreSQLConnector::create_query_result() @@ -97,7 +92,7 @@ bool PostgreSQLConnector::do_query(const char * query_str, PostgreSQLQueryResult if( log_queries && log ) { - (*log) << PT::Log::log1 << "Morm: query: " << query_str << PT::Log::logend; + (*log) << PT::Log::log3 << "Morm: query: " << query_str << PT::Log::logend; } psql_result->psql_result = PQexec(pg_conn, query_str); diff --git a/src/postgresqlconnector.h b/src/postgresqlconnector.h index 86561d3..27e4f1a 100644 --- a/src/postgresqlconnector.h +++ b/src/postgresqlconnector.h @@ -5,7 +5,7 @@ */ /* - * Copyright (c) 2018, Tomasz Sowa + * Copyright (c) 2018-2019, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,7 +54,6 @@ public: virtual ~PostgreSQLConnector(); - virtual void set_log_queries(bool log_queries); bool query(const PT::TextStream & stream, QueryResult & query_result); bool query(const char * query_str, QueryResult & query_result); @@ -86,10 +85,8 @@ public: protected: PGconn * pg_conn; - bool log_queries; PT::TextStream stream; std::string query_str; - std::string temp_column_name; std::wstring db_database; std::wstring db_user;