The official C++ client API for PostgreSQL.

Overview

libpqxx

Welcome to libpqxx, the C++ API to the PostgreSQL database management system.

Home page: http://pqxx.org/development/libpqxx/

Find libpqxx on Github: https://github.com/jtv/libpqxx

Documentation on Read The Docs: https://readthedocs.org/projects/libpqxx/

Compiling this package requires PostgreSQL to be installed -- or at least the C headers and library for client development. The library builds on top of PostgreSQL's standard C API, libpq, though your code won't notice.

If you're getting the code straight from the Git repo, the master branch contains the current development version. To get a released version, check out the revision that's tagged for that version. For example, to get version 7.1.1:

git checkout 7.1.1

Upgrade notes

The 7.x versions require C++17. However, it's probably not a problem if your compiler does not implement C++17 fully. Initially the 7.x series will only require some basic C++17 features such as std::string_view. More advanced use may follow later.

Also, 7.0 makes some breaking changes in rarely used APIs:

  • There is just a single connection class. It connects immediately.
  • Custom connection classes are no longer supported.
  • Closed connections can no longer be reactivated.
  • The API for defining string conversions has changed.

And if you're defining your own type conversions, *7.1 requires one additional field in your nullness traits.

Building libpqxx

There are two different ways of building libpqxx from the command line:

  1. Using CMake, on any system which supports it.
  2. On Unix-like systems, using a configure script.

"Unix-like" systems include GNU/Linux, Apple macOS and the BSD family, AIX, HP-UX, Irix, Solaris, etc. Even on Microsoft Windows, a Unix-like environment such as WSL, Cygwin, or MinGW should work.

You'll find detailed build and install instructions in BUILDING-configure.md and BUILDING-cmake.md, respectively.

And if you're working with Microsoft Visual Studio, have a look at Gordon Elliott's Easy-PQXX Build for Windows Visual Studio project:

https://github.com/GordonLElliott/Easy-PQXX-Build-for-Windows-Visual-Studio

At the time of writing, June 2020, this is still in development and in need of testers and feedback.

Documentation

Building the library, if you have the right tools installed, generates HTML documentation in the doc/ directory. It is based on the headers in include/pqxx/ and text in include/pqxx/doc/. The documentation is also available online at readthedocs.org.

Programming with libpqxx

Your first program will involve the libpqxx classes "connection" (see the pqxx/connection.hxx header), and work (a convenience alias for transaction<> which conforms to the interface defined in pqxx/transaction_base.hxx).

These *.hxx headers are not the ones you include in your program. Instead, include the versions without filename suffix (e.g. pqxx/connection). Those will include the actual .hxx files for you. This was done so that includes are in standard C++ style (as in <iostream> etc.), but an editor will still recognize them as files containing C++ code.

Continuing the list of classes, you will most likely also need the result class (pqxx/result.hxx). In a nutshell, you create a connection based on a Postgres connection string (see below), create a work in the context of that connection, and run one or more queries on the work which return result objects. The results are containers of rows of data, each of which you can treat as an array of strings: one for each field in the row. It's that simple.

Here is a simple example program to get you going, with full error handling:

#include <iostream>
#include <pqxx/pqxx>

int main()
{
    try
    {
        pqxx::connection C;
        std::cout << "Connected to " << C.dbname() << std::endl;
        pqxx::work W{C};

        pqxx::result R{W.exec("SELECT name FROM employee")};

        std::cout << "Found " << R.size() << "employees:\n";
        for (auto row: R)
            std::cout << row[0].c_str() << '\n';

        std::cout << "Doubling all employees' salaries...\n";
        W.exec0("UPDATE employee SET salary = salary*2");

        std::cout << "Making changes definite: ";
        W.commit();
        std::cout << "OK.\n";
    }
    catch (std::exception const &e)
    {
        std::cerr << e.what() << '\n';
        return 1;
    }
    return 0;
}

Connection strings

Postgres connection strings state which database server you wish to connect to, under which username, using which password, and so on. Their format is defined in the documentation for libpq, the C client interface for PostgreSQL. Alternatively, these values may be defined by setting certain environment variables as documented in e.g. the manual for psql, the command line interface to PostgreSQL. Again the definitions are the same for libpqxx-based programs.

The connection strings and variables are not fully and definitively documented here; this document will tell you just enough to get going. Check the PostgreSQL documentation for authoritative information.

The connection string consists of attribute=value pairs separated by spaces, e.g. "user=john password=1x2y3z4". The valid attributes include:

  • host Name of server to connect to, or the full file path (beginning with a slash) to a Unix-domain socket on the local machine. Defaults to "/tmp". Equivalent to (but overrides) environment variable PGHOST.

  • hostaddr IP address of a server to connect to; mutually exclusive with "host".

  • port Port number at the server host to connect to, or socket file name extension for Unix-domain connections. Equivalent to (but overrides) environment variable PGPORT.

  • dbname Name of the database to connect to. A single server may host multiple databases. Defaults to the same name as the current user's name. Equivalent to (but overrides) environment variable PGDATABASE.

  • user User name to connect under. This defaults to the name of the current user, although PostgreSQL users are not necessarily the same thing as system users.

  • requiressl If set to 1, demands an encrypted SSL connection (and fails if no SSL connection can be created).

Settings in the connection strings override the environment variables, which in turn override the default, on a variable-by-variable basis. You only need to define those variables that require non-default values.

Linking with libpqxx

To link your final program, make sure you link to both the C-level libpq library and the actual C++ library, libpqxx. With most Unix-style compilers, you'd do this using the options

	-lpqxx -lpq

while linking. Both libraries must be in your link path, so the linker knows where to find them. Any dynamic libraries you use must also be in a place where the loader can find them when loading your program at runtime.

Some users have reported problems using the above syntax, however, particularly when multiple versions of libpqxx are partially or incorrectly installed on the system. If you get massive link errors, try removing the "-lpqxx" argument from the command line and replacing it with the name of the libpqxx library binary instead. That's typically libpqxx.a, but you'll have to add the path to its location as well, e.g. /usr/local/pqxx/lib/libpqxx.a. This will ensure that the linker will use that exact version of the library rather than one found elsewhere on the system, and eliminate worries about the exact right version of the library being installed with your program..

