SOCI - The C++ Database Access Library

Overview

SOCI - The C++ Database Access Library

GitHub release GitHub commits

Website SourceForge

Gitter Mailing Lists StackExchange

Build Status

Branches GitHub Actions AppVeyor-CI Documentation Coverity Scan
master Build Status Build status Docs Status Coverage
release/4.0 Build Status Build status Docs Status

History

Originally, SOCI was developed by Maciej Sobczak at CERN as abstraction layer for Oracle, a Simple Oracle Call Interface. Later, several database backends have been developed for SOCI, thus the long name has lost its practicality. Currently, if you like, SOCI may stand for Simple Open (Database) Call Interface or something similar.

"CERN is also a user of the SOCI library, which serves as a database access layer in some of the control system components."

-- Maciej Sobczak at Inspirel

License

SOCI library is distributed under the terms of the Boost Software License.

Requirements

Core:

  • C++ compiler
  • Boost C++ Libraries (optional, headers and Boost.DateTime)

Backend specific client libraries for:

  • DB2
  • Firebird
  • MySQL
  • ODBC with specific database driver
  • Oracle
  • PostgreSQL
  • SQLite 3

See documentation at soci.sourceforge.net for details

BSL © Maciej Sobczak and contributors.

Issues
  • Avoid exception from destructor while stack unwinding

    Avoid exception from destructor while stack unwinding

    Maciej notified me about discussion on SOCI at Linkedin C++ Professionals Group, where folks discussed that SOCI still suffers from potential of throwing from destructor while another exception is handled.

    Maciej suggested to fix it by checking std::uncaught_exception() in ref_counted_statement_base::dec_ref(), and if it returns true, the final_action() should not be called to avoid _any_ interactions with database.

    Core Category/Annoyance 
    opened by mloskot 39
  • Build failure with Oracle Instant Client 11.2.0.3.0

    Build failure with Oracle Instant Client 11.2.0.3.0

    Hello, I'm writing on behalf of the MacPorts package management system. We are trying to update our port of Oracle Instant Client from 10.2.0.4.0 to 11.2.0.3.0, but doing this causes soci to fail to build with Oracle support. I tested version 3.1.0 and 176805b886929d7f7df4f93b1eb987e6f4be0a1e from git with the same result. This is the error message:

    ld: can't link with bundle (MH_BUNDLE) only dylibs (MH_DYLIB) for architecture x86_64
    

    We get the same error when trying to build TOra 2.1.3 with Oracle support.

    Here is the full build log. I'm on OS X 10.8.2 compiling with Xcode 4.6's version of clang ("Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn)").

    Oracle 
    opened by ryandesign 30
  • Repair VC8 compile of test applications

    Repair VC8 compile of test applications

    Due to unsupported default param usage in macros and no qualified given _WIN32_WINNT version the test apps will not compile with some of Microsoft compilers. Exception Features used are only available if a minimum version is set due to conditional enabling in windows.h file (and sub required files)

    Category/Test Toolset/MSVC Toolset/MinGW 
    opened by hrabe 28
  • `soci` not found when adding as subproject

    `soci` not found when adding as subproject

    I can't seem to be able to add soci as a subproject.

    I have tried with ExternalProject_Add, and FetchContent but I can't figure out why I keep getting:

    CMake Error at src/test_app/CMakeLists.txt:21 (add_dependencies):
      The dependency target "soci" of target "test_app" does not exist.
    

    Project description

    My project structure is the following:

    └── src
        ├── CMakeLists.txt
        ├── cmake
        │   ├── soci.cmake
        │   └── spdlog.cmake
        ├── test_app
        │   └── CMakeLists.txt
        └── (...)
    

    src/CMakeLists.txt

    cmake_minimum_required(VERSION 3.11)
    
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    set(CMAKE_CXX_EXTENSIONS OFF)
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
    
    include(cmake/spdlog.cmake)
    include(cmake/soci.cmake)
    
    add_subdirectory(test_app)
    

    src/test_app/CMakeLists.txt

    cmake_minimum_required(VERSION 3.11)
    
    project(test_app LANGUAGES CXX)
    
    add_executable(test_app main.cpp)
    
    target_link_libraries(test_app PRIVATE
        spdlog
        SOCI::core
    )
    
    add_dependencies(test_app spdlog soci)
    

    spdlog.cmake

    cmake_minimum_required(VERSION 3.11)
    
    message(STATUS "Extern: spdlog v1.4.2")
    
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    set(CMAKE_CXX_EXTENSIONS OFF)
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
    
    include(FetchContent)
    
    FetchContent_Declare( spdlog
        GIT_REPOSITORY https://github.com/gabime/spdlog
        GIT_TAG v1.4.2
        GIT_SHALLOW ON
    )
    FetchContent_GetProperties(spdlog)
    if(NOT spdlog_POPULATED)
        set(SPDLOG_BUILD_EXAMPLE OFF)
        set(SPDLOG_BUILD_EXAMPLE_HO OFF)
        set(SPDLOG_BUILD_TESTS OFF)
        set(SPDLOG_BUILD_TESTS_HO OFF)
        set(SPDLOG_BUILD_BENCH OFF)
        set(SPDLOG_SANITIZE_ADDRESS OFF)
        set(SPDLOG_INSTALL ON)
        set(SPDLOG_FMT_EXTERNAL OFF)
        FetchContent_Populate(spdlog)
        add_subdirectory(
            ${spdlog_SOURCE_DIR}
            ${spdlog_BINARY_DIR}
            EXCLUDE_FROM_ALL)
    endif()
    

    soci.cmake

    cmake_minimum_required(VERSION 3.11)
    
    message(STATUS "Extern: SOCI pre4.0+git_blksail")
    
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    set(CMAKE_CXX_EXTENSIONS OFF)
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
    
    include(FetchContent)
    
    FetchContent_Declare( soci
        GIT_REPOSITORY https://github.com/SOCI/soci
        GIT_TAG master
        GIT_SHALLOW ON
    )
    FetchContent_GetProperties(soci)
    if(NOT soci_POPULATED)
        set(SOCI_STATIC ON)
        set(SOCI_SHARED ON)
        set(SOCI_TESTS OFF)
        # set(SOCI_ASAN OFF)
        set(SOCI_CXX11 ON)
        set(SOCI_LIBDIR lib)
        set(WITH_SQLITE3 ON)
        set(WITH_POSTGRESQL ON)
        set(WITH_BOOST OFF)
        set(WITH_DB2 OFF)
        set(WITH_ODBC OFF)
        set(WITH_ORACLE OFF)
        set(WITH_MYSQL OFF)
        set(SOCI_EMPTY OFF)
        FetchContent_Populate(soci)
        add_subdirectory(
            ${soci_SOURCE_DIR}
            ${soci_BINARY_DIR}
            EXCLUDE_FROM_ALL)
    endif()
    
    CMake 
    opened by msis 23
  • Replace type_ptr by shared_ptr and solve some issues

    Replace type_ptr by shared_ptr and solve some issues

    Replace type_ptr by shared_ptr that can be easily replaced by boost::shared_ptr

    Solve some issues encountered using sqlite3 backend

    Not tested with any other backend

    Core 
    opened by ArnaudD-FR 22
  • Commit odbc backend updates

    Commit odbc backend updates

    1. Fixed a bug in preparing a vector of strings for binding. The current implementation inserted an extra white character to the end of each string. This error shows up in SQL Server, not in MySQL (via ODBC).
    2. Added support for long long.
    3. Added two search paths to FindODBC.cmake.
    ODBC 
    opened by candychiu 22
  • "use" parameters additional functionality

    When developing with soci I tried to use the following:

    //tried to insert null as second parameter
    sql << "insert into test values( :int, :str )", use(1), use("",i_null); 
    

    which was not supported because use indicator was only implemented for non const scenario.

    I have also tried to call use with const char instead of std::string:

     //This was also not supported
    sql << "insert into test values( :str )", use("Hello");
    

    So I wrote some additional templates and functions in use.h to support the following cases: 1.) dbNull() function to use whenever we need to insert null value into database 2.) Support for const char* type 3.) Support for const char[N] type

    In order to enable the following scenarios I needed to modify use_container template to support some additional cases so bool isDataOwner template argument is added in order to detect whether use_container holds a referenced value or holds a copy of the value passed to use function.

    With this PR additional use scenarios are possible:

    //use const char[N] directly 
    sql << "insert into test values(:str)", use("Hello");
    
    //use const char* directly
    const char* value = "Hello";
    sql << "insert into test values(:str)", use(value);
    
    // use dbNull() instead of explicit indicator
    sql << "insert into test values(:str)", dbNull();
    // alternative to dbNull( value type is ignored in this case)
    sql << "insert into test values(:str)", use("",i_null);
    
    Core Category/Feature Status/Need-Feedback 
    opened by ravselj 21
  • Building of very first file fails with mingw

    Building of very first file fails with mingw

    With the most recent master checkout (70085e8a0a6d0d) building with mingw fails now at the very first file. Although I already got one ticket ( #338 ) about building problems with mingw, I have opened this one, because I assume this is just a minor, different, one line correction bug.

    C:\Users\klm\Downloads\soci_build>"C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\mi
    ngw32-make.exe"
    Scanning dependencies of target soci_core
    [  1%] Building CXX object src/core/CMakeFiles/soci_core.dir/backend-loader.cpp.
    obj
    C:\Users\klm\Downloads\soci\src\core\backend-loader.cpp:1:0: error: -fPIC ignore
    d for target (all code is position independent) [-Werror]
     //
     ^
    cc1plus.exe: all warnings being treated as errors
    src\core\CMakeFiles\soci_core.dir\build.make:54: recipe for target 'src/core/CMa
    keFiles/soci_core.dir/backend-loader.cpp.obj' failed
    mingw32-make[2]: *** [src/core/CMakeFiles/soci_core.dir/backend-loader.cpp.obj]
    Error 1
    CMakeFiles\Makefile2:125: recipe for target 'src/core/CMakeFiles/soci_core.dir/a
    ll' failed
    mingw32-make[1]: *** [src/core/CMakeFiles/soci_core.dir/all] Error 2
    Makefile:126: recipe for target 'all' failed
    mingw32-make: *** [all] Error 2
    
    CMake Toolset/MinGW 
    opened by Superlokkus 19
  • Issue #83 - get_affected_rows support for bulk operations

    Issue #83 - get_affected_rows support for bulk operations

    Here is the fix for the lack of info when calling statement::get_affected_rows() after bulk operations using postgresql backend. The other backends seem to already provide this info under this kind of use but I don't have the means to confirm that. The tests for get_affected_rows might confirm that.

    PostgreSQL 
    opened by ricardofandrade 19
  • Fix code writing to the database to work in any locale as well.

    Fix code writing to the database to work in any locale as well.

    This is similar to #238 but completes it by

    1. Doing the same thing in the other direction, i.e. when writing doubles to the database and not reading them.
    2. Doing the same changes in mysql and sqlite3 backends in addition to the postgresql one.
    Core Category/Annoyance 
    opened by vadz 18
  • Enable visibility for gcc and clang

    Enable visibility for gcc and clang

    Gcc and clang has support visibility just like MSVC for a long time and it trim off a lot internal symbols from the shared library and executable.

    This PR define SOCI_DECL and SOCI_<database>_DECL to __attribute__ ((visibility ("default"))) on gcc & clang and adds option SOCI_VIS (OFF by default) which set default visibility to hidden.

    On my x86-64 linux with clang-10.0.0-4ubuntu1 and lld-10.0.0, setting default visibility to hidden makes the shared libraries smaller.

    Visibility disabled, LTO enabled:

    332K    libsoci_core.so.4.0.1      
    56K     libsoci_empty.so.4.0.1     
    112K    libsoci_mysql.so.4.0.1     
    116K    libsoci_odbc.so.4.0.1      
    124K    libsoci_postgresql.so.4.0.1
    108K    libsoci_sqlite3.so.4.0.1   
    

    Visibility enabled, LTO enabled:

    324K    libsoci_core.so.4.0.1      
    52K     libsoci_empty.so.4.0.1     
    104K    libsoci_mysql.so.4.0.1     
    104K    libsoci_odbc.so.4.0.1      
    112K    libsoci_postgresql.so.4.0.1
    96K     libsoci_sqlite3.so.4.0.1   
    

    The size of statically linked applications aren't affected and this PR should have minor influence over the build time.

    opened by NobodyXu 17
  • User-defined types for non-wrapper types

    User-defined types for non-wrapper types

    My ultimate goal is to have a query of the form SELECT a, b FROM ... and then use a soci::use(container) where container is a std::vector< std::pair< std::string, std::string > >. Thus, my thinking was that if I can teach SOCI about the standard pair type, this should work.

    I am aware of http://soci.sourceforge.net/doc/release/4.0/types/#user-defined-c-types and http://soci.sourceforge.net/doc/release/4.0/types/#object-relational-mapping.

    However, I don't like the idea on depending on my columns to be required to have specific names for this to work, so the object-relational mapping seems to be ruled out.

    The example in the documentation about user-defined types unfortunately only demonstrates how to write the conversion functions for a simple wrapper type that wraps an already supported type. From this I can't seem to generalize the syntax enough to get an idea how to go about writing the conversion functions for the std::pair type (given that this is a two-to-one mapping). Could someone point me into the right direction for how something like this is supposed to be done?

    Category/Enhancement 
    opened by Krzmbrzl 5
  • Map dt_date to datetime in SQLite3's DDL API

    Map dt_date to datetime in SQLite3's DDL API

    As the datetime data type doesn't exist in SQLite3, the DDL method create_column_type() mapped dt_date to an integer type. This was possible because SQLite3 internally handles datetime values as text, real or integer. When using the soci::row API however, we want to be able to query datetime columns as std::tm instead of integers. To do this, create_column_type() must assign dt_date to a type that gets mapped back to dt_date in get_data_type_map() in sqlite3/statement.cpp. The most generic one in this case is datetime.

    Fixes #969

    SQLite 
    opened by zann1x 2
  • Sqlite3 dt_date usage

    Sqlite3 dt_date usage

    Creating a table using the generic code

    soci::ddl_type ddl = db.create_table(name);
    ddl.column("TIMESTAMP", soci::dt_date)("not null");
    

    a new table is created with the column type INTEGER instead of the expected type "DATE".

    When querying data from this column the following code an std::bad_cast error is thrown:

    std::tm timestamp;
    statement st = (db.prepare << "select TIMESTAMP from name, into(timestamp));
    st.execute();
    

    This might be due to this part of code: https://github.com/SOCI/soci/blob/master/include/soci/sqlite3/soci-sqlite3.h#L319 I would expect for "dt_date" a mapping to "date" or something similar.

    The corresponding std::tm test for sqlite3 succeeds, because it is not using ddl_type but rather a direct sql command for creating the table: https://github.com/SOCI/soci/blob/master/tests/sqlite3/test-sqlite3.cpp#L379

    opened by mmaurus 0
  • Improve FindSoci.cmake

    Improve FindSoci.cmake

    The new version uses consistent spelling that matches the name of then module file (Soci instead of SOCI). In addition it delegates the handling of individual components to the standard cmake function and adds support for querying the SOCI version (from the version.h header file).

    CMake 
    opened by Krzmbrzl 18
  • Blob and copy/move constructor

    Blob and copy/move constructor

    Blob has no explicit copy/move constructor but a destructor which calls delete. So making a copy/move can result in double free or use after free. example:

      soci::session sql (soci::sqlite3, databaseName);
      auto originalBlob = soci::blob{ sql };
      auto copyBlob = originalBlob;
    
    AddressSanitizer:DEADLYSIGNAL
    =================================================================
    ==46681==ERROR: AddressSanitizer: SEGV on unknown address 0x00000700000a (pc 0x55f275330f88 bp 0x7fff806d8ef0 sp 0x7fff806d8ee0 T0)
    ==46681==The signal is caused by a READ memory access.
        #0 0x55f275330f88 in soci::blob::~blob() /home/walde/.conan/data/soci/4.0.2/werto87/stable/build/7ef31e0413043c7eb48a64bb0d0adb2c77e9639e/source_subfolder/src/core/blob.cpp:23:5
        #1 0x55f2752e611f in main /home/walde/projects/sandbox/cxx_template/main.cxx:129:1
        #2 0x14f42d6f030f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)
        #3 0x14f42d6f03c0 in __libc_start_main_impl (/usr/lib/libc.so.6+0x2d3c0)
        #4 0x55f2751fdd14 in _start (/home/walde/projects/sandbox/cxx_template/build/bin/project+0x32d14)
    
    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: SEGV /home/walde/.conan/data/soci/4.0.2/werto87/stable/build/7ef31e0413043c7eb48a64bb0d0adb2c77e9639e/source_subfolder/src/core/blob.cpp:23:5 in soci::blob::~blob()
    ==46681==ABORTING
    

    Possible solution: remove destructor of blob and replace "details::blob_backend * backEnd_;" with std::unique_ptr < details::blob_backend > backEnd_;

    Problem: This is api breaking

    opened by werto87 0
MySQL Server, the world's most popular open source database, and MySQL Cluster, a real-time, open source transactional database.

Copyright (c) 2000, 2021, Oracle and/or its affiliates. This is a release of MySQL, an SQL database server. License information can be found in the

MySQL 8k Jul 4, 2022
A mini database for learning database

A mini database for learning database

Chuckie Tan 3 Nov 3, 2021
Tntdb is a c++-class-library for easy access to databases

Tntdb is a c++-class-library for easy access to databases

Tommi Mäkitalo 30 Jan 23, 2022
SpDB is a data integration tool designed to organize scientific data from different sources under the same namespace according to a global schema and to provide access to them in a unified form (views)

SpDB is a data integration tool designed to organize scientific data from different sources under the same namespace according to a global schema and to provide access to them in a unified form (views). Its main purpose is to provide a unified data access interface for complex scientific computations in order to enable the interaction and integration between different programs and databases.

YU Zhi 0 Jun 22, 2022
A hook for Project Zomboid that intercepts files access for savegames and puts them in an SQLite DB instead.

ZomboidDB This project consists of a library and patcher that results in file calls for your savegame(s) being transparently intercepted and redirecte

Oliver 6 May 6, 2022
Velox is a new C++ vectorized database acceleration library aimed to optimizing query engines and data processing systems.

Velox is a C++ database acceleration library which provides reusable, extensible, and high-performance data processing components

Facebook Incubator 893 Jun 27, 2022
The fastest database-library on Android OS.

Android SQLite3 NDK 封装 Demo下载 (操作:按钮新增 按钮查询 点按编辑 长按删除) 写在前面 sqlite3 开源、集成简单(现在的版本只有2个文件 sqlite3.h sqlite3.c) 这个库抽离自 Telegram 的开源代码、作者:DrKLO 我个人感觉 Tele

水银灯、 2 Dec 27, 2021
C++11 wrapper for the LMDB embedded B+ tree database library.

lmdb++: a C++11 wrapper for LMDB This is a comprehensive C++ wrapper for the LMDB embedded database library, offering both an error-checked procedural

D.R.Y. C++ 257 Jun 16, 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 155 Jun 26, 2022
Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.

Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.

GitHub 248 Jun 11, 2022
dqlite is a C library that implements an embeddable and replicated SQL database engine with high-availability and automatic failover

dqlite dqlite is a C library that implements an embeddable and replicated SQL database engine with high-availability and automatic failover. The acron

Canonical 3k Jun 27, 2022
Nebula Graph is a distributed, fast open-source graph database featuring horizontal scalability and high availability

Nebula Graph is an open-source graph database capable of hosting super large scale graphs with dozens of billions of vertices (nodes) and trillions of edges, with milliseconds of latency.

vesoft inc. 807 Jun 30, 2022
DuckDB is an in-process SQL OLAP Database Management System

DuckDB is an in-process SQL OLAP Database Management System

DuckDB 5.4k Jun 27, 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 6.6k Jul 1, 2022
TimescaleDB is an open-source database designed to make SQL scalable for time-series data.

An open-source time-series SQL database optimized for fast ingest and complex queries. Packaged as a PostgreSQL extension.

Timescale 13.3k Jun 27, 2022
Beryl-cli is a client for the BerylDB database server

Beryl-cli is a client for the BerylDB database server. It offers multiple commands and is designed to be fast and user-friendly.

BerylDB 11 Apr 21, 2022
PolarDB for PostgreSQL (PolarDB for short) is an open source database system based on PostgreSQL.

PolarDB for PostgreSQL (PolarDB for short) is an open source database system based on PostgreSQL. It extends PostgreSQL to become a share-nothing distributed database, which supports global data consistency and ACID across database nodes, distributed SQL processing, and data redundancy and high availability through Paxos based replication. PolarDB is designed to add values and new features to PostgreSQL in dimensions of high performance, scalability, high availability, and elasticity. At the same time, PolarDB remains SQL compatibility to single-node PostgreSQL with best effort.

Alibaba 2.3k Jun 30, 2022
A MariaDB-based command line tool to connect to OceanBase Database.

什么是 OceanBase Client OceanBase Client(简称 OBClient) 是一个基于 MariaDB 开发的客户端工具。您可以使用 OBClient 访问 OceanBase 数据库的集群。OBClient 采用 GPL 协议。 OBClient 依赖 libobclie

OceanBase 47 Mar 16, 2022
A proxy server for OceanBase Database.

OceanBase Database Proxy TODO: some badges here OceanBase Database Proxy (ODP for short) is a dedicated proxy server for OceanBase Database. OceanBase

OceanBase 76 Apr 6, 2022