/* * This file is a part of morm * and is distributed under the 2-Clause BSD licence. * Author: Tomasz Sowa */ /* * Copyright (c) 2018-2021, 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_postgresqlconnector #define headerfile_morm_postgresqlconnector #include #include #include "dbconnector.h" #include "postgresqlqueryresult.h" namespace morm { class PostgreSQLConnector : public DbConnector { public: PostgreSQLConnector(); PostgreSQLConnector(const PostgreSQLConnector &) = delete; virtual ~PostgreSQLConnector(); bool query(const pt::TextStream & stream, QueryResult & query_result); bool query(const char * query_str, QueryResult & query_result); bool query(const std::string & query_str, QueryResult & query_result); bool query_select(const char * query_str, QueryResult & query_result); bool query_update(const char * query_str, QueryResult & query_result); bool query_insert(const char * query_str, QueryResult & query_result); bool query_remove(const char * query_str, QueryResult & query_result); bool query_select(const pt::TextStream & stream, QueryResult & query_result); bool query_update(const pt::TextStream & stream, QueryResult & query_result); bool query_insert(const pt::TextStream & stream, QueryResult & query_result); bool query_remove(const pt::TextStream & stream, QueryResult & query_result); virtual void set_conn_param(const std::wstring & database, const std::wstring & user, const std::wstring & pass); virtual void connect(); virtual void wait_for_connection(); virtual void close(); //virtual bool assert_connection(bool put_log = true, bool throw_if_no_connection = true); virtual bool assert_connection(bool put_log = true); virtual void set_db_parameters(); virtual void log_connection_socket(); protected: PGconn * pg_conn; pt::TextStream stream; std::string query_str; std::wstring db_database; std::wstring db_user; std::wstring db_pass; virtual bool do_query(const char * query_str, PostgreSQLQueryResult * psql_result); virtual void allocate_default_expression(); virtual void overwrite(pt::TextStream & stream); virtual const char * query_last_sequence(const wchar_t * sequence_table_name); virtual QueryResult * create_query_result(); void log_unsupported_bin_format(); size_t unescape_bin_char(const char * str, wchar_t & field_value, const FT & field_type); void unescape_bin_string(const char * str, std::string & out); void unescape_bin_string(const char * str, std::wstring & out, const FT & field_type); }; } #endif