Skip to content

Commit

Permalink
Merge branch 'master' into data_types
Browse files Browse the repository at this point in the history
  • Loading branch information
vadz committed Jan 2, 2024
2 parents fdfcc12 + 65a7e4d commit 07cb45e
Show file tree
Hide file tree
Showing 25 changed files with 674 additions and 84 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ jobs:
;;
esac
case "${{matrix.container}}" in
ubuntu:18.04)
# We need to use this option as GitHub certificate is not recognized by
# wget in this old container otherwise.
set_env_var SOCI_WGET_OPTIONS --no-check-certificate
;;
esac
if [ -n "${{matrix.cxxstd}}" ]; then
set_env_var SOCI_CXXSTD ${{matrix.cxxstd}}
fi
Expand Down
25 changes: 23 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
This file contains the history of changes in the SOCI library.

Latest version is v4.0.3 released on 2022-02-14.
Please read at least the following section when upgrading from
a previous version of the library.

INCOMPATIBLE CHANGES
====================

Changes in behaviour not resulting in compilation errors
--------------------------------------------------------

Changes in behaviour which may result in build errors
-----------------------------------------------------

- Temporary values cannot be passed to soci::use() any longer.
Previously this would compile but result in undefined behaviour
during run-time, but now this doesn't compile any longer. Please
create a temporary variable holding the value if necessary (#1070).


Other changes in v4.1.0:


History of the changes in the previous versions:

---
Version 4.0.3 differs from 4.0.2 in the following ways:
Version 4.0.3 (released on 2022-02-14) differs from 4.0.2 in the following ways:

Changes affecting all or multiple backends:
- Fix opening sessions from pool (#891).
Expand Down
33 changes: 19 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 14)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Path to additional CMake modules
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})

include(SociUtilities)

###############################################################################
# Build features and variants
##############################################################################
Expand Down Expand Up @@ -47,13 +53,7 @@ if (SOCI_LTO)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Check for lld as clang lto works best with its own linker
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-fuse-ld=lld" HAS_LLD)
if (HAS_LLD)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
endif()
soci_use_ld_if_supported(lld)
endif()
elseif(supported)
message(STATUS "IPO / LTO is supported but conflicts with ASAN and not enabled")
Expand Down Expand Up @@ -82,15 +82,20 @@ else()
set(SOCI_HAVE_VISIBILITY_SUPPORT off)
endif()

# Allow using alternative linker such as mold, which can be significantly
# faster than GNU ld.
option(SOCI_LD "Use non-default linker, such as 'mold'" "")
if(SOCI_LD)
# -fuse-ld works only with recent gcc (>= 12), but we don't need to support
# this with all gcc versions as this is entirely optional. I.e. if we really
# wanted to, we could use -B option as explained in mold README to make it
# work with any gcc, but for now keep the things simple.
soci_use_ld_if_supported(${SOCI_LD})
endif()

###############################################################################
# SOCI CMake modules
# SOCI configuration
###############################################################################

# Path to additional CMake modules
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})

include(SociUtilities)
include(SociConfig)

colormsg(_HIBLUE_ "Configuring SOCI:")
Expand Down
13 changes: 9 additions & 4 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,46 @@ environment:
BOOST_ROOT: C:\Libraries\boost_1_77_0
MSSQL_VER: 2019
POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\13
MYSQL_DIR: C:\Program Files\MySql\MySQL Server 5.7
MYSQL_VER: 80
MYSQL_DIR: C:\Program Files\MySql\MySQL Server 8.0
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
- G: "Visual Studio 16 2019"
BOOST_ROOT: C:\Libraries\boost_1_73_0
MSSQL_VER: 2017
POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\12
MYSQL_DIR: C:\Program Files\MySql\MySQL Server 5.7
MYSQL_VER: 80
MYSQL_DIR: C:\Program Files\MySql\MySQL Server 8.0
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
- G: "Visual Studio 15 2017 Win64"
BOOST_ROOT: C:\Libraries\boost_1_69_0
MSSQL_VER: 2016
POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\11
MYSQL_VER: 57
MYSQL_DIR: C:\Program Files\MySql\MySQL Server 5.7
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
- G: "Visual Studio 14 2015 Win64"
BOOST_ROOT: C:\Libraries\boost_1_60_0
MSSQL_VER: 2014
POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\10
MYSQL_VER: 57
MYSQL_DIR: C:\Program Files\MySql\MySQL Server 5.7
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
- G: "MinGW Makefiles"
MINGW_BIN: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
MSSQL_VER: 2014
BOOST_ROOT: C:\Libraries\boost_1_60_0
POSTGRESQL_ROOT: C:\Program Files\PostgreSQL\9.4
MYSQL_VER: 57
MYSQL_DIR: C:\Program Files\MySql\MySQL Server 5.7
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015

services:
- mysql
- postgresql