Comments
  • problem of installing Windows

    problem of installing Windows

    I install x64 libpq then I build libpqxx using cmake and visual studio 2017. I got this error MSB4126 Debug |x64 is invalid. I need to build x64 libpqxx. How to do? Thanks,chenqingguo.

    opened by chenqingguo 110
  • Tuple support for separated_list(), tablewriter, tablereader

    Tuple support for separated_list(), tablewriter, tablereader

    First of all, I do see tablewriter and tablereader are marked as deprecated — is there currently a preferred alternative? If there isn't one, what exactly are the multibyte issues these run into, so I can take a stab at fixing/replacing these classes.

    I've found tablewriter to be pretty useful except for having to convert all values in a row into a single type. The class is written such that it mentions "tuples" but doesn't actually have support for tuple types (multiple elements of different types). I took a stab at implementing support for my own use, visible in my fork of libpqxx. This of course necessitated tuple support for separated_list(), which is not deprecated. If you want, I can make a pull request specifically for that.

    I isolated a proof-of-concept implementation for separated_list() in this gist; note this also supports plain arrays due to switching from c.begin()/c.end() to begin(c)/end(c) like C++11's range-based-for uses.

    opened by JadeMatrix 81
  • to_string fails on certain double values

    to_string fails on certain double values

    There seems to be an issue converting certain double floating point values to text. The issue is that one will receive a conversion overrun exception even though there is nothing special about the floating point value at all.

    This is all assuming we're using the pqxx::to_string(double) method.

    More specifically the problem is that the string buffer is too small for those double values that want to print more digits.

    In order to know how big the string buffer should be the code uses a so called buffer_budget number.

    For double values the budget becomes 21 chars at runtime (I presume this includes the terminating NUL character).

    Now let's look at two examples:

    This is fine:

    double d = 0.000111111111111111; // Okay (20+1 bytes)
    std::string s = pqxx::to_string(d);
    

    This is not, it'll throw a pqxx conversion overrun exception:

    double d = 0.0001111111111111111; // Not okay (21+1 bytes), to_string will throw exception
    std::string s = pqxx::to_string(d);
    

    (compiling with vs2017)

    opened by edwinvp 73
  • Test fails on FreeBSD 11.3

    Test fails on FreeBSD 11.3

    Hello, I checked out 7.1.1 and built:

    ../configure --prefix=/home/rmason/Software/LibPQXX/libpqxx/build

    Then I tried the tests, from the =build= directory:

    make PGHOST=127.0.0.1 PGDATABASE=rmason check

    Compilation succeeds but the test runner dumps core:

    make check-TESTS Segmentation fault (core dumped) FAIL: runner

    1 of 1 test failed Please report to Jeroen T. Vermeulen

    So here I am, reporting.

    Cheers, Roger

    opened by sprock 55
  • cmake build confusion

    cmake build confusion

    I am trying to update my project from 6.x.x to 7.1.0 and am having troubles with the cmake build system. My project uses cmake, and I include 6.x.x as a subdirectory. My cmake provides the various PostgreSQL_xxxxx variables (using pg_config because the cmake FindLibrary stuff is just broken) and sets a few of the options (shared libs off, tests off, docs off). Switching to 7.1.0 is just a mess and the docs aren't much of a help. It also appears that the cmake is attempting to "install" libpqxx somewhere (I don't want that), and that target properties need to be set in order to select static library instead of shared library? How do I set the target properties before I add_subdirectory?

    opened by abrownsword 47
  • New `exec_prepared` and `exec_params` don't support runtime variable argument lists

    New `exec_prepared` and `exec_params` don't support runtime variable argument lists

    Unless I'm missing something, the old prepared followed by exec methods (as we use here and here) no longer support the case where we don't know how many parameters we need until runtime.

    I'm looking at the APIs at these two locations:

    • https://github.com/jtv/libpqxx/blob/master/include/pqxx/transaction_base.hxx#L284
    • https://github.com/jtv/libpqxx/blob/master/include/pqxx/transaction_base.hxx#L347

    What's the intended method for doing this now? I'm looking at current HEAD of master. (ah, found something, see below)

    We've been used prepared statements for this, but actually for most of our use cases it'd probably be better to use exec_params method.

    What I think I really need is something with a function signature like this:

    template<typename Iter, typename Func>
    result exec_params(std::string_view query, Iter begin, Iter end, Func transform);
    
    template<typename Iter, typename Func>
    result exec_prepared(std::string_view query, Iter begin, Iter end, Func transform);
    

    Hopefully it's possible to do something with string_view rather than c_str for the return type from the transform, but for that to work I believe you'll actually need to expect transform to return std::optional<std::string_view>.

    I've just found #75 which also talks about this, so I'll have a go at that solution. The only way I found out about dynamic_params was to look at the commit referenced in the issue :-) Without the transform function it's going to cost several allocations to do the data transform I need :(

    opened by KayEss 47
  • CMake MSVC x64 Windows compilation failed

    CMake MSVC x64 Windows compilation failed

    Greetings. Trying to compile this library on windows. My project cmake:

    cmake_minimum_required (VERSION 3.6)
    set(CMAKE_CXX_STANDARD 23)
    
    project(toolgun)
    
    add_executable(toolgun main.cpp)
    
    set(SKIP_BUILD_TEST ON)
    set(BUILD_SHARED_LIBS ON)
    
    set(PostgreSQL_ROOT "C:/Program Files/PostgreSQL/14/")
    
    add_subdirectory(deps/libpqxx)
    

    Here is how configuring went:

    C:\Users\mails\Documents\C++\Toolgun\build>cmake .. -A x64
    -- Building for: Visual Studio 17 2022
    -- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19044.
    -- The C compiler identification is MSVC 19.31.31105.0
    -- The CXX compiler identification is MSVC 19.31.31105.0
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe - skipped
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.31.31103/bin/Hostx64/x64/cl.exe - skipped
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Found PostgreSQL: C:/Program Files/PostgreSQL/14/lib/libpq.lib (found version "14.2")
    -- Looking for poll
    -- Looking for poll - not found
    -- Looking for PQencryptPasswordConn
    -- Looking for PQencryptPasswordConn - not found
    -- Looking for PQenterPipelineMode
    -- Looking for PQenterPipelineMode - not found
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Generating config.h
    -- Generating config.h - done
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/Users/mails/Documents/C++/Toolgun/build
    

    Here is how build went:

    C:\Users\mails\Documents\C++\Toolgun\build>cmake --build . --config Debug
    Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.
    
      Checking Build System
      Building Custom Rule C:/Users/mails/Documents/C++/Toolgun/deps/libpqxx/src/CMakeLists.txt
      array.cxx
      binarystring.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      blob.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      connection.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      cursor.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      encodings.cxx
      errorhandler.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      except.cxx
      field.cxx
      largeobject.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      notification.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      params.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      pipeline.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      result.cxx
      robusttransaction.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      row.cxx
      sql_cursor.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      strconv.cxx
      stream_from.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      stream_to.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      Generating Code...
      Compiling...
      subtransaction.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      time.cxx
      transaction.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      transaction_base.cxx
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,23): error C2672: 'binary_cast': no matching overloaded function foun
    d [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/binarystring.hxx(220,1): error C7602: 'pqxx::binary_cast': the associated constraints are
    not satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\src\transaction_base.cxx(217,23): error C2672: 'binary_cast': no matching overloaded function found [C:
    \Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\src\transaction_base.cxx(217,38): error C7602: 'pqxx::binary_cast': the associated constraints are not
    satisfied [C:\Users\mails\Documents\C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
    C:\Users\mails\Documents\C++\Toolgun\deps\libpqxx\include\pqxx/util.hxx(296): message : see declaration of 'pqxx::binary_cast' [C:\Users\mails\Documents\
    C++\Toolgun\build\deps\libpqxx\src\pqxx.vcxproj]
      util.cxx
      version.cxx
      wait.cxx
      Generating Code...
      Building Custom Rule C:/Users/mails/Documents/C++/Toolgun/CMakeLists.txt
      main.cpp
    C:\Users\mails\Documents\C++\Toolgun\main.cpp(2,10): fatal error C1083: Cannot open include file: 'pqxx/pqxx': No such file or directory [C:\Users\mails\
    Documents\C++\Toolgun\build\toolgun.vcxproj]
    

    Basically:

    • No 'pqxx/pqxx'
    • binary_cast issue
    opened by GitSparTV 46
  • Enhancement: Asynchronous database connection.

    Enhancement: Asynchronous database connection.

    Connecting over a slow network link can take some time. Connecting to an unreachable host can also take some time to fail.

    My understanding, which may be incorrect, is that constructing a pqxx::connection() blocks while libpqxx attempts to connect to the database. This can cause applications to hang, much to user frustration, and also cause issues in real time data processing applications.

    It would be nice if there was a way to construct a pqxx::connection instance without blocking and then access the underlying socket in an event loop to trigger calls to libpqxx to further process the connection, calling a libpqxx function to determine if connecting is successful, in progress, or failed.

    I am trying to write an application to track the different versions of firmware that get programmed onto various devices and then send the data back to base (where an internet connection is present) to store it in a database so we know what version of firmware is flashed on each device for each customer. When out in the field we may need to connect using VPN over 3G or 4G - not a fast connection by any means. The last thing I need is my boss getting irate because the software hung for 10 seconds for no apparent reason. Also, detailed error codes as to why connection failed would be good. Was it a network failure or simply wrong credentials? I have looked through the code, but other than trapping exceptions and reporting the exception string there doesn't seem to be any way to determine why a connection failed to open.

    opened by AlastairGrowcott 43
  • Cannot build using mingw on Ubuntu and conan

    Cannot build using mingw on Ubuntu and conan

    Hey,

    when I try to build an app that uses this library and wxWidgets. When ever I try to build the app using mingw on Ubuntu it fails with the following error:

    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x2b): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x4a): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0x89): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(main.cpp.obj):main.cpp:(.text.startup+0xa8): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainApp.cpp.obj):MainApp.cpp:(.text.startup+0x2b): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainApp.cpp.obj):MainApp.cpp:(.text.startup+0x4a): more undefined references to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)' follow
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x24b9): undefined reference to `pqxx::connection::init(char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x24f4): undefined reference to `pqxx::internal::basic_transaction::basic_transaction(pqxx::connection&, pqxx::zview)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x253d): undefined reference to `pqxx::connection::esc[abi:cxx11](std::basic_string_view<char, std::char_traits<char> >) const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x274a): undefined reference to `pqxx::transaction_base::exec(std::basic_string_view<char, std::char_traits<char> >, std::basic_string_view<char, std::char_traits<char> >)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2782): undefined reference to `pqxx::result::begin() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x278a): undefined reference to `pqxx::result::size() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2794): undefined reference to `pqxx::result::columns() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x27b5): undefined reference to `pqxx::row::row(pqxx::result const&, int, int)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e23): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e2b): undefined reference to `pqxx::field::is_null() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e3b): undefined reference to `pqxx::field::size() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e46): undefined reference to `pqxx::field::c_str() const &'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e5e): undefined reference to `pqxx::internal::float_traits<float>::from_string(std::basic_string_view<char, std::char_traits<char> >)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e92): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2e9a): undefined reference to `pqxx::field::is_null() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2eaa): undefined reference to `pqxx::field::size() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2eb5): undefined reference to `pqxx::field::c_str() const &'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2ecd): undefined reference to `pqxx::internal::float_traits<float>::from_string(std::basic_string_view<char, std::char_traits<char> >)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f02): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f0a): undefined reference to `pqxx::field::is_null() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f1a): undefined reference to `pqxx::field::size() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f25): undefined reference to `pqxx::field::c_str() const &'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f3d): undefined reference to `pqxx::internal::float_traits<double>::from_string(std::basic_string_view<char, std::char_traits<char> >)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f73): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f7b): undefined reference to `pqxx::field::is_null() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f8b): undefined reference to `pqxx::field::size() const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2f96): undefined reference to `pqxx::field::c_str() const &'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2fae): undefined reference to `pqxx::internal::float_traits<double>::from_string(std::basic_string_view<char, std::char_traits<char> >)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2fed): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x2ff5): undefined reference to `pqxx::field::c_str() const &'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x310d): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3115): undefined reference to `pqxx::field::c_str() const &'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3225): undefined reference to `pqxx::row::operator[](pqxx::zview) const'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x322d): undefined reference to `pqxx::field::c_str() const &'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3aed): undefined reference to `pqxx::transaction_base::commit()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3c9e): undefined reference to `pqxx::transaction_base::close()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3ca6): undefined reference to `pqxx::internal::basic_transaction::~basic_transaction()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3cb3): undefined reference to `pqxx::connection::close()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x3f2d): undefined reference to `pqxx::internal::check_pqxx_version_7_7()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x422f): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x423b): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x4247): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x4253): undefined reference to `pqxx::internal::throw_null_conversion(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x43a5): undefined reference to `pqxx::transaction_base::close()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text+0x43ad): undefined reference to `pqxx::internal::basic_transaction::~basic_transaction()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED1Ev[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED1Ev]+0x14): undefined reference to `pqxx::transaction_base::close()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED1Ev[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED1Ev]+0x22): undefined reference to `pqxx::internal::basic_transaction::~basic_transaction()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED0Ev[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED0Ev]+0x14): undefined reference to `pqxx::transaction_base::close()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED0Ev[_ZN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EED0Ev]+0x1c): undefined reference to `pqxx::internal::basic_transaction::~basic_transaction()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text$_ZN4pqxx10connectionD1Ev[_ZN4pqxx10connectionD1Ev]+0xc): undefined reference to `pqxx::connection::close()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0x2b): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0x4a): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0x78): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0xa6): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0xd4): undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.text.startup+0xf3): more undefined references to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)' follow
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.rdata$_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EEE[_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EEE]+0x20): undefined reference to `pqxx::internal::basic_transaction::do_commit()'
    /usr/bin/x86_64-w64-mingw32-ld: CMakeFiles/filament_manager.dir/objects.a(MainWindow.cpp.obj):MainWindow.cpp:(.rdata$_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EEE[_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_12write_policyE1EEE]+0x28): undefined reference to `pqxx::transaction_base::do_abort()'
    collect2: error: ld returned 1 exit status
    gmake[2]: *** [CMakeFiles/filament_manager.dir/build.make:151: bin/filament_manager.exe] Error 1
    gmake[1]: *** [CMakeFiles/Makefile2:526: CMakeFiles/filament_manager.dir/all] Error 2
    gmake: *** [Makefile:149: all] Error 2
    The command '/bin/sh -c cmake --build build/' returned a non-zero code: 2
    
    

    The issue can be reproduced with the following Dockerfile:

    FROM ubuntu:rolling
    
    ENV DEBIAN_FRONTEND noninteractive
    RUN apt-get update && apt-get upgrade -y
    RUN apt-get install mingw-w64 mingw-w64-x86-64-dev g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 build-essential cmake git wget -y
    RUN wget https://github.com/conan-io/conan/releases/latest/download/conan-ubuntu-64.deb
    RUN dpkg -i conan-ubuntu-64.deb
    RUN git clone https://github.com/DerKnerd/filament-browser.git
    WORKDIR /filament-browser
    RUN git checkout e513b687d92de70bd83ad100b642032c8c44124c
    RUN git submodule update --init --recursive
    RUN cmake -DCMAKE_TOOLCHAIN_FILE=/filament-browser/mingw-w64-x86_64.cmake -B build -S /filament-browser -DCMAKE_BUILD_TYPE=Release
    RUN cmake --build build/
    

    And here is the CMakeList.txt I use:

    cmake_minimum_required(VERSION 3.16)
    project(filament_manager CXX)
    
    set(CMAKE_CXX_STANDARD 20)
    
    include(./ucm.cmake)
    include(./conan.cmake)
    
    ucm_set_runtime(STATIC)
    if (WIN32 OR MINGW)
        add_compile_definitions(__WXMSW__ _UNICODE)
        set(BUILD_SHARED_LIBS false)
        set(CMAKE_SYSTEM_NAME Windows)
        set(CMAKE_SYSTEM_PROCESSOR x86_64)
        set(CONAN_ARCHITECTURE x86_64)
        set(CMAKE_WIN32_EXECUTABLE 1)
        set(options Poco:enable_netssl_win=True Poco:enable_netssl=False)
    
        conan_cmake_run(
                BASIC_SETUP
                ARCH ${CONAN_ARCHITECTURE}
                ENV CC=${CMAKE_C_COMPILER}
                ENV CXX=${CMAKE_CXX_COMPILER}
                ENV CFLAGS=${CMAKE_C_FLAGS}
                ENV CXXFLAGS=${CMAKE_CXX_FLAGS}
                SETTINGS os=Windows
                SETTINGS compiler.cppstd=20
        )
    endif ()
    
    set(wxUSE_STL ON)
    set(wxBUILD_SHARED OFF)
    add_subdirectory(libs/wxWidgets)
    
    list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
    list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR})
    
    conan_cmake_configure(
            REQUIRES libpqxx/7.7.0
            GENERATORS cmake_find_package
    )
    
    conan_cmake_autodetect(settings)
    
    conan_cmake_install(PATH_OR_REFERENCE .
            BUILD missing
            REMOTE conancenter
            SETTINGS ${settings}
            SETTINGS ${CONAN_SETTINGS}
            OPTIONS Poco:enable_netssl_win=True Poco:enable_netssl=False)
    
    find_package(libpqxx)
    
    add_executable(filament_manager ${target} main.cpp MainApp.h MainApp.cpp MainWindow.cpp MainWindow.h)
    target_link_libraries(filament_manager PRIVATE libpqxx::libpqxx wx::core wx::base)
    

    And this is the toolchain file:

    # Sample toolchain file for building for Windows from an Ubuntu Linux system.
    #
    # Typical usage:
    #    *) install cross compiler: `sudo apt-get install mingw-w64`
    #    *) cd build
    #    *) cmake -DCMAKE_TOOLCHAIN_FILE=~/mingw-w64-x86_64.cmake ..
    
    set(CMAKE_SYSTEM_NAME Windows)
    set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
    
    # cross compilers to use for C, C++ and Fortran
    set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
    set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++)
    set(CMAKE_Fortran_COMPILER ${TOOLCHAIN_PREFIX}-gfortran)
    set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres)
    
    # target environment on the build host system
    set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX})
    
    # modify default behavior of FIND_XXX() commands
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    

    Do you by any chance know what causes this issue?

    opened by DerKnerd 41
  • Trying to use libpqxx on a cmake project, but getting errors

    Trying to use libpqxx on a cmake project, but getting errors

    Hi, I dont know if this is the right channel, if not please direct me to it. I have a small project (one .h and one .cpp) where I include a compiled version of this project 7.4.1. I am able to include the <pqxx/pqxx> header and all that goes with it. In the link phase I am having the following error :

    -- Configuring done -- Generating done -- Build files have been written to: C:/code/NervesOfSteelProject/DatabaseNode/cmake-build-debug [ 50%] Building CXX object CMakeFiles/NOSDatabaseProcess.dir/NOSDatabaseProcess.cpp.obj [100%] Linking CXX executable NOSDatabaseProcess.exe CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function __static_initialization_and_destruction_0': C:/code/NervesOfSteelProject/DatabaseNode/libpqxx/include/pqxx/strconv.hxx:76: undefined reference topqxx::internal::demangle_type_name[abi:cxx11](char const*)' C:/code/NervesOfSteelProject/DatabaseNode/libpqxx/include/pqxx/strconv.hxx:76: undefined reference to pqxx::internal::demangle_type_name[abi:cxx11](char const*)' C:/code/NervesOfSteelProject/DatabaseNode/libpqxx/include/pqxx/strconv.hxx:76: undefined reference topqxx::internal::demangle_type_name[abi:cxx11](char const*)' C:/code/NervesOfSteelProject/DatabaseNode/libpqxx/include/pqxx/strconv.hxx:76: undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)' collect2.exe: error: ld returned 1 exit status mingw32-make.exe[2]: *** [CMakeFiles\NOSDatabaseProcess.dir\build.make:107: NOSDatabaseProcess.exe] Error 1 mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:95: CMakeFiles/NOSDatabaseProcess.dir/all] Error 2 mingw32-make.exe: *** [Makefile:103: all] Error 2

    I am forcing my project to use C++ 17. If I don't I get a greater amount of errors. Can you help me ? Thanks, Regards

    opened by daniel-dlds 40
  • pqxx library build error for crosscompiling on linux for Windows target with Mingw64

    pqxx library build error for crosscompiling on linux for Windows target with Mingw64

    I built PostrgeSQL libpq (.dll, .a, ,..) v9.3.6 on ubuntu 14.04 and then tried building libpqxx v6.2.5 using cmake. It failed with error below: [ 35%] Linking CXX shared library libpqxx.dll CMakeFiles/pqxx_shared.dir/objects.a(connection_base.cxx.obj):connection_base.cxx:(.text+0x8eac): undefined reference to `__imp_select' collect2: error: ld returned 1 exit status make[2]: *** [src/libpqxx.dll] Error 1 make[1]: *** [src/CMakeFiles/pqxx_shared.dir/all] Error 2 make: *** [all] Error Since PostgreSQL distro doers not have support for find_PQ.cmake, I replaced find_package with find_library and cmake funds static libpq.a while I am trying to build for .dll Windows I am not sure how to figure out the issue. Changing versions to later is not desirable as I am porting code that works with v9.3.5 on linux (arm or x86).

    opened by yscontrol 38
  • Speed up encoding handling in streams.

    Speed up encoding handling in streams.

    Speeds up scanning of text in various encodings in stream_to and stream_from. (Even stream_to needs to be able to do that, because it escapes data for use with COPY.)

    The optimisations are:

    1. Inline glyph scanning function in the search loop.
    2. For "ASCII-safe" encodings, use the "monobyte" search loop.

    The inlining optimisation works as follows: Previously the stream classes kept a pointer to a function that figures out glyph boundaries (the byte where the next character begins in a byte string). It looks up the function specialised for the current kind of encoding: UTF-8, GBK, SJIS, etc... or "monobyte" for single-byte encodings. In libpqxx I call those functions glyph scanners. But this way of working is painfully slow: the stream calls that function pointer for every single character it tries to read. Here, I rewrite the loop to use a different specialised function pointer, which works at a higher level: "Find any one of these special characters." That means that the inner loop is now inside that function, not on the outside calling in. Gives the compiler more of a chance to optimise the loop.

    The other change is based on the fact that many encodings have two basic kinds of characters: ASCII ones which are in the 0..127 range, and non-ASCII ones in the non-ASCII byte range — they have the high bit in their bit value set to 1. And that means that we can never have the "SJIS" situation where an ASCII byte value (such as that of a backslash character) can also occur inside a multibyte character. When we know we're in an encoding where that can't ever happen (and UTF-8 is one of those!) then we don't need the glyph scanner for that encoding at all. We can just use the simpler "monobyte" glyph scanner which just always returns offset + 1.

    Neither of these optimisations is particularly powerful on its own. Inlining UTF-8 scanning (for instance) will probably be a bit faster than a function pointer, but it won't be a huge difference. And calling a simpler glyph scanner won't do us much good, especially if that just means that we'll need to call it 3 times for a 3-byte character, for instance. But the two changes work well together: the monobyte scanner can be as simple as an offset++.

    Unfortunately this is an ABI-breaking change. We're replacing a function pointer field with a pointer to a different type of function.

    opened by jtv 0
  • Feature request: Can 'quote' and 'escape' be separated from connection/transaction?

    Feature request: Can 'quote' and 'escape' be separated from connection/transaction?

    Hi

    I find that I have a need to create query requests separately from running those queries. The problem I have is that I need to 'quote' or 'escape' user inputs that go into the query. But I am not in the code which runs the queries (which has connection and transaction objects), so those functions are not available to me.

    For the time being, I work around this by creating a connection in my code which creates the queries whose only function is to provide access to quote/escape functions.

    Is there a better way?

    Thanks

    Dave Riedel

    opened by dpriedel 2
  • How to config CMakeLists.txt and package.xml in ROS using libpqxx?

    How to config CMakeLists.txt and package.xml in ROS using libpqxx?

    In my project, I want to use libpqxx library to connect the postgreSQL,when i run the command 'g++ my_src -lpqxx -lpq' ,the file can build successful ,but i want to using catkin_make(ROS) to built this file ,I don't know how to config CMakelist.txt and package.xml file to use the library libpqxx .

    Is there anyone who can give some help, thanks?

    opened by hwLiu8 2
  • as_array() on varchar-based array_agg() column - and semicolon separator

    as_array() on varchar-based array_agg() column - and semicolon separator

    We've experienced some issue when using as_array() on a varchar-based array_agg() column:

      auto values = psql_array_to_vector(row["tag_v"].as_array());
    
    (psql_array_to_vector is a simple wrapper method calling the libpqxx provided array parser)
    std::vector<std::string> psql_array_to_vector(pqxx::array_parser&& parser) {
      std::vector<std::string> result;
    
      auto obj = parser.get_next();
      while (obj.first != pqxx::array_parser::done)
      {
        if (obj.first == pqxx::array_parser::string_value) {
          result.push_back(obj.second);
        }
        obj = parser.get_next();
      }
      return result;
    }
    

    Source:

    • https://github.com/zerebubuth/openstreetmap-cgimap/blob/89e84c1e89479a64f7736f7d5cef28a03278d273/src/backend/apidb/common_pgsql_selection.cpp#L78-L79
    • https://github.com/zerebubuth/openstreetmap-cgimap/blob/89e84c1e89479a64f7736f7d5cef28a03278d273/src/data_selection.cpp#L9-L21

    For our payload {use_sidepath,secondary,3,1,yes,50,"Rijksweg Noord",asphalt,left|through;right}, we expected the libpqxx array parser to extract 9 values, rather than 10.

    10 values:
        use_sidepath
        secondary
        3
        1
        yes
        50
        Rijksweg Noord
        asphalt
        left|through
        right
    

    As shown in the payload above, the last element in the array ( asphalt,left|through;right ) is both unquoted, and contains a semicolon character.

    libpqxx seems to treat this semicolon as a separator character, although the underlying datatype is a varchar. We didn't find any way to influence which characters should be treated as a separator character. As Postgresql wouldn't escape a string containing semicolons, it would be good not to consider semicolon as a separator here.

    https://github.com/zerebubuth/openstreetmap-cgimap/issues/276#issuecomment-1196380394 has a bit more discussion

    Relevant query
    SELECT w.id, w.visible, 
             to_char(w.timestamp,'YYYY-MM-DD\T\HH24:MI:SS\Z\') AS timestamp, 
             w.changeset_id, w.version, t.keys as tag_k, t.values as tag_v, 
             wn.node_ids as node_ids 
           FROM current_ways w 
             LEFT JOIN LATERAL 
               (SELECT array_agg(k) as keys, array_agg(v) as values 
                FROM current_way_tags WHERE w.id=way_id) t ON true 
             LEFT JOIN LATERAL 
               (SELECT array_agg(node_id) as node_ids 
                FROM 
                  (SELECT node_id FROM current_way_nodes WHERE w.id=way_id 
                   ORDER BY sequence_id) x) wn ON true 
           WHERE w.id = 4000392205
           ORDER BY w.id
    

    (based on https://github.com/zerebubuth/openstreetmap-cgimap/blob/master/test/structure.sql)

    Downstream issue: https://github.com/zerebubuth/openstreetmap-cgimap/issues/276

    Thanks for looking in this!

    @tomhughes, @pnorman: please chime in, in case I forgot something.

    opened by mmd-osm 2
Releases(7.7.4)
  • 7.7.4(Jul 6, 2022)

    This comes as a patch update, but it's a pretty big thing: libpqxx 7.7.4 comes with new, more convenient ways to query data.

    In many cases you can simply forget about the pqxx::result class. Instead, use a transaction's "query" functions (query(), query1(), query01(), query_n(), query_value()) to execute an SQL query and go straight to the result data, converted into the C++ types of your choice. Or use for_query() to execute a query and on each row, invoke a callback you provide.

    As a high-performance alternative, you can stream() your query. This works much like query(), except it starts iterating rows as soon as they come in (where query() waits for the full result first) and the rows come faster. Initial startup is a bit slower than with query(), but when you're expecting a lot of rows, it's likely to be faster and use less memory.

    And then there's the classic "exec" functions (exec(), exec0(), exec1(), exec_n()). These return pqxx::result objects, apart from exec1() which returns a pqxx::row for convenience. Use these only when you expect no data rows, or when you need the result's metadata, such as the number of rows affected by an UPDATE statement.

    I'd be interested to hear about your experiences! Do you still need pqxx::result at all in your application? Feel free to file a bug giving me some feedback.

    Source code(tar.gz)
    Source code(zip)
  • 7.7.3(Apr 14, 2022)

    This is mostly a bug-fix release. But also, it continues reorganising how libpqxx headers include each other. It's clearer and simpler now, it's easier to get right, and also, it seems to compile faster. Oh, and there's a new way to iterate over rows in a result or a streamed query.

    Here's what else has changed:

    • Fix up more damage done by auto-formatting.
    • New result::for_each(): simple iteration and conversion of rows. (#528)
    • Similarly, transaction_base::for_each() — stream a query and run a callback on each row.
    • Add some missing headers in <pqxx/pqxx>. (#551)
    • More strictness in header-pre.hxx/header-post.hxx checking.
    • Disallow nesting of ignore-deprecated blocks.
    • Deprecate exec functions' desc parameter.
    • Fix placeholders documentation. (#557)
    • Strip const and references from value_type. (#558)
    • Get tests running on appveyor. (#560)
    • Fix broken nonblocking connection on Windows. (#560)

    This release may break some things for you:

    1. If you included the wrong libpqxx headers directly into your own code, you will get an error message about it. Include only the <pqxx/something> headers yourself, not any of the .hxx ones.
    2. The exec() query execution functions no longer accept a desc (description) argument. In C++20, we'll replace that with std::source_location so that we can automatically show the location in the source code where the failing query was issued. Or optionally, some different location that you pass explicitly.
    Source code(tar.gz)
    Source code(zip)
  • 7.7.2(Mar 23, 2022)

    Sorry, the 7.7.1 release was a dud. Rushed it, after bedtime, somebody talking at me. Try 7.7.2 instead.

    Here's the 7.7.1 changes again:

    The configure script no longer tries to tell your compiler what C++ language version it should compile. If you want a specific C++ version, you need to pass the right options to the compiler. Otherwise, you get your compiler's default C++ version.

    Also:

    • Fix digit_to_number not being found on some compilers. (#518, #519)
    • In audit mode, define _FORTIFY_SOURCE to enable some extra checks.
    • Make more functions constexpr. Nothing particularly useful though.
    • Make more functions noexcept.
    • Move constructor & move assignment for result.
    • Deprecate set_variable/get_variable on transaction_base. (Design had unearthed warts in SQL variables, which were later fixed.)
    • Set/get session variables on connection: set_session_var/get_var.
    • Set/get local variables: execute SQL statements.
    • When using select(), include <winsock2.h> if available. (#548)
    • Fix those pointless MSVC warnings at last.
    • Fix when cross-compiling using MinGW and CMake. (#548, #550)

    I also reorganised the way libpqxx #includes its own headers. You may find that builds are a bit faster.

    Source code(tar.gz)
    Source code(zip)
  • 7.7.1(Mar 23, 2022)

    The main change in libpqxx 7.7.1 is that the configure script no longer tries to tell your compiler what C++ language version it should compile. If you want a specific C++ version, you need to pass the right options to the compiler. Otherwise, you get your compiler's default C++ version.

    There are many other changes:

    • Finally fix a long-standing silly warning in autogen.
    • Fix digit_to_number not being found on some compilers. (#518, #519)
    • In audit mode, define _FORTIFY_SOURCE to enable some extra checks.
    • Make more functions constexpr. Nothing particularly useful though.
    • Make more functions noexcept.
    • Move constructor & move assignment for result.
    • Support LGTM.com and Facebook "infer" static analysis.
    • Deprecate set_variable/get_variable on transaction_base. (Design had unearthed warts in SQL variables, which were later fixed.)
    • Set/get session variables on connection: set_session_var/get_var.
    • Set/get local variables: execute SQL statements.
    • When using select(), include <winsock2.h> if available. (#548)
    • Library includes its own headers differently. Simpler, compiles faster.
    • Fix those pointless MSVC warnings at last.
    • Extract waiting functions into separate module.
    • Fix when cross-compiling using MinGW and CMake. (#548, #550)

    I also reorganised the way libpqxx #includes its own headers. You may find that builds are a bit faster.

    Source code(tar.gz)
    Source code(zip)
  • 7.7.0(Jan 9, 2022)

    It's going to be a big one. Believe me, I toyed with the idea of calling it 8.0. But I think it's not quite radical enough for that. I'm still hoping to raise the language baseline to C++20 for libpqxx 8.0. We'll see.

    But here's what you get:

    This version introduces a new class, connecting, for connecting to the database asynchronously. It's not native C++ async support, and it's not based on coroutines, but you can build coroutines on top of it. Kirit Sælensminde has built a sample project for this..

    You can now convert SQL range values to and from C++ strings, using the new pqxx::range class.

    There is now also support for converting between SQL timestamps (without time zones) and C++ std::chrono::year_month_day values. It's pretty limited, because there are lots of inherent problems with date/time support. For one, it only works with the ISO date format.

    If you want fast access to a result's fields without having to go through row objects, the pqxx::result class now has a two-dimensional at() member that takes a row number and a column number. And since there's a proposal for permitting two-dimensional array indexing in C++23, there's a provisional two-dimensional operator[] as well. (However I can't test this yet, so it could be broken.)

    The project now has a file requirements.json which lists the minimum major versions of compilers, C++, and PostgreSQL that you need for the current version of libpqxx. It's not going to be too detailed, because the more detail I put in there, the more is going to go wrong in maintenance. But at least it should be easy to see in the future which libpqxx versions require which C++ versions etc.

    The Doxygen documentation now uses the (Doxygen-extended) Markdown format. That should make the documentation comments in the libpqxx headers a little more modern and easier to read.

    Also, we now build docs in doc/html/, no longer in doc/html/Reference/.

    There are also some changes that may affect you without exactly creating serious incompatibilities. More functions are [[nodiscard]]. Some member functions are now lvalue-qualified or rvalue-qualified. You can't call an lvalue-qualified function on an rvalue object — so I lvalue-qualified some functions that sane code would not call as the last operation on an object. I also rvalue-qualified one member function that effectively invalidates its object.

    Finally, I promised you a lot of fixes:

    • Fix stream_to for differing table/client encodings. (#473)
    • Use [[likely]] & [[unlikely]] only in C++20, to silence warnings.
    • Fix clang "not a const expression" error in Windows. (#472)
    • Fix warnings about [[likely]] in if constexpr. (#475)
    • Clearer error for ambiguous string conversion of char type. (#481)
    • Statement name in prepare() error was for the wrong statement. (#488)
    • Helper for implementing string traits: generic_to_buf.
    • Work around broken std::filesystem::path in MinGW. (#498)
    • Fix leak when getting client encoding fails. (#500)
    • Re-enable pyflakes testing in tools/lint.
    • Don't run clang-tidy by default. Compatibility issues with gcc options.
    • Disable some std::filesystem features on Windows.
    • Shut up stupid Visual Studio warnings.
    • On gcc, mark rarely-used functions as "cold," to be optimised for size.
    • Glyph scanning for GB18030 encoding was utterly broken. (#517)

    Did I promise too much? Hope you all have a great 2022!

    Source code(tar.gz)
    Source code(zip)
  • 7.6.1(Jan 9, 2022)

    Support for the GB18030 encoding contained a bug that would probably have triggered an exception when trying to stream data or handle SQL arrays, composite values, streaming queries, or SQL range values.

    See #517.

    Source code(tar.gz)
    Source code(zip)
  • 7.5.3(Jan 9, 2022)

    Support for the GB18030 encoding contained a bug that would probably have triggered an exception when trying to stream data or handle SQL arrays, composite values, streaming queries, or SQL range values.

    See #517.

    Source code(tar.gz)
    Source code(zip)
  • 7.4.2(Jan 9, 2022)

    Support for the GB18030 encoding contained a bug that would probably have triggered an exception when trying to stream data or handle SQL arrays, composite values, streaming queries, or SQL range values.

    See #517.

    Source code(tar.gz)
    Source code(zip)
  • 7.3.2(Jan 9, 2022)

    Support for the GB18030 encoding contained a bug that would probably have triggered an exception when trying to stream data or handle SQL arrays, composite values, streaming queries, or SQL range values.

    See #517.

    Source code(tar.gz)
    Source code(zip)
  • 6.4.8(Dec 15, 2021)

    This bugfix update to the old 6.x series resolves a bug where executing a prepared statement would fail to activate the ongoing transaction.

    That is, if the first thing you did in a transaction was execute a prepared statement, the actual transaction would not start at that point. The prepared statement would execute outside it.

    Newer versions of libpqxx (as of 7.0) never had this problem because they start transactions as soon as you create them. If your environment supports C++17, please use those newer versions instead.

    Source code(tar.gz)
    Source code(zip)
  • 7.6.0(Jul 28, 2021)

    Bad news first: I just removed the ability to convert a string to std::basic_string_view<std::byte>. I'm sorry: this conversion should never have existed and it's not safe to use. See bug #463. It's not safe because it leaves no object to "own" the converted data. The view points into deallocated memory. If this breaks your code, use std::basic_string<std::byte> instead — so string, not string_view.

    Now for the good news, of which there is a lot:

    • Add C++20 concepts: binary, char_string, char_strings.
    • In C++20: generalise binary strings to any contiguous range of std::byte.
    • Mark zview as a view and as a borrowed range.
    • Save a copy step on string fields in stream_to.
    • New helper: pqxx::value_type<CONTAINER>.
    • New helper: pqxx::binary_cast. (#450)
    • Some escaping functions now have "into my buffer" variants.
    • More generic escaping functions, supporting more types of binary.
    • In C++20, accept generic columns list for stream_to. (#447)
    • Renamed <pqxx/prepared_statement> to <pqxx/params>. (Old name still works for now, of course.)
    • Deprecated dynamic_params in favour of params.
    • pqxx::params::append_multi() now calls reserve() if possible.
    • pqxx::params::size() is now noexcept (but sadly, ssize() is not — because std::ssize() isn't).
    • Helper for generating parameter placeholders $1, $2, etc. (#443)
    • Now requires support for C++14 [[deprecated]] attribute.
    • Deprecated unesc_raw() in favour of unesc_bin() variants.
    • Once unesc_raw() is gone, we'll support only the hex escape format for binary data.
    • Work around broken thread_local in MinGW gcc < 11.1.
    • pqxx::blob now supports std::filesystem::path.
    • Fixed check against header/lib version mismatch: check_pqxx_version_7_6
    • More complete documentation, of cursors in particular.

    Finally, "result slicing" is now deprecated. It will go away in the future. Was anyone using this? It never felt complete or useful to me, and I haven't heard anyone mention it in at least a decade. Once we get rid of it, that'll shave a tiny bit of complexity out of your inner loops and make them a little more efficient. The main reason though is simplicity. Simpler code means fewer mistakes and surprises.

    Source code(tar.gz)
    Source code(zip)
  • 7.5.2(May 8, 2021)

    This is an emergency patch release. The recently added pqxx::blob::read() variant which takes a std::vector<std::byte> was utterly broken. It did not actually read any data from the blob.

    This is now fixed, and properly tested.

    Source code(tar.gz)
    Source code(zip)
  • 7.5.1(May 8, 2021)

    This maintenance release of libpqxx works around a <thread> bug in MinGW; fixes some Visual C++ warnings; and makes the code a little easier to build out of the box by including config/compile in revision control.

    But also, it deprecates more "legacy" representations of binary data, such as unsigned char *. We keep moving towards std::byte. If your compiler supports it, upcoming releases will move towards generic support for spans and ranges of binary data. If not, you'll need to represent binary data as std::basic_string<std::byte> and std::basic_string_view<std::byte>.

    Eventually we'll raise the baseline C++ version to C++20, and at that point, it will be all ranges and spans.

    Source code(tar.gz)
    Source code(zip)
  • 7.5.0(Apr 24, 2021)

    There are now more ways to pass a BYTEA parameter to a query, and more of them get passed as binary data without intervening encode/decode pass. This last part makes it more efficient, but should not be visible to you otherwise.

    When it comes to passing parameters to queries, some people wanted a way to build parameter lists on the fly. This was possible with the old parameter-passing API, but never actually supported. There is now a class for doing this, params, with some optimisation built in to prevent unnecessary copying of string_view and similar values.

    "Blobs" (the new BYTEA API) have a new read() method on compilers which support C++20 "spans." It's based on std::span, and you can expect more use of spans soon.

    Here's the more complete list:

    • Now requires std::variant support! No longer works with gcc7.
    • When implementing a string conversion, consider specialising param_format.
    • Stop "aborting" nontransaction on closing. (#419)
    • Silence an overzealous Visual C++ warning. (#418)
    • Starting support for C++20 std::span.
    • New blob::read() using std::span. (#429)
    • New params class lets you build parameter lists incrementally. (#387)
    • Pass std::vector<std::byte> params in binary format.
    • Dropped legacy tests 31 and 49 to work around clang C++20 bug.
    • Fixed stream_to test failure in non-English locales. (#440)
    • Clarify transaction_base::stream documentation. (#423)
    • Avoid <thread> on MinGW; it's broken there. (#336, #398, #424, #441)
    Source code(tar.gz)
    Source code(zip)
  • 7.4.1(Feb 23, 2021)

    This is a minor build fix. There are no other fixes, so if you have 7.4.0 and it works, this patch will make no difference to you.

    But if 7,.4.0 failed to build on your system, this may well fix it.

    Source code(tar.gz)
    Source code(zip)
  • 7.4.0(Feb 23, 2021)

    Named constructors

    Some classes were getting too many constructors. Too much overloading makes for a programming minefield. So these classes are now growing factory functions, also known as named constructors.

    For these classes, I would like applications to replace this kind of existing code:

    pqxx::stream_to mystream(tx, "mytable");
    

    with this new-style code:

    auto mystream(pqxx::stream_to(tx, "mytable"));
    

    Actually there's another change in that line; read on below.

    Table paths

    Sometimes you need to pass a table name to a libpqxx function. The function will often quote and escape that name internally. But what if the table name includes a schema name, and perhaps even a database name? If we quote the whole thing as one string, it will look to the database as a single weird name, with dots in it. What should happen is that libpqxx quotes each portion (database name, schema name, table name) separately, and puts bare dots between them.

    To support that, there's a new way of describing table names: table_path, an alias for std::initializer_list<std::string_view>. Use this instead of strings to specify table names.

    So instead of this:

    auto mystream(pqxx::stream_to(tx, "mytable"));
    

    ...I would prefer you to write this:

    auto mystream(pqxx::stream_to(tx, {"mytable"}));
    

    The difference is that a table path is not just a name, it's a sequence of one, two, or three strings. (The last of those being the table name, of course.)

    Which means that you can now also write:

    auto mystream(pqxx::stream_to(tx, {"myschema", "mytable"}));
    

    The rest

    All major changes:

    • Work around Visual Studio 2017 bug with [[deprecated]]. (#405, #406)
    • Work around eternal Windows bug with max macro yet again. (#101)
    • Prepare for C++20 std::ssize().
    • Dropped test12, which didn't add much and tried to read null strings.
    • Support string conversion for std::monostate. (#409)
    • Consistent "named constructors" for stream_to and stream_from.
    • New table_path type.
    • New connection methods quote_table and quote_columns.
    • Lots of deprecated stream constructors.
    • pqxx::row::swap() now finally has the deprecated attribute.
    • Finally deprecated a bunch of field, row, and result constructors.
    • Exposed transaction_focus marker class.
    Source code(tar.gz)
    Source code(zip)
  • 7.3.1(Jan 11, 2021)

    This new release replaces the largeobject class and friends with a single, much simpler blob class. Down with complexity! The new API has no streams; I don't think those stream classes really added much over a basic "write these n bytes" API.

    The largeobject hierarchy now has the deprecated attribute, so your compiler may warn you when you use it. A lot of other things that were merely documented as deprecated now have that attribute as well.

    In other news: the documentation now describes the concept of "transaction focus." This is how libpqxx enforces rules such as "you can't issue a query on a transaction while there's a pipeline open on that transaction," or "you can't have two table streams open on one transaction at once," or "you can't issue queries on a transaction that currently has an active subtransaction."

    The errors themselves also got better: if you give your query a name or description —it's entirely optional— then an error message caused by that query can now actually mention that name. This is of no help when your code is running smoothly, but it can make debugging easier.

    I'm also dipping a toe in the water of "named constructors." Some classes, particularly stream_from and the new blob, have too many constructors. Overloading can get a bit finicky, and the differences in meaning are not always very clear.

    So for instance instead of just constructing a blob, for instance, and passing a "read-only please" argument, you do it like this:

        auto myblob = pqxx::blob::open_r(mytransaction, blob_id);
    

    And similar for read-write or write-only. There is a new named constructor for stream_from as well, though only for the "stream from query" case. For the "stream from table" case, I'm still looking at the overloading possibilities for the list of columns.

    Source code(tar.gz)
    Source code(zip)
  • 7.3.0(Dec 17, 2020)

    Sorry, no shiny new features on this one. But a lot of std::string const & parameters are now either std::string_view or (if we're passing them on to the C-level library) pqxx::zview. Depending on how exactly you call those functions, it may speed up your code by eliminating some implicit string constructions and heap buffer allocations. Also some little compile fixes, of course.

    Under the hood, though, it's a different story. I broke up the biggest inheritance hierarchy, which included almost all the major classes: the transaction classes, pipeline, streams, and so on. It is now two, much smaller, inheritance hierarchies. It rids us of the one case of virtual inheritance that the library had.

    You may hit some minor compile problems with the changed parameter types. If you built your own transaction classes, you'll have to deal with some major changes. In the longer run we're going to drop the ability to plug your own transaction types into the hierarchy, and make more things final.

    Source code(tar.gz)
    Source code(zip)
  • 7.2.1(Oct 24, 2020)

    Here's a new patch release. Changes are:

    • Fix infinite loop in converting char * to string. (#377)
    • Deprecated namedclass.
    • Convert an entire row using row::as<type...>().
    • Internal rework of field::to() and field::as() functions.
    • Some more warning options in maintainer mode.
    • Removed the old, DocBook-based tutorial.
    • Fixed wrong query and SQLSTATE params to some exceptions. (#378)

    Okay, okay, there's one nice new feature there. You can now convert an entire result row to client-side types at once. See row::as().

    Source code(tar.gz)
    Source code(zip)
  • 7.2.0(Sep 16, 2020)

    Many things have changed in this release:

    • You can now implicitly convert a const std::string & to zview.
    • Replaced some overloads for C strings and C++ strings with zview.
    • Deprecating binarystring. Use std::basic_string<std::byte> instead!
    • Array parser did not recognise escaping in unquoted values.
    • Document that string conversions assume non-null values.
    • Sketch out concepts-based PQconnectdbParams support. (#343)
    • Fixed infinite recursion when using std::optional in stream_to. (#364)
    • Catch floating-point negative overflow in check_cast, not underflow.
    • Bit more work on CMake build doc. (#318)
    • Experimental support basics for composite types. (#355)
    • Use stream_from without knowing the number of fields. (#357)
    • Global size_buffer function.
    • quote() now works for always-null types without conversions defined.
    • std::nullopt now converts to an SQL null.
    • New type trait: is_unquoted_safe.
    • Fixed mktemp invocation that broke on FreeBSD.

    For a more complete list, see the NEWS file inside the codebase. Several more bugs were fixed, and there were performance improvements as well.

    A few highlights in more detail:

    String overloads. Many overloaded functions in libpqxx take "strings" of various kinds: there's C-style strings (char const *), C++ strings (std::string), there's std::string_view, and then there's pqxx::zview — which is a string_view where the creator promises that there's a terminating zero behind it. A bunch of these functions have been simplified and now just take zview. You can now implicitly convert a string to a zview too — but be careful to keep the string alive and unchanged while you may still use the zview!

    Arrays. There was an important fix in the array parser, which previously did not support escape sequences in unquoted values. On the other hand, generating SQL arrays using to_string now makes fewer allocations, thanks to an optional new type trait.

    Binary data. Another significant change is that binarystring is now deprecated. To work with binary values such as SQL's BYTEA type, represent them on the client side using the std::byte type: represent binary values as std::basic_string<std::byte> or std::basic_string_view<std::byte>. The string conversions know about these types, so you can use from_string() and to_string() to convert these types back and forth between their C++ and SQL forms.

    Composite types. There is experimental support for SQL "composite types." You can now convert an incoming field of such types into a series of C++ values using the field's composite_to() method. Likewise there is a helper for representing a series of C++ values as an SQL composite-type object. The best way to use these is probably to write your own C++ type, and write custom string conversions for it. See datatypes.md for more about how to do this. The string conversions can call the existing libpqxx functions for convenience.

    Enjoy!

    Source code(tar.gz)
    Source code(zip)
  • 7.1.2(Jun 23, 2020)

    Lots of changes here, some important:

    • Document build in BUILDING-configure.md / BUILDING-cmake.md.
    • Work around silly clang warning in test_errorhandler.cxx.
    • Fix install error with some internal headers. (#322)
    • Fix "No object selected" error message in large objects. (#324)
    • If error has no SQLSTATE, throw broken_connection. (#280)
    • Fix argument order in encrypt_password. (#333, #334)
    • Fix underestimate of buffer size for to_string for floats. (#328)
    Source code(tar.gz)
    Source code(zip)
  • 6.4.7(Jun 23, 2020)

    By request, here's an update to the last 6.x release. It fixes a link error where, when building libpqxx as a shared library, you might not have the nullptr_t specialisation of extract_value in stream_from.

    This is in response to #340, but it may help others with compilers which don't support C++17.

    Source code(tar.gz)
    Source code(zip)
  • 7.1.1(May 18, 2020)

  • 7.1.0(May 16, 2020)

    Another big update.

    The bad news:

    • Any string_traits<TYPE>::size_buffer() must now be noexcept.
    • There's an extra data member in nullness: always_null. You'll need to implement to give your type full functionality.

    The good news: there's a new way of retrieving data from the database! It's faster, it's easier, it includes conversion to a type of your choice. Using transaction::stream, you can query rows from the database straight into a std::tuple, and so, into local variables:

    for (auto const [id, name] : tx.stream<int, std::string_view>("SELECT id, name FROM item"))
        process(id, name);
    

    And in other news...

    • stream_from now supports more or less arbitrary queries.
    • Instead of a tuple of fields, you can pass stream_to a container as well.
    • There is now to_buf support for string literals.
    • Streaming data is now more efficient.
    • The table name in stream_from is now escaped.
    • You can now "convert" strings to std::string_view. Mind your lifetimes!
    • A std::variant will now convert to string, if its member types do.
    • If a stream_from row fails to convert, you can no longer retry it.
    • from_string(field const &) now handles null values properly.
    • Obsolete Windows build docs are gone.
    • Added row::to(std::tuple<...>) — converts the whole row in one go.
    • Unified the test suites. We no longer need test/unit/unit_runner.
    • New helper: strip_t<...> to remove a type's constness and reference.
    • Replace some custom templating in CMakeFiles with CMake globs.
    Source code(tar.gz)
    Source code(zip)
  • 7.0.7(May 8, 2020)

    Here's a few improvements to both the "configure" build and the "CMake" build:

    • Fix broken --with-postgres-lib option in configure script (#311)
    • Should now build even if neither pkg-config nor pg_config is available.
    • CMake accepts PostgreSQL_ROOT, if it's a sufficiently recent version.
    Source code(tar.gz)
    Source code(zip)
  • 7.0.6(Apr 23, 2020)

    In the run-up to a 7.1 release, here's some more fixes:

    • Prefer pg_config over pkg-config for include path (#291).
    • Try to plod on if we don't know the PostgreSQL include path.
    • Fix error message when starting overlapping transactions and such (#303).
    • Fix potential crashes when converting invalid strings to floats (#307, #308).
    Source code(tar.gz)
    Source code(zip)
  • 7.0.5(Mar 12, 2020)

    Updates libpqxx with a few more small fixes:

    • Compile fix for g++ 10: include <limits> (#292).
    • Cleaned up error-checking of PG results. (#280).
    • The esc() methods now also take std::string_view (#295).
    Source code(tar.gz)
    Source code(zip)
  • 7.0.4(Feb 29, 2020)

    Another small batch of changes:

    • Fix possible crash in connection::connection_string (#290).
    • Fix filtering of default values in connection::connection_string (#288).
    • Deprecate row::swap and public inheritance of iterators from row.
    • More copy/move/default constructors/assignments on result iterators.
    • More copy/move/default constructors/assignments on row iterators.
    Source code(tar.gz)
    Source code(zip)
  • 6.4.6(Feb 26, 2020)

    This patch release fixes an important bug which could happen when reading large objects through the ilostream class. On systems where char is a signed type (which I believe includes most desktop systems), if the stream found any byte with value -1 at a buffer boundary, then it would mistake that byte for an end-of-file marker.

    A similar fix was released in libpqxx 7.0.3.

    Source code(tar.gz)
    Source code(zip)
  • 7.0.3(Feb 26, 2020)

    This new version fixes an important bug which could happen when reading large objects through the ilostream class. On systems where char is a signed type (which I believe includes most desktop systems), if the stream found any byte with value -1 at a buffer boundary, then it would mistake that byte for an end-of-file marker.

    Thanks to @tomlankhorst for finding and fixing this bug. A similar update for the 6.4 series is forthcoming.

    There are also some other fixes: large-object streams open in binary mode. Some compile errors have been fixed (though the tests may not pass) on non-Unicode systems, and in some scenarios, lost database connections are now properly reported as broken_connection exceptions instead of sql_error exceptions. Unfortunately this does not cover all scenarios, so more work will be needed.

    Source code(tar.gz)
    Source code(zip)
Owner
Jeroen Vermeulen
Jeroen Vermeulen
The PostgreSQL client API in modern C++

C++ client API to PostgreSQL {#mainpage} Dmitigr Pgfe (PostGres FrontEnd, hereinafter referred to as Pgfe) - is a C++ client API to PostgreSQL servers

Dmitry Igrishin 138 Sep 16, 2022
C++ client library for PostgreSQL

Welcome to taoPQ taoPQ is a lightweight C++ client library for accessing a PostgreSQL➚ database. It has no dependencies beyond libpq➚, the C applicati

The Art of C++ 220 Sep 6, 2022
YugabyteDB is a high-performance, cloud-native distributed SQL database that aims to support all PostgreSQL features

YugabyteDB is a high-performance, cloud-native distributed SQL database that aims to support all PostgreSQL features. It is best to fit for cloud-native OLTP (i.e. real-time, business-critical) applications that need absolute data correctness and require at least one of the following: scalability, high tolerance to failures, or globally-distributed deployments.

yugabyte 7.1k Oct 4, 2022
A PostgreSQL extension providing an async networking interface accessible via SQL using a background worker and curl.

pg_net is a PostgreSQL extension exposing a SQL interface for async networking with a focus on scalability and UX.

Supabase 49 Sep 24, 2022
A framework to monitor and improve the performance of PostgreSQL using Machine Learning methods.

pg_plan_inspector pg_plan_inspector is being developed as a framework to monitor and improve the performance of PostgreSQL using Machine Learning meth

suzuki hironobu 186 Sep 30, 2022
Prometheus exporter for PostgreSQL

pgexporter pgexporter is a Prometheus exporter for PostgreSQL. pgexporter will connect to one or more PostgreSQL instances and let you monitor their o

null 17 Sep 26, 2022
PostgreSQL extension for pgexporter

pgexporter_ext pgexporter_ext is an extension for PostgreSQL to provide additional Prometheus metrics for pgexporter. Features Disk space metrics See

null 4 Apr 13, 2022
A friendly and lightweight C++ database library for MySQL, PostgreSQL, SQLite and ODBC.

QTL QTL is a C ++ library for accessing SQL databases and currently supports MySQL, SQLite, PostgreSQL and ODBC. QTL is a lightweight library that con

null 163 Sep 6, 2022
Backup / restore solution for PostgreSQL

pgmoneta pgmoneta is a backup / restore solution for PostgreSQL. pgmoneta is named after the Roman Goddess of Memory. Features Full backup Restore Sym

null 39 Sep 27, 2022
recovery postgresql table data by update/delete/rollback/dropcolumn command

recovery postgresql table data by update/delete/rollback/dropcolumn command

RadonDB 6 Aug 4, 2022
pgagroal is a high-performance protocol-native connection pool for PostgreSQL.

pgagroal is a high-performance protocol-native connection pool for PostgreSQL.

Agroal 543 Sep 26, 2022
xxhash functions for PostgreSQL

pg_xxhash PostgreSQL ❤️ xxhash Tested with xxhash 0.8.1 and PostgreSQL 14.1 on Linux and macOS. Think twice before even considering to use it in any s

Igor Hatarist 5 Mar 11, 2022
Distributed PostgreSQL as an extension

What is Citus? Citus is a PostgreSQL extension that transforms Postgres into a distributed database—so you can achieve high performance at any scale.

Citus Data 7.4k Oct 3, 2022
High-performance time-series aggregation for PostgreSQL

PipelineDB has joined Confluent, read the blog post here. PipelineDB will not have new releases beyond 1.0.0, although critical bugs will still be fix

PipelineDB 2.5k Oct 2, 2022
Reliable PostgreSQL Backup & Restore

pgBackRest Reliable PostgreSQL Backup & Restore Introduction pgBackRest aims to be a reliable, easy-to-use backup and restore solution that can seamle

pgBackRest 1.3k Sep 28, 2022
upstream module that allows nginx to communicate directly with PostgreSQL database.

About ngx_postgres is an upstream module that allows nginx to communicate directly with PostgreSQL database. Configuration directives postgres_server

RekGRpth 1 Apr 29, 2022
Modern cryptography for PostgreSQL using libsodium.

pgsodium pgsodium is an encryption library extension for PostgreSQL using the libsodium library for high level cryptographic algorithms. pgsodium can

Michel Pelletier 343 Oct 3, 2022
Open Source Oracle Compatible PostgreSQL.

IvorySQL is advanced, fully featured, open source Oracle compatible PostgreSQL with a firm commitment to always remain 100% compatible and a Drop-in r

null 103 Sep 20, 2022
Simple-MySQL-API is a free and easy API to manipulate MySQL with C99 and GCC compiler under GNU/Linux OS.

Simple-MySQL-API is a free and easy API to manipulate MySQL with C99 and GCC compiler under GNU/Linux OS.

Neptune 8 Aug 21, 2022