GithubHelp home page GithubHelp logo

tghosgor / postgrespp Goto Github PK

View Code? Open in Web Editor NEW
34.0 34.0 8.0 89 KB

postgres++ async C++ driver is a thin libpq wrapper in C++ for PostgreSQL that aims to make libpq easier to use. It has asynchronous behavior and depends on Boost.ASIO for async operations. It makes use of C++11 variadic templates for parameter-ed functions like PQsendQueryParams.

License: BSD 3-Clause "New" or "Revised" License

C++ 97.94% CMake 2.06%

postgrespp's People

Contributors

tghosgor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

postgrespp's Issues

Read access violation when running with MSVC

I managed to build your project with Visual Studio and include and use it in a new Visual Studio project with the following (trivial) code:

#include <iostream>

#include "boost/asio.hpp"

#include "connection.hpp"
#include "async_exec.hpp"

int main()
{
  boost::asio::io_context ioc;
  postgrespp::connection c{ ioc, "<valid connection info>" };
  postgrespp::async_exec(c, "SELECT 1", [](postgrespp::result res) { std::cout << res.ok();  });
  
  ioc.run();
}

However, when running the program I get an error in postgrespp::basic_connection::underlying_handle() (file include\basic_connection.hpp), even before printing res.ok() in the lambda, saying:

Exception thrown: read access violation.
this was 0xFFFFFFFFFFFFFF67.

This does not happen when I build as Release (i. e. with optimizations enabled). Thus I assume this is caused by mistakenly accessing some de-allocated/released memory (from some move or anything): In Debug build it is explicitly overwritten with some invalid value to make the provoked UB of accessing it noticeable. In Release build that invalid memory is not being overwritten, allowing the program to access it and deceptively complete "successfully".

The problem arises in the current master (a8f82b1) as well as on tag 0.2.2 (d789d70). Let me know if I can help you with any more details.

See the stack trace below (run with files from a8f82b1, postgrespp-testings.exe is the project name).

postgrespp-testings.exe!postgrespp::basic_connection::underlying_handle() Line 119	C++
postgrespp-testings.exe!postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::on_write_ready(const boost::system::error_code & ec) Line 116	C++
[External Code]	
postgrespp-testings.exe!boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::system::error_code>::operator()() Line 66	C++
postgrespp-testings.exe!boost::asio::asio_handler_invoke<boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::system::error_code>>(boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::system::error_code> & function, ...) Line 92	C++
postgrespp-testings.exe!boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::system::error_code>,std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>>(boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::system::error_code> & function, std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &> & context) Line 56	C++
postgrespp-testings.exe!boost::asio::detail::handler_work<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>>,void>::complete<boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::system::error_code>>(boost::asio::detail::binder1<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::system::error_code> & function, std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &> & handler) Line 426	C++
postgrespp-testings.exe!boost::asio::detail::win_iocp_wait_op<std::_Binder<std::_Unforced,void (__cdecl postgrespp::socket_operations<postgrespp::basic_transaction<void,void>>::*)(boost::system::error_code const &),postgrespp::socket_operations<postgrespp::basic_transaction<void,void>> *,std::_Ph<1> const &>,boost::asio::execution::any_executor<boost::asio::execution::context_as_t<boost::asio::execution_context &>,boost::asio::execution::detail::blocking::never_t<0>,boost::asio::execution::prefer_only<boost::asio::execution::detail::blocking::possibly_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::tracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::outstanding_work::untracked_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::fork_t<0>>,boost::asio::execution::prefer_only<boost::asio::execution::detail::relationship::continuation_t<0>>>>::do_complete(void * owner, boost::asio::detail::win_iocp_operation * base, const boost::system::error_code & result_ec, unsigned __int64 __formal) Line 111	C++
postgrespp-testings.exe!boost::asio::detail::win_iocp_operation::complete(void * owner, const boost::system::error_code & ec, unsigned __int64 bytes_transferred) Line 48	C++
postgrespp-testings.exe!boost::asio::detail::win_iocp_io_context::do_one(unsigned long msec, boost::asio::detail::win_iocp_thread_info & this_thread, boost::system::error_code & ec) Line 469	C++
postgrespp-testings.exe!boost::asio::detail::win_iocp_io_context::run(boost::system::error_code & ec) Line 204	C++
postgrespp-testings.exe!boost::asio::io_context::run() Line 63	C++
postgrespp-testings.exe!main() Line 14	C++
[External Code]	

Arrays

Does this library support binding arrays to a query param? This will be the primary reason for me to switch over from Rust which has been hell on productivity

could not deconde numeric return types

I am not able to retrieve numeric return values . here is an example function that returns out4 and out5 as numeric.

CREATE OR REPLACE FUNCTION common.my_function(p1 integer, p2 integer, p3 text, p4 numeric, p5 text)
RETURNS TABLE(out1 text, out2 text, out3 text, out4 numeric, out5 numeric)
LANGUAGE plpgsql
AS $function$
BEGIN
-- Do some processing here
-- ...

-- Return the output values
RETURN QUERY 
    SELECT 
        'output1' AS out1, 
        'output2' AS out2, 
        'output3' AS out3, 
        123.45 AS out4, 
        678.90 AS out5;

END;
$function$
;
in result.hpp I have added
PGresult* underlying_result_handle() { return res_;}

Here is test code cpp code,
std::string query = fmt::format("select out1 "o1", out2 "o2",out3 "o3", out4 "o4" ,out5 "o5" from common.my_function ({}, {}, '{}', {}, '{}')",
fmt::arg("p1", 1),
fmt::arg("p2", 1),
fmt::arg("p3", "Delete"),
fmt::arg("p4", 1),
fmt::arg("p5", "USD"));

                    auto result_future = async_exec(*_dbconn,
                                                    query,
                                                    postgrespp::use_future);


                    postgrespp::result result = result_future.get();
                    if (result.ok()) {

                        auto result_handle = result.underlying_result_handle();
                        std::cout << "Rows=" << PQntuples(result_handle) << std::endl;
                        std::string o1,o2, o3;
                        double o4, o5;
                      std::cout << std::atof(PQgetvalue(result_handle, 0, 3)) << std::endl; ///always prints 0


               }  

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.