install:
# Start this one here as we can't specify the service name dynamically.
# Start these ones here as we can't specify the service name dynamically above.
- net start mssql$SQL%MSSQL_VER%
- net start mysql%MYSQL_VER%
- ps: |
Import-Module C:\projects\soci\scripts\windows\Get-ODBCList.ps1
$drivers_list = Get-ODBCList
Expand Down
12 changes: 11 additions & 1 deletion cmake/SociUtilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function (colormsg)
set(coloron FALSE)
foreach(arg ${ARGV})
if (NOT ${${arg}} STREQUAL "")
if (CMAKE_COLOR_MAKEFILE)
if (CMAKE_COLOR_DIAGNOSTICS)
set(str "${str}${_escape}[${${arg}}m")
set(coloron TRUE)
endif()
Expand Down Expand Up @@ -424,3 +424,13 @@ function(soci_target_output_name TARGET_NAME OUTPUT_NAME)

set(${OUTPUT_NAME} ${TARGET_NAME}${SUFFIX} PARENT_SCOPE)
endfunction()

# Check if the given linker is supported and use it if it is.
function(soci_use_ld_if_supported ld)
include(CheckCXXCompilerFlag)
set(ld_flag "-fuse-ld=${ld}")
check_cxx_compiler_flag(${ld_flag} can_use_ld)
if (can_use_ld)
add_link_options(${ld_flag})
endif()
endfunction()
42 changes: 6 additions & 36 deletions cmake/modules/FindMySQL.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# - Try to find MySQL / MySQL Embedded library
# - Try to find MariaDB / MySQL library
# Find the MySQL includes and client library
# This module defines
# MYSQL_INCLUDE_DIR, where to find mysql.h
# MYSQL_LIBRARIES, the libraries needed to use MySQL.
# MYSQL_LIB_DIR, path to the MYSQL_LIBRARIES
# MYSQL_EMBEDDED_LIBRARIES, the libraries needed to use MySQL Embedded.
# MYSQL_EMBEDDED_LIB_DIR, path to the MYSQL_EMBEDDED_LIBRARIES
# MYSQL_FOUND, If false, do not try to use MySQL.
# MYSQL_EMBEDDED_FOUND, If false, do not try to use MySQL Embedded.

# Copyright (c) 2006-2008, Jarosław Staniek <[email protected]>
# Copyright (c) 2023 Vadim Zeitline <[email protected]> (MariaDB support)
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
Expand All @@ -30,9 +28,8 @@ else(WIN32)
PATHS
$ENV{MYSQL_INCLUDE_DIR}
$ENV{MYSQL_DIR}/include
/usr/local/mysql/include
/opt/mysql/mysql/include
PATH_SUFFIXES
mariadb
mysql
)
endif(WIN32)
Expand Down Expand Up @@ -74,41 +71,22 @@ if(WIN32)
else(WIN32)
# find_library(MYSQL_LIBRARIES NAMES mysqlclient
set(MYSQL_LIB_PATHS
$ENV{MYSQL_DIR}/libmysql_r/.libs
$ENV{MYSQL_DIR}/lib
$ENV{MYSQL_DIR}/lib/mysql
/usr/local/mysql/lib
/opt/mysql/mysql/lib
$ENV{MYSQL_DIR}/libmysql_r/.libs
$ENV{MYSQL_DIR}/lib
$ENV{MYSQL_DIR}/lib/mysql
/usr/local/mysql/lib
/opt/mysql/mysql/lib
PATH_SUFFIXES
mariadb
mysql
)
find_library(MYSQL_LIBRARIES NAMES mysqlclient
find_library(MYSQL_LIBRARIES NAMES mariadbclient mysqlclient
PATHS
${MYSQL_LIB_PATHS}
)
endif(WIN32)

find_library(MYSQL_EMBEDDED_LIBRARIES NAMES mysqld
PATHS
${MYSQL_LIB_PATHS}
)

if(MYSQL_LIBRARIES)
get_filename_component(MYSQL_LIB_DIR ${MYSQL_LIBRARIES} PATH)
endif(MYSQL_LIBRARIES)

if(MYSQL_EMBEDDED_LIBRARIES)
get_filename_component(MYSQL_EMBEDDED_LIB_DIR ${MYSQL_EMBEDDED_LIBRARIES} PATH)
endif(MYSQL_EMBEDDED_LIBRARIES)

set( CMAKE_REQUIRED_INCLUDES ${MYSQL_INCLUDE_DIR} )
set( CMAKE_REQUIRED_LIBRARIES ${MYSQL_EMBEDDED_LIBRARIES} )
check_cxx_source_compiles( "#include <mysql.h>\nint main() { int i = MYSQL_OPT_USE_EMBEDDED_CONNECTION; }" HAVE_MYSQL_OPT_EMBEDDED_CONNECTION )

if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
set(MYSQL_FOUND TRUE)
Expand All @@ -118,12 +96,4 @@ else(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)
message(STATUS "MySQL not found.")
endif(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARIES)

if(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
set(MYSQL_EMBEDDED_FOUND TRUE)
message(STATUS "Found MySQL Embedded: ${MYSQL_INCLUDE_DIR}, ${MYSQL_EMBEDDED_LIBRARIES}")
else(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)
set(MYSQL_EMBEDDED_FOUND FALSE)
message(STATUS "MySQL Embedded not found.")
endif(MYSQL_INCLUDE_DIR AND MYSQL_EMBEDDED_LIBRARIES AND HAVE_MYSQL_OPT_EMBEDDED_CONNECTION)

mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES MYSQL_EMBEDDED_LIBRARIES)
mark_as_advanced(MYSQL_INCLUDE_DIR MYSQL_LIBRARIES)
1 change: 1 addition & 0 deletions docs/backends/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ The set of parameters used in the connection string for MySQL is:
* `connect_timeout` - should be positive integer value that means seconds corresponding to `MYSQL_OPT_CONNECT_TIMEOUT`.
* `read_timeout` - should be positive integer value that means seconds corresponding to `MYSQL_OPT_READ_TIMEOUT`.
* `write_timeout` - should be positive integer value that means seconds corresponding to `MYSQL_OPT_WRITE_TIMEOUT`.
* `ssl_mode` - should be one of the name constants `DISABLED`, `PREFERRED`, `REQUIRED`, `VERIFY_CA` or `VERIFY_IDENTITY` corresponding to `MYSQL_OPT_SSL_MODE` options.

Once you have created a `session` object as shown above, you can use it to access the database, for example:

Expand Down
16 changes: 15 additions & 1 deletion include/private/soci-mktime.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ namespace soci
namespace details
{

SOCI_DECL time_t timegm_impl_soci ( struct tm* tb );

template <typename T>
auto timegm_impl(T* t) -> decltype(timegm(t))
{
return timegm(t);
}

template <typename T>
auto timegm_impl(T t) -> time_t
{
return timegm_impl_soci(t);
}

// Fill the provided struct tm with the values corresponding to the given date
// in UTC.
//
Expand All @@ -40,7 +54,7 @@ mktime_from_ymdhms(tm& t,
t.tm_min = minute;
t.tm_sec = second;

timegm(&t);
timegm_impl(&t);
}

// Helper function for parsing datetime values.
Expand Down
4 changes: 4 additions & 0 deletions include/soci/connection-parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class SOCI_DECL connection_parameters
explicit connection_parameters(std::string const & fullConnectString);

connection_parameters(connection_parameters const& other);
connection_parameters(connection_parameters && other);
connection_parameters& operator=(connection_parameters const& other);
connection_parameters& operator=(connection_parameters && other);

~connection_parameters();

Expand Down Expand Up @@ -77,6 +79,8 @@ class SOCI_DECL connection_parameters
}

private:
void reset_after_move();

// The backend and connection string specified in our ctor.
backend_factory const * factory_;
std::string connectString_;
Expand Down
25 changes: 23 additions & 2 deletions include/soci/rowset.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class rowset_impl

typedef rowset_iterator<T> iterator;

rowset_impl()
: refs_(1), st_(nullptr), define_(nullptr)
{
}

rowset_impl(details::prepare_temp_type const & prep)
: refs_(1), st_(new statement(prep)), define_(new T())
{
Expand All @@ -135,8 +140,8 @@ class rowset_impl

iterator begin() const
{
// No ownership transfer occurs here
return iterator(*st_, *define_);
// No ownership transfer occurs here. Empty rowset doesn't have any valid begin iterator.
return st_ ? iterator(*st_, *define_) : iterator();
}

iterator end() const
Expand Down Expand Up @@ -182,6 +187,17 @@ class rowset
pimpl_->incRef();
}

rowset()
: pimpl_(new details::rowset_impl<T>())
{
}

// Due to the existence of conversion from session to prepare_temp_type, it
// would have been possible to construct a rowset from session if we didn't
// delete this ctor -- so do delete it because it doesn't make sense to
// provide such constructor.
rowset(session const& session) = delete;

~rowset()
{
pimpl_->decRef();
Expand All @@ -198,6 +214,11 @@ class rowset
return *this;
}

void clear()
{
*this = rowset();
}

const_iterator begin() const
{
return pimpl_->begin();
Expand Down
5 changes: 5 additions & 0 deletions include/soci/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class SOCI_DECL session
explicit session(std::string const & connectString);
explicit session(connection_pool & pool);

session(session &&other);
session &operator=(session &&other);

~session();

void open(connection_parameters const & parameters);
Expand Down Expand Up @@ -211,6 +214,8 @@ class SOCI_DECL session
private:
SOCI_NOT_COPYABLE(session)

void reset_after_move();

std::ostringstream query_stream_;
std::unique_ptr<details::query_transformation_function> query_transformation_;

Expand Down
Loading

0 comments on commit 07cb45e

Please sign in to comment.