mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 16:50:48 +00:00
dbms: Server: merged from master [#METR-19266]
This commit is contained in:
commit
924402f33e
2
.vimrc
Normal file
2
.vimrc
Normal file
@ -0,0 +1,2 @@
|
||||
au BufRead,BufNewFile ./* set ts=4 sw=4 noexpandtab tags=tags,../tags
|
||||
|
@ -26,7 +26,11 @@ IF(NOT CMAKE_BUILD_TYPE)
|
||||
ENDIF()
|
||||
MESSAGE( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} )
|
||||
|
||||
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo;Debug;Release;MinSizeRel" CACHE STRING "" FORCE)
|
||||
# ASan - build type with address sanitizer
|
||||
# UBSan - build type with undefined behaviour sanitizer
|
||||
# TSan is not supported due to false positive errors in libstdc++ and necessity to rebuild libstdc++ with TSan
|
||||
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo;Debug;Release;MinSizeRel;ASan;UBSan" CACHE STRING "" FORCE)
|
||||
|
||||
|
||||
IF (CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*)")
|
||||
SET(AARCH64 1)
|
||||
@ -37,6 +41,7 @@ IF (NOT AARCH64)
|
||||
ENDIF()
|
||||
|
||||
SET(COMMON_WARNING_FLAGS "-Wall -Werror")
|
||||
SET(CXX_WARNING_FLAGS "-Wnon-virtual-dtor -Wold-style-cast")
|
||||
|
||||
|
||||
set (GLIBC_COMPATIBILITY FALSE CACHE BOOL "Set to TRUE to enable compatibility with older glibc libraries")
|
||||
@ -50,23 +55,31 @@ if (GLIBC_COMPATIBILITY)
|
||||
SET(GLIBC_COMPATIBILITY_LINK_FLAGS "-Wl,--wrap=memcpy")
|
||||
endif()
|
||||
|
||||
if (DISABLE_CXX11_ABI)
|
||||
SET(CXX11_ABI "-D_GLIBCXX_USE_CXX11_ABI=0")
|
||||
endif()
|
||||
|
||||
SET(CMAKE_BUILD_COLOR_MAKEFILE ON)
|
||||
SET(CMAKE_CXX_FLAGS "-std=gnu++1y ${COMMON_WARNING_FLAGS} -Wnon-virtual-dtor ${MACHINE_FLAGS} ${GLIBC_COMPATIBILITY_COMPILE_FLAGS}")
|
||||
SET(CMAKE_CXX_FLAGS "-std=gnu++1y -fno-omit-frame-pointer ${COMMON_WARNING_FLAGS} ${CXX_WARNING_FLAGS} ${MACHINE_FLAGS} ${GLIBC_COMPATIBILITY_COMPILE_FLAGS} ${CXX11_ABI}")
|
||||
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
|
||||
SET(CMAKE_C_FLAGS "${COMMON_WARNING_FLAGS} ${MACHINE_FLAGS} ${GLIBC_COMPATIBILITY_COMPILE_FLAGS}")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
|
||||
|
||||
SET(CMAKE_C_FLAGS "-fno-omit-frame-pointer ${COMMON_WARNING_FLAGS} ${MACHINE_FLAGS} ${GLIBC_COMPATIBILITY_COMPILE_FLAGS} ${CXX11_ABI}")
|
||||
SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
|
||||
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ ${GLIBC_COMPATIBILITY_LINK_FLAGS}")
|
||||
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
|
||||
|
||||
# cmake -DCMAKE_BUILD_TYPE=Debug ..
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ ${GLIBC_COMPATIBILITY_LINK_FLAGS} ${CXX11_ABI}")
|
||||
|
||||
SET(CMAKE_CXX_FLAGS_ASAN "-O3 -g -fsanitize=address -fno-omit-frame-pointer ${CXX11_ABI}")
|
||||
SET(CMAKE_CXX_FLAGS_UBSAN "-O3 -g -fsanitize=undefined -fno-omit-frame-pointer ${CXX11_ABI}")
|
||||
SET(CMAKE_C_FLAGS_ASAN "-O3 -g -fsanitize=address -fno-omit-frame-pointer ${CXX11_ABI}")
|
||||
SET(CMAKE_C_FLAGS_UBSAN "-O3 -g -fsanitize=undefined -fno-omit-frame-pointer ${CXX11_ABI}")
|
||||
|
||||
# Флаги для test coverage
|
||||
SET(TEST_COVERAGE TRUE CACHE BOOL "Add compliler flags for test coverage")
|
||||
IF (TEST_COVERAGE)
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fprofile-arcs -ftest-coverage -fPIC -DIS_DEBUG")
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -fprofile-arcs -ftest-coverage -fPIC -DIS_DEBUG ${CXX11_ABI}")
|
||||
ENDIF(TEST_COVERAGE)
|
||||
|
||||
# Собирать тесты?
|
||||
|
2
contrib/CMakeLists.txt
vendored
2
contrib/CMakeLists.txt
vendored
@ -1,3 +1,5 @@
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-old-style-cast")
|
||||
|
||||
add_subdirectory (libcityhash)
|
||||
add_subdirectory (liblz4)
|
||||
add_subdirectory (libdouble-conversion)
|
||||
|
@ -1,6 +1,8 @@
|
||||
/* libdivide.h
|
||||
Copyright 2010 ridiculous_fish
|
||||
*/
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wold-style-cast"
|
||||
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#define LIBDIVIDE_WINDOWS 1
|
||||
@ -1340,3 +1342,5 @@ __m128i operator/(__m128i numer, const divider<int_type, ALGO> & denom) {
|
||||
} //close namespace libdivide
|
||||
} //close anonymous namespace
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
|
@ -78,7 +78,7 @@ option(ENABLE_NETSSL "Enable NetSSL" ON)
|
||||
option(ENABLE_NETSSL_WIN "Enable NetSSL Windows" OFF)
|
||||
option(ENABLE_CRYPTO "Enable Crypto" ON)
|
||||
option(ENABLE_DATA "Enable Data" ON)
|
||||
option(ENABLE_DATA_SQLITE "Enable Data SQlite" ON)
|
||||
option(ENABLE_DATA_SQLITE "Enable Data SQlite" OFF)
|
||||
option(ENABLE_DATA_MYSQL "Enable Data MySQL" ON)
|
||||
option(ENABLE_DATA_ODBC "Enable Data ODBC" ON)
|
||||
option(ENABLE_SEVENZIP "Enable SevenZip" OFF)
|
||||
|
@ -28,11 +28,6 @@ set_target_properties( "${LIBNAME}"
|
||||
|
||||
target_link_libraries( "${LIBNAME}" PocoFoundation)
|
||||
|
||||
if(ENABLE_DATA_SQLITE)
|
||||
# SQlite3 is built in any case
|
||||
add_subdirectory( SQLite )
|
||||
endif(ENABLE_DATA_SQLITE)
|
||||
|
||||
if(ENABLE_DATA_MYSQL)
|
||||
find_package(MySQL)
|
||||
if(MYSQL_FOUND)
|
||||
|
@ -357,7 +357,7 @@ inline SQLINTEGER stringLength(SQLPOINTER pValue, SQLINTEGER length)
|
||||
{
|
||||
if (SQL_NTS != length) return length;
|
||||
|
||||
return (SQLINTEGER) std::strlen((const char*) pValue);
|
||||
return static_cast<SQLINTEGER>(std::strlen(static_cast<const char*>(pValue)));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,50 +0,0 @@
|
||||
set(LIBNAME "PocoDataSQLite")
|
||||
set(POCO_LIBNAME "${LIBNAME}")
|
||||
|
||||
# Sources
|
||||
file(GLOB SRCS_G "src/*.cpp")
|
||||
POCO_SOURCES_AUTO( SQLITE_SRCS ${SRCS_G})
|
||||
|
||||
# Headers
|
||||
file(GLOB_RECURSE HDRS_G "include/*.h" )
|
||||
POCO_HEADERS_AUTO( SQLITE_SRCS ${HDRS_G})
|
||||
|
||||
if (POCO_UNBUNDLED)
|
||||
find_package(SQLite3)
|
||||
set(DATASQLITELIBS ${SQLITE3_LIBRARIES})
|
||||
include_directories("${SQLITE3_INCLUDE_DIRS}")
|
||||
else()
|
||||
# sqlite3
|
||||
POCO_SOURCES( SQLITE_SRCS sqlite3
|
||||
src/sqlite3.c
|
||||
)
|
||||
|
||||
POCO_HEADERS( SQLITE_SRCS sqlite3
|
||||
src/sqlite3.h
|
||||
)
|
||||
|
||||
set(DATASQLITELIBS "")
|
||||
endif()
|
||||
|
||||
if(WINCE)
|
||||
add_definitions(-DSQLITE_MSVC_LOCALTIME_API)
|
||||
endif(WINCE)
|
||||
|
||||
add_definitions(-DSQLITE_THREADSAFE=1 -DSQLITE_DISABLE_LFS -DSQLITE_OMIT_UTF16 -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_COMPLETE -DSQLITE_OMIT_TCL_VARIABLE -DSQLITE_OMIT_DEPRECATED)
|
||||
|
||||
include_directories(src)
|
||||
|
||||
add_library( "${LIBNAME}" ${LIB_MODE} ${SQLITE_SRCS} )
|
||||
set_target_properties( "${LIBNAME}"
|
||||
PROPERTIES
|
||||
VERSION ${SHARED_LIBRARY_VERSION} SOVERSION ${SHARED_LIBRARY_VERSION}
|
||||
OUTPUT_NAME ${POCO_LIBNAME}
|
||||
DEFINE_SYMBOL SQLite_EXPORTS
|
||||
)
|
||||
|
||||
target_link_libraries( "${LIBNAME}" PocoFoundation PocoData ${DATASQLITELIBS} )
|
||||
|
||||
if (ENABLE_TESTS)
|
||||
add_subdirectory(testsuite)
|
||||
endif ()
|
||||
|
@ -1,4 +0,0 @@
|
||||
include(CMakeFindDependencyMacro)
|
||||
find_dependency(PocoFoundation)
|
||||
find_dependency(PocoData)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/PocoDataSQLiteTargets.cmake")
|
@ -1,222 +0,0 @@
|
||||
//
|
||||
// Binder.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Binder.h#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Binder
|
||||
//
|
||||
// Definition of the Binder class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_Binder_INCLUDED
|
||||
#define Data_SQLite_Binder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/AbstractBinder.h"
|
||||
#include "Poco/Data/LOB.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "sqlite3.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Binder: public Poco::Data::AbstractBinder
|
||||
/// Binds placeholders in the sql query to the provided values. Performs data types mapping.
|
||||
{
|
||||
public:
|
||||
Binder(sqlite3_stmt* pStmt);
|
||||
/// Creates the Binder.
|
||||
|
||||
~Binder();
|
||||
/// Destroys the Binder.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int8 &val, Direction dir);
|
||||
/// Binds an Int8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt8 &val, Direction dir);
|
||||
/// Binds an UInt8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int16 &val, Direction dir);
|
||||
/// Binds an Int16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt16 &val, Direction dir);
|
||||
/// Binds an UInt16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int32 &val, Direction dir);
|
||||
/// Binds an Int32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt32 &val, Direction dir);
|
||||
/// Binds an UInt32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int64 &val, Direction dir);
|
||||
/// Binds an Int64.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt64 &val, Direction dir);
|
||||
/// Binds an UInt64.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
void bind(std::size_t pos, const long &val, Direction dir);
|
||||
/// Binds a long
|
||||
|
||||
void bind(std::size_t pos, const unsigned long &val, Direction dir);
|
||||
/// Binds an unsigned long
|
||||
#endif
|
||||
|
||||
void bind(std::size_t pos, const bool &val, Direction dir);
|
||||
/// Binds a boolean.
|
||||
|
||||
void bind(std::size_t pos, const float &val, Direction dir);
|
||||
/// Binds a float.
|
||||
|
||||
void bind(std::size_t pos, const double &val, Direction dir);
|
||||
/// Binds a double.
|
||||
|
||||
void bind(std::size_t pos, const char &val, Direction dir);
|
||||
/// Binds a single character.
|
||||
|
||||
void bind(std::size_t pos, const char* const &pVal, Direction dir);
|
||||
/// Binds a const char ptr.
|
||||
|
||||
void bind(std::size_t pos, const std::string& val, Direction dir);
|
||||
/// Binds a string.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir);
|
||||
/// Binds a BLOB.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Data::CLOB& val, Direction dir);
|
||||
/// Binds a CLOB.
|
||||
|
||||
void bind(std::size_t pos, const Date& val, Direction dir);
|
||||
/// Binds a Date.
|
||||
|
||||
void bind(std::size_t pos, const Time& val, Direction dir);
|
||||
/// Binds a Time.
|
||||
|
||||
void bind(std::size_t pos, const DateTime& val, Direction dir);
|
||||
/// Binds a DateTime.
|
||||
|
||||
void bind(std::size_t pos, const NullData& val, Direction dir);
|
||||
/// Binds a null.
|
||||
|
||||
private:
|
||||
void checkReturn(int rc);
|
||||
/// Checks the SQLite return code and throws an appropriate exception
|
||||
/// if error has occurred.
|
||||
|
||||
template <typename T>
|
||||
void bindLOB(std::size_t pos, const Poco::Data::LOB<T>& val, Direction dir)
|
||||
{
|
||||
// convert a blob to a an unsigned char* array
|
||||
const T* pData = reinterpret_cast<const T*>(val.rawContent());
|
||||
int valSize = static_cast<int>(val.size());
|
||||
|
||||
int rc = sqlite3_bind_blob(_pStmt, static_cast<int>(pos), pData, valSize, SQLITE_STATIC); // no deep copy, do not free memory
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
sqlite3_stmt* _pStmt;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int8 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt8 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int16 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt16 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt32 &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = static_cast<Poco::Int32>(val);
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt64 &val, Direction dir)
|
||||
{
|
||||
Poco::Int64 tmp = static_cast<Poco::Int64>(val);
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const bool &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = (val ? 1 : 0);
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const float &val, Direction dir)
|
||||
{
|
||||
double tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const char &val, Direction dir)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const char* const &pVal, Direction dir)
|
||||
{
|
||||
std::string val(pVal);
|
||||
bind(pos, val, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val, Direction dir)
|
||||
{
|
||||
bindLOB<Poco::Data::BLOB::ValueType>(pos, val, dir);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Data::CLOB& val, Direction dir)
|
||||
{
|
||||
bindLOB<Poco::Data::CLOB::ValueType>(pos, val, dir);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // Data_SQLite_Binder_INCLUDED
|
@ -1,145 +0,0 @@
|
||||
//
|
||||
// Connector.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Connector.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Connector
|
||||
//
|
||||
// Definition of the Connector class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_Connector_INCLUDED
|
||||
#define Data_SQLite_Connector_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/Connector.h"
|
||||
|
||||
|
||||
// Note: to avoid static (de)initialization problems,
|
||||
// during connector automatic (un)registration, it is
|
||||
// best to have this as a macro.
|
||||
#define POCO_DATA_SQLITE_CONNECTOR_NAME "sqlite"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Connector: public Poco::Data::Connector
|
||||
/// Connector instantiates SqLite SessionImpl objects.
|
||||
{
|
||||
public:
|
||||
static const std::string KEY;
|
||||
/// Keyword for creating SQLite sessions ("SQLite").
|
||||
|
||||
Connector();
|
||||
/// Creates the Connector.
|
||||
|
||||
~Connector();
|
||||
/// Destroys the Connector.
|
||||
|
||||
const std::string& name() const;
|
||||
/// Returns the name associated with this connector.
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> createSession(const std::string& connectionString,
|
||||
std::size_t timeout = Poco::Data::SessionImpl::LOGIN_TIMEOUT_DEFAULT);
|
||||
/// Creates a SQLite SessionImpl object and initializes it with the given connectionString.
|
||||
|
||||
static void registerConnector();
|
||||
/// Registers the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory.
|
||||
|
||||
static void unregisterConnector();
|
||||
/// Unregisters the Connector under the Keyword Connector::KEY at the Poco::Data::SessionFactory.
|
||||
|
||||
static void enableSharedCache(bool flag = true);
|
||||
/// Enables or disables SQlite shared cache mode
|
||||
/// (see http://www.sqlite.org/sharedcache.html for a discussion).
|
||||
|
||||
static void enableSoftHeapLimit(int limit);
|
||||
/// Sets a soft upper limit to the amount of memory allocated
|
||||
/// by SQLite. For more information, please see the SQLite
|
||||
/// sqlite_soft_heap_limit() function (http://www.sqlite.org/c3ref/soft_heap_limit.html).
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline const std::string& Connector::name() const
|
||||
{
|
||||
static const std::string n(POCO_DATA_SQLITE_CONNECTOR_NAME);
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
//
|
||||
// Automatic Connector registration
|
||||
//
|
||||
|
||||
struct SQLite_API SQLiteConnectorRegistrator
|
||||
/// Connector registering class.
|
||||
/// A global instance of this class is instantiated
|
||||
/// with sole purpose to automatically register the
|
||||
/// SQLite connector with central Poco Data registry.
|
||||
{
|
||||
SQLiteConnectorRegistrator()
|
||||
/// Calls Poco::Data::SQLite::registerConnector();
|
||||
{
|
||||
Poco::Data::SQLite::Connector::registerConnector();
|
||||
}
|
||||
|
||||
~SQLiteConnectorRegistrator()
|
||||
/// Calls Poco::Data::SQLite::unregisterConnector();
|
||||
{
|
||||
try
|
||||
{
|
||||
Poco::Data::SQLite::Connector::unregisterConnector();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIB_INIT)
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS) && !defined(__GNUC__)
|
||||
extern "C" const struct SQLite_API SQLiteConnectorRegistrator pocoSQLiteConnectorRegistrator;
|
||||
#if defined(SQLite_EXPORTS)
|
||||
#if defined(_WIN64) || defined(_WIN32_WCE)
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:"#s))
|
||||
#elif defined(_WIN32)
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/export:_"#s))
|
||||
#endif
|
||||
#else // !SQLite_EXPORTS
|
||||
#if defined(_WIN64) || defined(_WIN32_WCE)
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:"#s))
|
||||
#elif defined(_WIN32)
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) __pragma(comment (linker, "/include:_"#s))
|
||||
#endif
|
||||
#endif // SQLite_EXPORTS
|
||||
#else // !POCO_OS_FAMILY_WINDOWS
|
||||
#define POCO_DATA_SQLITE_FORCE_SYMBOL(s) extern "C" const struct SQLiteConnectorRegistrator s;
|
||||
#endif // POCO_OS_FAMILY_WINDOWS
|
||||
POCO_DATA_SQLITE_FORCE_SYMBOL(pocoSQLiteConnectorRegistrator)
|
||||
#endif // POCO_NO_AUTOMATIC_LIB_INIT
|
||||
|
||||
//
|
||||
// End automatic Connector registration
|
||||
//
|
||||
|
||||
#endif // Data_SQLite_Connector_INCLUDED
|
@ -1,315 +0,0 @@
|
||||
//
|
||||
// Extractor.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Extractor.h#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Extractor
|
||||
//
|
||||
// Definition of the Extractor class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_Extractor_INCLUDED
|
||||
#define Data_SQLite_Extractor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/AbstractExtractor.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/Data/Constants.h"
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/Data/Time.h"
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/Data/Time.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/DynamicAny.h"
|
||||
#include "sqlite3.h"
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Extractor: public Poco::Data::AbstractExtractor
|
||||
/// Extracts and converts data values form the result row returned by SQLite.
|
||||
/// If NULL is received, the incoming val value is not changed and false is returned
|
||||
{
|
||||
public:
|
||||
typedef std::vector<std::pair<bool, bool> > NullIndVec;
|
||||
/// Type for null indicators container.
|
||||
|
||||
Extractor(sqlite3_stmt* pStmt);
|
||||
/// Creates the Extractor.
|
||||
|
||||
~Extractor();
|
||||
/// Destroys the Extractor.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int8& val);
|
||||
/// Extracts an Int8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt8& val);
|
||||
/// Extracts an UInt8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int16& val);
|
||||
/// Extracts an Int16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt16& val);
|
||||
/// Extracts an UInt16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int32& val);
|
||||
/// Extracts an Int32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt32& val);
|
||||
/// Extracts an UInt32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int64& val);
|
||||
/// Extracts an Int64.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt64& val);
|
||||
/// Extracts an UInt64.
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
bool extract(std::size_t pos, long& val);
|
||||
/// Extracts a long.
|
||||
|
||||
bool extract(std::size_t pos, unsigned long& val);
|
||||
/// Extracts an unsigned long.
|
||||
#endif
|
||||
|
||||
bool extract(std::size_t pos, bool& val);
|
||||
/// Extracts a boolean.
|
||||
|
||||
bool extract(std::size_t pos, float& val);
|
||||
/// Extracts a float.
|
||||
|
||||
bool extract(std::size_t pos, double& val);
|
||||
/// Extracts a double.
|
||||
|
||||
bool extract(std::size_t pos, char& val);
|
||||
/// Extracts a single character.
|
||||
|
||||
bool extract(std::size_t pos, std::string& val);
|
||||
/// Extracts a string.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Data::BLOB& val);
|
||||
/// Extracts a BLOB.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Data::CLOB& val);
|
||||
/// Extracts a CLOB.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Data::Date& val);
|
||||
/// Extracts a Date.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Data::Time& val);
|
||||
/// Extracts a Time.
|
||||
|
||||
bool extract(std::size_t pos, Poco::DateTime& val);
|
||||
/// Extracts a DateTime.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Any& val);
|
||||
/// Extracts an Any.
|
||||
|
||||
bool extract(std::size_t pos, Poco::DynamicAny& val);
|
||||
/// Extracts a DynamicAny.
|
||||
|
||||
bool isNull(std::size_t pos, std::size_t row = POCO_DATA_INVALID_ROW);
|
||||
/// Returns true if the current row value at pos column is null.
|
||||
/// Because of the loss of information about null-ness of the
|
||||
/// underlying database values due to the nature of SQLite engine,
|
||||
/// (once null value is converted to default value, SQLite API
|
||||
/// treats it as non-null), a null indicator container member
|
||||
/// variable is used to cache the indicators of the underlying nulls
|
||||
/// thus rendering this function idempotent.
|
||||
/// The container is a vector of [bool, bool] pairs.
|
||||
/// The vector index corresponds to the column position, the first
|
||||
/// bool value in the pair is true if the null indicator has
|
||||
/// been set and the second bool value in the pair is true if
|
||||
/// the column is actually null.
|
||||
/// The row argument, needed for connectors with bulk capabilities,
|
||||
/// is ignored in this implementation.
|
||||
|
||||
void reset();
|
||||
/// Clears the cached nulls indicator vector.
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
bool extractImpl(std::size_t pos, T& val)
|
||||
/// Utility function for extraction of Any and DynamicAny.
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
|
||||
bool ret = false;
|
||||
|
||||
switch (Utility::getColumnType(_pStmt, pos))
|
||||
{
|
||||
case MetaColumn::FDT_BOOL:
|
||||
{
|
||||
bool i = false;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT8:
|
||||
{
|
||||
Poco::Int8 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT8:
|
||||
{
|
||||
Poco::UInt8 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT16:
|
||||
{
|
||||
Poco::Int16 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT16:
|
||||
{
|
||||
Poco::UInt16 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT32:
|
||||
{
|
||||
Poco::Int32 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT32:
|
||||
{
|
||||
Poco::UInt32 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT64:
|
||||
{
|
||||
Poco::Int64 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT64:
|
||||
{
|
||||
Poco::UInt64 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_STRING:
|
||||
{
|
||||
std::string s;
|
||||
ret = extract(pos, s);
|
||||
val = s;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_DOUBLE:
|
||||
{
|
||||
double d(0.0);
|
||||
ret = extract(pos, d);
|
||||
val = d;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_FLOAT:
|
||||
{
|
||||
float f(0.0);
|
||||
ret = extract(pos, f);
|
||||
val = f;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_BLOB:
|
||||
{
|
||||
BLOB b;
|
||||
ret = extract(pos, b);
|
||||
val = b;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_DATE:
|
||||
{
|
||||
Date d;
|
||||
ret = extract(pos, d);
|
||||
val = d;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_TIME:
|
||||
{
|
||||
Time t;
|
||||
ret = extract(pos, t);
|
||||
val = t;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_TIMESTAMP:
|
||||
{
|
||||
DateTime dt;
|
||||
ret = extract(pos, dt);
|
||||
val = dt;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw Poco::Data::UnknownTypeException("Unknown type during extraction");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool extractLOB(std::size_t pos, Poco::Data::LOB<T>& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
int size = sqlite3_column_bytes(_pStmt, (int) pos);
|
||||
const T* pTmp = reinterpret_cast<const T*>(sqlite3_column_blob(_pStmt, (int) pos));
|
||||
val = Poco::Data::LOB<T>(pTmp, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
sqlite3_stmt* _pStmt;
|
||||
NullIndVec _nulls;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline void Extractor::reset()
|
||||
{
|
||||
_nulls.clear();
|
||||
}
|
||||
|
||||
|
||||
inline bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& val)
|
||||
{
|
||||
return extractLOB<Poco::Data::BLOB::ValueType>(pos, val);
|
||||
}
|
||||
|
||||
|
||||
inline bool Extractor::extract(std::size_t pos, Poco::Data::CLOB& val)
|
||||
{
|
||||
return extractLOB<Poco::Data::CLOB::ValueType>(pos, val);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // Data_SQLite_Extractor_INCLUDED
|
@ -1,197 +0,0 @@
|
||||
//
|
||||
// Notifier.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Notifier.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Notifier
|
||||
//
|
||||
// Definition of Notifier.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_Notifier_INCLUDED
|
||||
#define SQLite_Notifier_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Types.h"
|
||||
#include "Poco/Dynamic/Var.h"
|
||||
#include "Poco/BasicEvent.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Notifier
|
||||
/// Notifier is a wrapper for SQLite callback calls. It supports event callbacks
|
||||
/// for insert, update, delete, commit and rollback events. While (un)registering
|
||||
/// callbacks is thread-safe, execution of the callbacks themselves are not;
|
||||
/// it is the user's responsibility to ensure the thread-safey of the functions
|
||||
/// they provide as callback target. Additionally, commit callbacks may prevent
|
||||
/// database transactions from succeeding (see sqliteCommitCallbackFn documentation
|
||||
/// for details).
|
||||
///
|
||||
/// There can be only one set of callbacks per session (i.e. registering a new
|
||||
/// callback automatically unregisters the previous one). All callbacks are
|
||||
/// registered and enabled at Notifier contruction time and can be disabled
|
||||
/// at a later point time.
|
||||
{
|
||||
public:
|
||||
typedef unsigned char EnabledEventType;
|
||||
/// A type definition for events-enabled bitmap.
|
||||
|
||||
typedef Poco::BasicEvent<void> Event;
|
||||
|
||||
//
|
||||
// Events
|
||||
//
|
||||
Event update;
|
||||
Event insert;
|
||||
Event erase;
|
||||
Event commit;
|
||||
Event rollback;
|
||||
|
||||
// Event types.
|
||||
static const EnabledEventType SQLITE_NOTIFY_UPDATE = 1;
|
||||
static const EnabledEventType SQLITE_NOTIFY_COMMIT = 2;
|
||||
static const EnabledEventType SQLITE_NOTIFY_ROLLBACK = 4;
|
||||
|
||||
Notifier(const Session& session,
|
||||
EnabledEventType enabled = SQLITE_NOTIFY_UPDATE | SQLITE_NOTIFY_COMMIT | SQLITE_NOTIFY_ROLLBACK);
|
||||
/// Creates a Notifier and enables all callbacks.
|
||||
|
||||
Notifier(const Session& session,
|
||||
const Any& value,
|
||||
EnabledEventType enabled = SQLITE_NOTIFY_UPDATE | SQLITE_NOTIFY_COMMIT | SQLITE_NOTIFY_ROLLBACK);
|
||||
/// Creates a Notifier, assigns the value to the internal storage and and enables all callbacks.
|
||||
|
||||
~Notifier();
|
||||
/// Disables all callbacks and destroys the Notifier.
|
||||
|
||||
bool enableUpdate();
|
||||
/// Enables update callbacks.
|
||||
|
||||
bool disableUpdate();
|
||||
/// Disables update callbacks.
|
||||
|
||||
bool updateEnabled() const;
|
||||
/// Returns true if update callbacks are enabled, false otherwise.
|
||||
|
||||
bool enableCommit();
|
||||
/// Enables commit callbacks.
|
||||
|
||||
bool disableCommit();
|
||||
/// Disables commit callbacks.
|
||||
|
||||
bool commitEnabled() const;
|
||||
/// Returns true if update callbacks are enabled, false otherwise.
|
||||
|
||||
bool enableRollback();
|
||||
/// Enables rollback callbacks.
|
||||
|
||||
bool disableRollback();
|
||||
/// Disables rollback callbacks.
|
||||
|
||||
bool rollbackEnabled() const;
|
||||
/// Returns true if rollback callbacks are enabled, false otherwise.
|
||||
|
||||
bool enableAll();
|
||||
/// Enables all callbacks.
|
||||
|
||||
bool disableAll();
|
||||
/// Disables all callbacks.
|
||||
|
||||
static void sqliteUpdateCallbackFn(void* pVal, int opCode, const char* pDB, const char* pTable, Poco::Int64 row);
|
||||
/// Update callback event dispatcher. Determines the type of the event, updates the row number
|
||||
/// and triggers the event.
|
||||
|
||||
static int sqliteCommitCallbackFn(void* pVal);
|
||||
/// Commit callback event dispatcher. If an exception occurs, it is catched inside this function,
|
||||
/// non-zero value is returned, which causes SQLite engine to turn commit into a rollback.
|
||||
/// Therefore, callers should check for return value - if it is zero, callback completed succesfuly
|
||||
/// and transaction was committed.
|
||||
|
||||
static void sqliteRollbackCallbackFn(void* pVal);
|
||||
/// Rollback callback event dispatcher.
|
||||
|
||||
bool operator == (const Notifier& other) const;
|
||||
/// Equality operator. Compares value, row and database handles and
|
||||
/// returns true iff all are equal.
|
||||
|
||||
Poco::Int64 getRow() const;
|
||||
/// Returns the row number.
|
||||
|
||||
void setRow(Poco::Int64 row);
|
||||
/// Sets the row number.
|
||||
|
||||
const Poco::Dynamic::Var& getValue() const;
|
||||
/// Returns the value.
|
||||
|
||||
template <typename T>
|
||||
inline void setValue(const T& val)
|
||||
/// Sets the value.
|
||||
{
|
||||
_value = val;
|
||||
}
|
||||
|
||||
private:
|
||||
Notifier();
|
||||
Notifier(const Notifier&);
|
||||
Notifier& operator=(const Notifier&);
|
||||
|
||||
const Session& _session;
|
||||
Poco::Dynamic::Var _value;
|
||||
Poco::Int64 _row;
|
||||
EnabledEventType _enabledEvents;
|
||||
Poco::Mutex _mutex;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
|
||||
inline bool Notifier::operator == (const Notifier& other) const
|
||||
{
|
||||
return _value == other._value &&
|
||||
_row == other._row &&
|
||||
Utility::dbHandle(_session) == Utility::dbHandle(other._session);
|
||||
}
|
||||
|
||||
|
||||
inline Poco::Int64 Notifier::getRow() const
|
||||
{
|
||||
return _row;
|
||||
}
|
||||
|
||||
|
||||
inline void Notifier::setRow(Poco::Int64 row)
|
||||
/// Sets the row number.
|
||||
{
|
||||
_row = row;
|
||||
}
|
||||
|
||||
|
||||
inline const Poco::Dynamic::Var& Notifier::getValue() const
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // SQLite_Notifier_INCLUDED
|
@ -1,64 +0,0 @@
|
||||
//
|
||||
// SQLite.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLite.h#3 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLite
|
||||
//
|
||||
// Basic definitions for the Poco SQLite library.
|
||||
// This file must be the first file included by every other SQLite
|
||||
// header file.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_SQLite_INCLUDED
|
||||
#define SQLite_SQLite_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the SQLite_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// SQLite_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(SQLite_EXPORTS)
|
||||
#define SQLite_API __declspec(dllexport)
|
||||
#else
|
||||
#define SQLite_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(SQLite_API)
|
||||
#if !defined(POCO_NO_GCC_API_ATTRIBUTE) && defined (__GNUC__) && (__GNUC__ >= 4)
|
||||
#define SQLite_API __attribute__ ((visibility ("default")))
|
||||
#else
|
||||
#define SQLite_API
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link SQLite library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(SQLite_EXPORTS)
|
||||
#pragma comment(lib, "PocoDataSQLite" POCO_LIB_SUFFIX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SQLite_SQLite_INCLUDED
|
@ -1,62 +0,0 @@
|
||||
//
|
||||
// SQLiteException.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLiteException.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteException
|
||||
//
|
||||
// Definition of SQLiteException.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_SQLiteException_INCLUDED
|
||||
#define SQLite_SQLiteException_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, SQLiteException, Poco::Data::DataException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InvalidSQLStatementException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InternalDBErrorException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DBAccessDeniedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ExecutionAbortedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DBLockedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TableLockedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, NoMemoryException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ReadOnlyException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InterruptException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, IOErrorException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, CorruptImageException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TableNotFoundException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DatabaseFullException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, CantOpenDBFileException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, LockProtocolException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, SchemaDiffersException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, RowTooBigException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ConstraintViolationException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DataTypeMismatchException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ParameterCountMismatchException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InvalidLibraryUseException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, OSFeaturesMissingException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, AuthorizationDeniedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TransactionException, SQLiteException)
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif
|
@ -1,157 +0,0 @@
|
||||
//
|
||||
// SQLiteStatementImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteStatementImpl
|
||||
//
|
||||
// Definition of the SQLiteStatementImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_SQLiteStatementImpl_INCLUDED
|
||||
#define Data_SQLite_SQLiteStatementImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/SQLite/Extractor.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef struct sqlite3 sqlite3;
|
||||
typedef struct sqlite3_stmt sqlite3_stmt;
|
||||
}
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API SQLiteStatementImpl: public Poco::Data::StatementImpl
|
||||
/// Implements statement functionality needed for SQLite
|
||||
{
|
||||
public:
|
||||
SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqlite3* pDB);
|
||||
/// Creates the SQLiteStatementImpl.
|
||||
|
||||
~SQLiteStatementImpl();
|
||||
/// Destroys the SQLiteStatementImpl.
|
||||
|
||||
protected:
|
||||
std::size_t columnsReturned() const;
|
||||
/// Returns number of columns returned by query.
|
||||
|
||||
int affectedRowCount() const;
|
||||
/// Returns the number of affected rows.
|
||||
/// Used to find out the number of rows affected by insert, delete or update.
|
||||
/// All changes are counted, even if they are later undone by a ROLLBACK or ABORT.
|
||||
/// Changes associated with creating and dropping tables are not counted.
|
||||
|
||||
const MetaColumn& metaColumn(std::size_t pos) const;
|
||||
/// Returns column meta data.
|
||||
|
||||
bool hasNext();
|
||||
/// Returns true if a call to next() will return data.
|
||||
|
||||
std::size_t next();
|
||||
/// Retrieves the next row from the resultset and returns 1.
|
||||
/// Will throw, if the resultset is empty.
|
||||
|
||||
bool canBind() const;
|
||||
/// Returns true if a valid statement is set and we can bind.
|
||||
|
||||
bool canCompile() const;
|
||||
/// Returns true if statement can compile.
|
||||
|
||||
void compileImpl();
|
||||
/// Compiles the statement, doesn't bind yet.
|
||||
/// Returns true if the statement was succesfully compiled.
|
||||
/// The way SQLite handles batches of statmeents is by compiling
|
||||
/// one at a time and returning a pointer to the next one.
|
||||
/// The remainder of the statement is kept in a string
|
||||
/// buffer pointed to by _pLeftover member.
|
||||
|
||||
void bindImpl();
|
||||
/// Binds parameters
|
||||
|
||||
AbstractExtraction::ExtractorPtr extractor();
|
||||
/// Returns the concrete extractor used by the statement.
|
||||
|
||||
AbstractBinding::BinderPtr binder();
|
||||
/// Returns the concrete binder used by the statement.
|
||||
|
||||
private:
|
||||
void clear();
|
||||
/// Removes the _pStmt
|
||||
|
||||
typedef Poco::SharedPtr<Binder> BinderPtr;
|
||||
typedef Poco::SharedPtr<Extractor> ExtractorPtr;
|
||||
typedef Poco::Data::AbstractBindingVec Bindings;
|
||||
typedef Poco::Data::AbstractExtractionVec Extractions;
|
||||
typedef std::vector<Poco::Data::MetaColumn> MetaColumnVec;
|
||||
typedef std::vector<MetaColumnVec> MetaColumnVecVec;
|
||||
typedef Poco::SharedPtr<std::string> StrPtr;
|
||||
typedef Bindings::iterator BindIt;
|
||||
|
||||
sqlite3* _pDB;
|
||||
sqlite3_stmt* _pStmt;
|
||||
bool _stepCalled;
|
||||
int _nextResponse;
|
||||
BinderPtr _pBinder;
|
||||
ExtractorPtr _pExtractor;
|
||||
MetaColumnVecVec _columns;
|
||||
int _affectedRowCount;
|
||||
StrPtr _pLeftover;
|
||||
BindIt _bindBegin;
|
||||
bool _canBind;
|
||||
bool _isExtracted;
|
||||
bool _canCompile;
|
||||
|
||||
static const int POCO_SQLITE_INV_ROW_CNT;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AbstractExtraction::ExtractorPtr SQLiteStatementImpl::extractor()
|
||||
{
|
||||
return _pExtractor;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBinding::BinderPtr SQLiteStatementImpl::binder()
|
||||
{
|
||||
return _pBinder;
|
||||
}
|
||||
|
||||
|
||||
inline bool SQLiteStatementImpl::canBind() const
|
||||
{
|
||||
return _canBind;
|
||||
}
|
||||
|
||||
|
||||
inline bool SQLiteStatementImpl::canCompile() const
|
||||
{
|
||||
return _canCompile;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // Data_SQLite_SQLiteStatementImpl_INCLUDED
|
@ -1,168 +0,0 @@
|
||||
//
|
||||
// SessionImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SessionImpl
|
||||
//
|
||||
// Definition of the SessionImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_SQLite_SessionImpl_INCLUDED
|
||||
#define Data_SQLite_SessionImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Connector.h"
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/AbstractSessionImpl.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Mutex.h"
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef struct sqlite3 sqlite3;
|
||||
}
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API SessionImpl: public Poco::Data::AbstractSessionImpl<SessionImpl>
|
||||
/// Implements SessionImpl interface.
|
||||
{
|
||||
public:
|
||||
SessionImpl(const std::string& fileName,
|
||||
std::size_t loginTimeout = LOGIN_TIMEOUT_DEFAULT);
|
||||
/// Creates the SessionImpl. Opens a connection to the database.
|
||||
|
||||
~SessionImpl();
|
||||
/// Destroys the SessionImpl.
|
||||
|
||||
Poco::Data::StatementImpl* createStatementImpl();
|
||||
/// Returns an SQLite StatementImpl.
|
||||
|
||||
void open(const std::string& connect = "");
|
||||
/// Opens a connection to the Database.
|
||||
///
|
||||
/// An in-memory system database (sys), with a single table (dual)
|
||||
/// containing single field (dummy) is attached to the database.
|
||||
/// The in-memory system database is used to force change count
|
||||
/// to be reset to zero on every new query (or batch of queries)
|
||||
/// execution. Without this functionality, select statements
|
||||
/// executions that do not return any rows return the count of
|
||||
/// changes effected by the most recent insert, update or delete.
|
||||
/// In-memory system database can be queried and updated but can not
|
||||
/// be dropped. It may be used for other purposes
|
||||
/// in the future.
|
||||
|
||||
void close();
|
||||
/// Closes the session.
|
||||
|
||||
bool isConnected();
|
||||
/// Returns true if connected, false otherwise.
|
||||
|
||||
void setConnectionTimeout(std::size_t timeout);
|
||||
/// Sets the session connection timeout value.
|
||||
|
||||
std::size_t getConnectionTimeout();
|
||||
/// Returns the session connection timeout value.
|
||||
|
||||
void begin();
|
||||
/// Starts a transaction.
|
||||
|
||||
void commit();
|
||||
/// Commits and ends a transaction.
|
||||
|
||||
void rollback();
|
||||
/// Aborts a transaction.
|
||||
|
||||
bool canTransact();
|
||||
/// Returns true if session has transaction capabilities.
|
||||
|
||||
bool isTransaction();
|
||||
/// Returns true iff a transaction is a transaction is in progress, false otherwise.
|
||||
|
||||
void setTransactionIsolation(Poco::UInt32 ti);
|
||||
/// Sets the transaction isolation level.
|
||||
|
||||
Poco::UInt32 getTransactionIsolation();
|
||||
/// Returns the transaction isolation level.
|
||||
|
||||
bool hasTransactionIsolation(Poco::UInt32 ti);
|
||||
/// Returns true iff the transaction isolation level corresponding
|
||||
/// to the supplied bitmask is supported.
|
||||
|
||||
bool isTransactionIsolation(Poco::UInt32 ti);
|
||||
/// Returns true iff the transaction isolation level corresponds
|
||||
/// to the supplied bitmask.
|
||||
|
||||
void autoCommit(const std::string&, bool val);
|
||||
/// Sets autocommit property for the session.
|
||||
|
||||
bool isAutoCommit(const std::string& name="");
|
||||
/// Returns autocommit property value.
|
||||
|
||||
const std::string& connectorName() const;
|
||||
/// Returns the name of the connector.
|
||||
|
||||
protected:
|
||||
void setConnectionTimeout(const std::string& prop, const Poco::Any& value);
|
||||
Poco::Any getConnectionTimeout(const std::string& prop);
|
||||
|
||||
private:
|
||||
std::string _connector;
|
||||
sqlite3* _pDB;
|
||||
bool _connected;
|
||||
bool _isTransaction;
|
||||
int _timeout;
|
||||
Poco::Mutex _mutex;
|
||||
|
||||
static const std::string DEFERRED_BEGIN_TRANSACTION;
|
||||
static const std::string COMMIT_TRANSACTION;
|
||||
static const std::string ABORT_TRANSACTION;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline bool SessionImpl::canTransact()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
inline bool SessionImpl::isTransaction()
|
||||
{
|
||||
return _isTransaction;
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& SessionImpl::connectorName() const
|
||||
{
|
||||
return _connector;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t SessionImpl::getConnectionTimeout()
|
||||
{
|
||||
return static_cast<std::size_t>(_timeout);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // Data_SQLite_SessionImpl_INCLUDED
|
@ -1,230 +0,0 @@
|
||||
//
|
||||
// Utility.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Utility.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Utility
|
||||
//
|
||||
// Definition of Utility.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_Utility_INCLUDED
|
||||
#define SQLite_Utility_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Types.h"
|
||||
#include <map>
|
||||
|
||||
|
||||
extern "C"
|
||||
{
|
||||
typedef struct sqlite3 sqlite3;
|
||||
typedef struct sqlite3_stmt sqlite3_stmt;
|
||||
}
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Utility
|
||||
/// Various utility functions for SQLite.
|
||||
{
|
||||
public:
|
||||
static const std::string SQLITE_DATE_FORMAT;
|
||||
static const std::string SQLITE_TIME_FORMAT;
|
||||
typedef std::map<std::string, MetaColumn::ColumnDataType> TypeMap;
|
||||
|
||||
static const int THREAD_MODE_SINGLE;
|
||||
static const int THREAD_MODE_MULTI;
|
||||
static const int THREAD_MODE_SERIAL;
|
||||
|
||||
static const int OPERATION_INSERT;
|
||||
static const int OPERATION_DELETE;
|
||||
static const int OPERATION_UPDATE;
|
||||
|
||||
static sqlite3* dbHandle(const Session& session);
|
||||
/// Returns native DB handle.
|
||||
|
||||
static std::string lastError(sqlite3* pDb);
|
||||
/// Retreives the last error code from sqlite and converts it to a string.
|
||||
|
||||
static std::string lastError(const Session& session);
|
||||
/// Retreives the last error code from sqlite and converts it to a string.
|
||||
|
||||
static void throwException(int rc, const std::string& addErrMsg = std::string());
|
||||
/// Throws for an error code the appropriate exception
|
||||
|
||||
static MetaColumn::ColumnDataType getColumnType(sqlite3_stmt* pStmt, std::size_t pos);
|
||||
/// Returns column data type.
|
||||
|
||||
static bool fileToMemory(sqlite3* pInMemory, const std::string& fileName);
|
||||
/// Loads the contents of a database file on disk into an opened
|
||||
/// database in memory.
|
||||
///
|
||||
/// Returns true if succesful.
|
||||
|
||||
static bool fileToMemory(const Session& session, const std::string& fileName);
|
||||
/// Loads the contents of a database file on disk into an opened
|
||||
/// database in memory.
|
||||
///
|
||||
/// Returns true if succesful.
|
||||
|
||||
static bool memoryToFile(const std::string& fileName, sqlite3* pInMemory);
|
||||
/// Saves the contents of an opened database in memory to the
|
||||
/// database on disk.
|
||||
///
|
||||
/// Returns true if succesful.
|
||||
|
||||
static bool memoryToFile(const std::string& fileName, const Session& session);
|
||||
/// Saves the contents of an opened database in memory to the
|
||||
/// database on disk.
|
||||
///
|
||||
/// Returns true if succesful.
|
||||
|
||||
static bool isThreadSafe();
|
||||
/// Returns true if SQLite was compiled in multi-thread or serialized mode.
|
||||
/// See http://www.sqlite.org/c3ref/threadsafe.html for details.
|
||||
///
|
||||
/// Returns true if succesful
|
||||
|
||||
static bool setThreadMode(int mode);
|
||||
/// Sets the threading mode to single, multi or serialized.
|
||||
/// See http://www.sqlite.org/threadsafe.html for details.
|
||||
///
|
||||
/// Returns true if succesful
|
||||
|
||||
static int getThreadMode();
|
||||
/// Returns the thread mode.
|
||||
|
||||
typedef void(*UpdateCallbackType)(void*, int, const char*, const char*, Poco::Int64);
|
||||
/// Update callback function type.
|
||||
|
||||
typedef int(*CommitCallbackType)(void*);
|
||||
/// Commit callback function type.
|
||||
|
||||
typedef void(*RollbackCallbackType)(void*);
|
||||
/// Rollback callback function type.
|
||||
|
||||
template <typename T, typename CBT>
|
||||
static bool registerUpdateHandler(sqlite3* pDB, CBT callbackFn, T* pParam)
|
||||
/// Registers the callback for (1)(insert, delete, update), (2)(commit) or
|
||||
/// or (3)(rollback) events. Only one function per group can be registered
|
||||
/// at a time. Registration is not thread-safe. Storage pointed to by pParam
|
||||
/// must remain valid as long as registration is active. Registering with
|
||||
/// callbackFn set to zero disables notifications.
|
||||
///
|
||||
/// See http://www.sqlite.org/c3ref/update_hook.html and
|
||||
/// http://www.sqlite.org/c3ref/commit_hook.html for details.
|
||||
{
|
||||
typedef std::pair<CBT, T*> CBPair;
|
||||
typedef std::multimap<sqlite3*, CBPair> CBMap;
|
||||
typedef typename CBMap::iterator CBMapIt;
|
||||
typedef std::pair<CBMapIt, CBMapIt> CBMapItPair;
|
||||
|
||||
static CBMap retMap;
|
||||
T* pRet = reinterpret_cast<T*>(eventHookRegister(pDB, callbackFn, pParam));
|
||||
|
||||
if (pRet == 0)
|
||||
{
|
||||
if (retMap.find(pDB) == retMap.end())
|
||||
{
|
||||
retMap.insert(std::make_pair(pDB, CBPair(callbackFn, pParam)));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CBMapItPair retMapRange = retMap.equal_range(pDB);
|
||||
for (CBMapIt it = retMapRange.first; it != retMapRange.second; ++it)
|
||||
{
|
||||
poco_assert (it->second.first != 0);
|
||||
if ((callbackFn == 0) && (*pRet == *it->second.second))
|
||||
{
|
||||
retMap.erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((callbackFn == it->second.first) && (*pRet == *it->second.second))
|
||||
{
|
||||
it->second.second = pParam;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename T, typename CBT>
|
||||
static bool registerUpdateHandler(const Session& session, CBT callbackFn, T* pParam)
|
||||
/// Registers the callback by calling registerUpdateHandler(sqlite3*, CBT, T*).
|
||||
{
|
||||
return registerUpdateHandler(dbHandle(session), callbackFn, pParam);
|
||||
}
|
||||
|
||||
private:
|
||||
Utility();
|
||||
/// Maps SQLite column declared types to Poco::Data types through
|
||||
/// static TypeMap member.
|
||||
///
|
||||
/// Note: SQLite is type-agnostic and it is the end-user responsibility
|
||||
/// to ensure that column declared data type corresponds to the type of
|
||||
/// data actually held in the database.
|
||||
///
|
||||
/// Column types are case-insensitive.
|
||||
|
||||
Utility(const Utility&);
|
||||
Utility& operator = (const Utility&);
|
||||
|
||||
static void* eventHookRegister(sqlite3* pDB, UpdateCallbackType callbackFn, void* pParam);
|
||||
static void* eventHookRegister(sqlite3* pDB, CommitCallbackType callbackFn, void* pParam);
|
||||
static void* eventHookRegister(sqlite3* pDB, RollbackCallbackType callbackFn, void* pParam);
|
||||
|
||||
static TypeMap _types;
|
||||
static Poco::Mutex _mutex;
|
||||
static int _threadMode;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline std::string Utility::lastError(const Session& session)
|
||||
{
|
||||
poco_assert_dbg ((0 == icompare(session.connector(), 0, 6, "sqlite")));
|
||||
return lastError(dbHandle(session));
|
||||
}
|
||||
|
||||
|
||||
inline bool Utility::memoryToFile(const std::string& fileName, const Session& session)
|
||||
{
|
||||
poco_assert_dbg ((0 == icompare(session.connector(), 0, 6, "sqlite")));
|
||||
return memoryToFile(fileName, dbHandle(session));
|
||||
}
|
||||
|
||||
|
||||
inline bool Utility::fileToMemory(const Session& session, const std::string& fileName)
|
||||
{
|
||||
poco_assert_dbg ((0 == icompare(session.connector(), 0, 6, "sqlite")));
|
||||
return fileToMemory(dbHandle(session), fileName);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // SQLite_Utility_INCLUDED
|
@ -1,129 +0,0 @@
|
||||
//
|
||||
// Binder.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Binder.cpp#5 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Binder
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/Data/Time.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
using Poco::DateTimeFormatter;
|
||||
using Poco::DateTimeFormat;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
Binder::Binder(sqlite3_stmt* pStmt):
|
||||
_pStmt(pStmt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Binder::~Binder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int32 &val, Direction dir)
|
||||
{
|
||||
int rc = sqlite3_bind_int(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int64 &val, Direction dir)
|
||||
{
|
||||
int rc = sqlite3_bind_int64(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
void Binder::bind(std::size_t pos, const long &val, Direction dir)
|
||||
{
|
||||
long tmp = static_cast<long>(val);
|
||||
int rc = sqlite3_bind_int(_pStmt, (int) pos, tmp);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
void Binder::bind(std::size_t pos, const unsigned long &val, Direction dir)
|
||||
{
|
||||
long tmp = static_cast<long>(val);
|
||||
int rc = sqlite3_bind_int(_pStmt, (int) pos, tmp);
|
||||
checkReturn(rc);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const double &val, Direction dir)
|
||||
{
|
||||
int rc = sqlite3_bind_double(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const std::string& val, Direction dir)
|
||||
{
|
||||
int rc = sqlite3_bind_text(_pStmt, (int) pos, val.c_str(), (int) val.size()*sizeof(char), SQLITE_TRANSIENT);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Date& val, Direction dir)
|
||||
{
|
||||
DateTime dt(val.year(), val.month(), val.day());
|
||||
std::string str(DateTimeFormatter::format(dt, Utility::SQLITE_DATE_FORMAT));
|
||||
bind(pos, str, dir);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Time& val, Direction dir)
|
||||
{
|
||||
DateTime dt;
|
||||
dt.assign(dt.year(), dt.month(), dt.day(), val.hour(), val.minute(), val.second());
|
||||
std::string str(DateTimeFormatter::format(dt, Utility::SQLITE_TIME_FORMAT));
|
||||
bind(pos, str, dir);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const DateTime& val, Direction dir)
|
||||
{
|
||||
std::string dt(DateTimeFormatter::format(val, DateTimeFormat::ISO8601_FORMAT));
|
||||
bind(pos, dt, dir);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const NullData&, Direction)
|
||||
{
|
||||
sqlite3_bind_null(_pStmt, pos);
|
||||
}
|
||||
|
||||
|
||||
void Binder::checkReturn(int rc)
|
||||
{
|
||||
if (rc != SQLITE_OK)
|
||||
Utility::throwException(rc);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
@ -1,79 +0,0 @@
|
||||
//
|
||||
// Connector.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Connector.cpp#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Connector
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/Connector.h"
|
||||
#include "Poco/Data/SQLite/SessionImpl.h"
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
|
||||
|
||||
const SQLiteConnectorRegistrator pocoSQLiteConnectorRegistrator;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const std::string Connector::KEY(POCO_DATA_SQLITE_CONNECTOR_NAME);
|
||||
|
||||
|
||||
Connector::Connector()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Connector::~Connector()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> Connector::createSession(const std::string& connectionString,
|
||||
std::size_t timeout)
|
||||
{
|
||||
return Poco::AutoPtr<Poco::Data::SessionImpl>(new SessionImpl(connectionString, timeout));
|
||||
}
|
||||
|
||||
|
||||
void Connector::registerConnector()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().add(new Connector());
|
||||
}
|
||||
|
||||
|
||||
void Connector::unregisterConnector()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().remove(POCO_DATA_SQLITE_CONNECTOR_NAME);
|
||||
}
|
||||
|
||||
|
||||
void Connector::enableSharedCache(bool flag)
|
||||
{
|
||||
sqlite3_enable_shared_cache(flag ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
void Connector::enableSoftHeapLimit(int limit)
|
||||
{
|
||||
sqlite3_soft_heap_limit(limit);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
@ -1,240 +0,0 @@
|
||||
//
|
||||
// Extractor.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Extractor.cpp#5 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Extractor
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/Extractor.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/Date.h"
|
||||
#include "Poco/Data/Time.h"
|
||||
#include "Poco/Data/LOB.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/DateTimeParser.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
using Poco::DateTimeParser;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
Extractor::Extractor(sqlite3_stmt* pStmt):
|
||||
_pStmt(pStmt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Extractor::~Extractor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#ifndef POCO_LONG_IS_64_BIT
|
||||
bool Extractor::extract(std::size_t pos, long& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, unsigned long& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, double& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_double(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, std::string& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
const char *pBuf = reinterpret_cast<const char*>(sqlite3_column_text(_pStmt, (int) pos));
|
||||
if (!pBuf)
|
||||
val.clear();
|
||||
else
|
||||
val.assign(pBuf);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, bool& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = (0 != sqlite3_column_int(_pStmt, (int) pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, float& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = static_cast<float>(sqlite3_column_double(_pStmt, (int) pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, char& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Date& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
std::string str;
|
||||
extract(pos, str);
|
||||
int tzd;
|
||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_DATE_FORMAT, str, tzd);
|
||||
val = dt;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Time& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
std::string str;
|
||||
extract(pos, str);
|
||||
int tzd;
|
||||
DateTime dt = DateTimeParser::parse(Utility::SQLITE_TIME_FORMAT, str, tzd);
|
||||
val = dt;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, DateTime& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
std::string dt;
|
||||
extract(pos, dt);
|
||||
int tzd;
|
||||
DateTimeParser::parse(dt, val, tzd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Any& val)
|
||||
{
|
||||
return extractImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::DynamicAny& val)
|
||||
{
|
||||
return extractImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::isNull(std::size_t pos, std::size_t)
|
||||
{
|
||||
if (pos >= _nulls.size())
|
||||
_nulls.resize(pos + 1);
|
||||
|
||||
if (!_nulls[pos].first)
|
||||
{
|
||||
_nulls[pos].first = true;
|
||||
_nulls[pos].second = (SQLITE_NULL == sqlite3_column_type(_pStmt, pos));
|
||||
}
|
||||
|
||||
return _nulls[pos].second;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
@ -1,201 +0,0 @@
|
||||
//
|
||||
// Notifier.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Notifier.cpp#5 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Notifier
|
||||
//
|
||||
// Implementation of Notifier
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/Notifier.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
Notifier::Notifier(const Session& session, EnabledEventType enabled):
|
||||
_session(session)
|
||||
{
|
||||
if (enabled & SQLITE_NOTIFY_UPDATE) enableUpdate();
|
||||
if (enabled & SQLITE_NOTIFY_COMMIT) enableCommit();
|
||||
if (enabled & SQLITE_NOTIFY_ROLLBACK) enableRollback();
|
||||
}
|
||||
|
||||
|
||||
Notifier::Notifier(const Session& session, const Any& value, EnabledEventType enabled):
|
||||
_session(session),
|
||||
_value(value)
|
||||
{
|
||||
if (enabled & SQLITE_NOTIFY_UPDATE) enableUpdate();
|
||||
if (enabled & SQLITE_NOTIFY_COMMIT) enableCommit();
|
||||
if (enabled & SQLITE_NOTIFY_ROLLBACK) enableRollback();
|
||||
}
|
||||
|
||||
|
||||
Notifier::~Notifier()
|
||||
{
|
||||
try
|
||||
{
|
||||
disableAll();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::enableUpdate()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
|
||||
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), &sqliteUpdateCallbackFn, this))
|
||||
_enabledEvents |= SQLITE_NOTIFY_UPDATE;
|
||||
|
||||
return updateEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::disableUpdate()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
|
||||
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), (Utility::UpdateCallbackType) 0, this))
|
||||
_enabledEvents &= ~SQLITE_NOTIFY_UPDATE;
|
||||
|
||||
return !updateEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::updateEnabled() const
|
||||
{
|
||||
return 0 != (_enabledEvents & SQLITE_NOTIFY_UPDATE);
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::enableCommit()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
|
||||
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), &sqliteCommitCallbackFn, this))
|
||||
_enabledEvents |= SQLITE_NOTIFY_COMMIT;
|
||||
|
||||
return commitEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::disableCommit()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
|
||||
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), (Utility::CommitCallbackType) 0, this))
|
||||
_enabledEvents &= ~SQLITE_NOTIFY_COMMIT;
|
||||
|
||||
return !commitEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::commitEnabled() const
|
||||
{
|
||||
return 0 != (_enabledEvents & SQLITE_NOTIFY_COMMIT);
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::enableRollback()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
|
||||
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), &sqliteRollbackCallbackFn, this))
|
||||
_enabledEvents |= SQLITE_NOTIFY_ROLLBACK;
|
||||
|
||||
return rollbackEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::disableRollback()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
|
||||
if (Utility::registerUpdateHandler(Utility::dbHandle(_session), (Utility::RollbackCallbackType) 0, this))
|
||||
_enabledEvents &= ~SQLITE_NOTIFY_ROLLBACK;
|
||||
|
||||
return !rollbackEnabled();
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::rollbackEnabled() const
|
||||
{
|
||||
return 0 != (_enabledEvents & SQLITE_NOTIFY_ROLLBACK);
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::enableAll()
|
||||
{
|
||||
return enableUpdate() && enableCommit() && enableRollback();
|
||||
}
|
||||
|
||||
|
||||
bool Notifier::disableAll()
|
||||
{
|
||||
return disableUpdate() && disableCommit() && disableRollback();
|
||||
}
|
||||
|
||||
|
||||
void Notifier::sqliteUpdateCallbackFn(void* pVal, int opCode, const char* pDB, const char* pTable, Poco::Int64 row)
|
||||
{
|
||||
poco_check_ptr(pVal);
|
||||
Notifier* pV = reinterpret_cast<Notifier*>(pVal);
|
||||
if (opCode == Utility::OPERATION_INSERT)
|
||||
{
|
||||
pV->_row = row;
|
||||
pV->insert.notify(pV);
|
||||
}
|
||||
else if (opCode == Utility::OPERATION_UPDATE)
|
||||
{
|
||||
pV->_row = row;
|
||||
pV->update.notify(pV);
|
||||
}
|
||||
else if (opCode == Utility::OPERATION_DELETE)
|
||||
{
|
||||
pV->_row = row;
|
||||
pV->erase.notify(pV);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int Notifier::sqliteCommitCallbackFn(void* pVal)
|
||||
{
|
||||
Notifier* pV = reinterpret_cast<Notifier*>(pVal);
|
||||
|
||||
try
|
||||
{
|
||||
pV->commit.notify(pV);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Notifier::sqliteRollbackCallbackFn(void* pVal)
|
||||
{
|
||||
Notifier* pV = reinterpret_cast<Notifier*>(pVal);
|
||||
pV->rollback.notify(pV);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
@ -1,53 +0,0 @@
|
||||
//
|
||||
// SQLiteException.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SQLiteException.cpp#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteException
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
POCO_IMPLEMENT_EXCEPTION(SQLiteException, Poco::Data::DataException, "Generic SQLite error")
|
||||
POCO_IMPLEMENT_EXCEPTION(InvalidSQLStatementException, SQLiteException, "SQL Statement invalid")
|
||||
POCO_IMPLEMENT_EXCEPTION(InternalDBErrorException, SQLiteException, "Internal error")
|
||||
POCO_IMPLEMENT_EXCEPTION(DBAccessDeniedException, SQLiteException, "Access permission denied")
|
||||
POCO_IMPLEMENT_EXCEPTION(ExecutionAbortedException, SQLiteException, "Execution of SQL statement aborted")
|
||||
POCO_IMPLEMENT_EXCEPTION(DBLockedException, SQLiteException, "The database is locked")
|
||||
POCO_IMPLEMENT_EXCEPTION(TableLockedException, SQLiteException, "A table in the database is locked")
|
||||
POCO_IMPLEMENT_EXCEPTION(NoMemoryException, SQLiteException, "Out of Memory")
|
||||
POCO_IMPLEMENT_EXCEPTION(ReadOnlyException, SQLiteException, "Attempt to write a readonly database")
|
||||
POCO_IMPLEMENT_EXCEPTION(InterruptException, SQLiteException, "Operation terminated by an interrupt")
|
||||
POCO_IMPLEMENT_EXCEPTION(IOErrorException, SQLiteException, "Some kind of disk I/O error occurred")
|
||||
POCO_IMPLEMENT_EXCEPTION(CorruptImageException, SQLiteException, "The database disk image is malformed")
|
||||
POCO_IMPLEMENT_EXCEPTION(TableNotFoundException, SQLiteException, "Table not found")
|
||||
POCO_IMPLEMENT_EXCEPTION(DatabaseFullException, SQLiteException, "Insertion failed because database is full")
|
||||
POCO_IMPLEMENT_EXCEPTION(CantOpenDBFileException, SQLiteException, "Unable to open the database file")
|
||||
POCO_IMPLEMENT_EXCEPTION(LockProtocolException, SQLiteException, "Database lock protocol error")
|
||||
POCO_IMPLEMENT_EXCEPTION(SchemaDiffersException, SQLiteException, "The database schema changed")
|
||||
POCO_IMPLEMENT_EXCEPTION(RowTooBigException, SQLiteException, "Too much data for one row of a table")
|
||||
POCO_IMPLEMENT_EXCEPTION(ConstraintViolationException, SQLiteException, "Abort due to constraint violation")
|
||||
POCO_IMPLEMENT_EXCEPTION(DataTypeMismatchException, SQLiteException, "Data type mismatch")
|
||||
POCO_IMPLEMENT_EXCEPTION(ParameterCountMismatchException, SQLiteException, "Parameter count mismatch")
|
||||
POCO_IMPLEMENT_EXCEPTION(InvalidLibraryUseException, SQLiteException, "Library used incorrectly")
|
||||
POCO_IMPLEMENT_EXCEPTION(OSFeaturesMissingException, SQLiteException, "Uses OS features not supported on host")
|
||||
POCO_IMPLEMENT_EXCEPTION(AuthorizationDeniedException, SQLiteException, "Authorization denied")
|
||||
POCO_IMPLEMENT_EXCEPTION(TransactionException, SQLiteException, "Transaction exception")
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
@ -1,312 +0,0 @@
|
||||
//
|
||||
// SQLiteStatementImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#8 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteStatementImpl
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLiteStatementImpl.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/String.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const int SQLiteStatementImpl::POCO_SQLITE_INV_ROW_CNT = -1;
|
||||
|
||||
|
||||
SQLiteStatementImpl::SQLiteStatementImpl(Poco::Data::SessionImpl& rSession, sqlite3* pDB):
|
||||
StatementImpl(rSession),
|
||||
_pDB(pDB),
|
||||
_pStmt(0),
|
||||
_stepCalled(false),
|
||||
_nextResponse(0),
|
||||
_affectedRowCount(POCO_SQLITE_INV_ROW_CNT),
|
||||
_canBind(false),
|
||||
_isExtracted(false),
|
||||
_canCompile(true)
|
||||
{
|
||||
_columns.resize(1);
|
||||
}
|
||||
|
||||
|
||||
SQLiteStatementImpl::~SQLiteStatementImpl()
|
||||
{
|
||||
try
|
||||
{
|
||||
clear();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::compileImpl()
|
||||
{
|
||||
if (!_pLeftover)
|
||||
{
|
||||
_bindBegin = bindings().begin();
|
||||
}
|
||||
|
||||
std::string statement(toString());
|
||||
|
||||
sqlite3_stmt* pStmt = 0;
|
||||
const char* pSql = _pLeftover ? _pLeftover->c_str() : statement.c_str();
|
||||
|
||||
if (0 == std::strlen(pSql))
|
||||
throw InvalidSQLStatementException("Empty statements are illegal");
|
||||
|
||||
int rc = SQLITE_OK;
|
||||
const char* pLeftover = 0;
|
||||
bool queryFound = false;
|
||||
|
||||
do
|
||||
{
|
||||
rc = sqlite3_prepare_v2(_pDB, pSql, -1, &pStmt, &pLeftover);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
if (pStmt) sqlite3_finalize(pStmt);
|
||||
pStmt = 0;
|
||||
std::string errMsg = sqlite3_errmsg(_pDB);
|
||||
Utility::throwException(rc, errMsg);
|
||||
}
|
||||
else if (rc == SQLITE_OK && pStmt)
|
||||
{
|
||||
queryFound = true;
|
||||
}
|
||||
else if (rc == SQLITE_OK && !pStmt) // comment/whitespace ignore
|
||||
{
|
||||
pSql = pLeftover;
|
||||
if (std::strlen(pSql) == 0)
|
||||
{
|
||||
// empty statement or an conditional statement! like CREATE IF NOT EXISTS
|
||||
// this is valid
|
||||
queryFound = true;
|
||||
}
|
||||
}
|
||||
} while (rc == SQLITE_OK && !pStmt && !queryFound);
|
||||
|
||||
//Finalization call in clear() invalidates the pointer, so the value is remembered here.
|
||||
//For last statement in a batch (or a single statement), pLeftover == "", so the next call
|
||||
// to compileImpl() shall return false immediately when there are no more statements left.
|
||||
std::string leftOver(pLeftover);
|
||||
trimInPlace(leftOver);
|
||||
clear();
|
||||
_pStmt = pStmt;
|
||||
if (!leftOver.empty())
|
||||
{
|
||||
_pLeftover = new std::string(leftOver);
|
||||
_canCompile = true;
|
||||
}
|
||||
else _canCompile = false;
|
||||
|
||||
_pBinder = new Binder(_pStmt);
|
||||
_pExtractor = new Extractor(_pStmt);
|
||||
|
||||
if (SQLITE_DONE == _nextResponse && _isExtracted)
|
||||
{
|
||||
//if this is not the first compile and there has already been extraction
|
||||
//during previous step, switch to the next set if there is one provided
|
||||
if (hasMoreDataSets())
|
||||
{
|
||||
activateNextDataSet();
|
||||
_isExtracted = false;
|
||||
}
|
||||
}
|
||||
|
||||
int colCount = sqlite3_column_count(_pStmt);
|
||||
|
||||
if (colCount)
|
||||
{
|
||||
std::size_t curDataSet = currentDataSet();
|
||||
if (curDataSet >= _columns.size()) _columns.resize(curDataSet + 1);
|
||||
for (int i = 0; i < colCount; ++i)
|
||||
{
|
||||
MetaColumn mc(i, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
|
||||
_columns[curDataSet].push_back(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::bindImpl()
|
||||
{
|
||||
_stepCalled = false;
|
||||
_nextResponse = 0;
|
||||
if (_pStmt == 0) return;
|
||||
|
||||
sqlite3_reset(_pStmt);
|
||||
|
||||
int paramCount = sqlite3_bind_parameter_count(_pStmt);
|
||||
BindIt bindEnd = bindings().end();
|
||||
if (0 == paramCount || bindEnd == _bindBegin)
|
||||
{
|
||||
_canBind = false;
|
||||
return;
|
||||
}
|
||||
|
||||
std::size_t availableCount = 0;
|
||||
Bindings::difference_type bindCount = 0;
|
||||
Bindings::iterator it = _bindBegin;
|
||||
for (; it != bindEnd; ++it)
|
||||
{
|
||||
availableCount += (*it)->numOfColumnsHandled();
|
||||
if (availableCount <= (size_t)paramCount) ++bindCount;
|
||||
else break;
|
||||
}
|
||||
|
||||
Bindings::difference_type remainingBindCount = bindEnd - _bindBegin;
|
||||
if (bindCount < remainingBindCount)
|
||||
{
|
||||
bindEnd = _bindBegin + bindCount;
|
||||
_canBind = true;
|
||||
}
|
||||
else if (bindCount > remainingBindCount)
|
||||
throw ParameterCountMismatchException();
|
||||
|
||||
std::size_t boundRowCount;
|
||||
if (_bindBegin != bindings().end())
|
||||
{
|
||||
boundRowCount = (*_bindBegin)->numOfRowsHandled();
|
||||
|
||||
Bindings::iterator oldBegin = _bindBegin;
|
||||
for (std::size_t pos = 1; _bindBegin != bindEnd && (*_bindBegin)->canBind(); ++_bindBegin)
|
||||
{
|
||||
if (boundRowCount != (*_bindBegin)->numOfRowsHandled())
|
||||
throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");
|
||||
|
||||
(*_bindBegin)->bind(pos);
|
||||
pos += (*_bindBegin)->numOfColumnsHandled();
|
||||
}
|
||||
|
||||
if ((*oldBegin)->canBind())
|
||||
{
|
||||
//container binding will come back for more, so we must rewind
|
||||
_bindBegin = oldBegin;
|
||||
_canBind = true;
|
||||
}
|
||||
else _canBind = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::clear()
|
||||
{
|
||||
_columns[currentDataSet()].clear();
|
||||
_affectedRowCount = POCO_SQLITE_INV_ROW_CNT;
|
||||
|
||||
if (_pStmt)
|
||||
{
|
||||
sqlite3_finalize(_pStmt);
|
||||
_pStmt=0;
|
||||
}
|
||||
_pLeftover = 0;
|
||||
}
|
||||
|
||||
|
||||
bool SQLiteStatementImpl::hasNext()
|
||||
{
|
||||
if (_stepCalled)
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
|
||||
// _pStmt is allowed to be null for conditional SQL statements
|
||||
if (_pStmt == 0)
|
||||
{
|
||||
_stepCalled = true;
|
||||
_nextResponse = SQLITE_DONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
_stepCalled = true;
|
||||
_nextResponse = sqlite3_step(_pStmt);
|
||||
|
||||
if (_affectedRowCount == POCO_SQLITE_INV_ROW_CNT) _affectedRowCount = 0;
|
||||
if (!sqlite3_stmt_readonly(_pStmt))
|
||||
_affectedRowCount += sqlite3_changes(_pDB);
|
||||
|
||||
if (_nextResponse != SQLITE_ROW && _nextResponse != SQLITE_OK && _nextResponse != SQLITE_DONE)
|
||||
Utility::throwException(_nextResponse);
|
||||
|
||||
_pExtractor->reset();//clear the cached null indicators
|
||||
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
}
|
||||
|
||||
|
||||
std::size_t SQLiteStatementImpl::next()
|
||||
{
|
||||
if (SQLITE_ROW == _nextResponse)
|
||||
{
|
||||
poco_assert (columnsReturned() == (size_t)sqlite3_column_count(_pStmt));
|
||||
|
||||
Extractions& extracts = extractions();
|
||||
Extractions::iterator it = extracts.begin();
|
||||
Extractions::iterator itEnd = extracts.end();
|
||||
std::size_t pos = 0; // sqlite starts with pos 0 for results!
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
_isExtracted = true;
|
||||
}
|
||||
_stepCalled = false;
|
||||
if (_affectedRowCount == POCO_SQLITE_INV_ROW_CNT) _affectedRowCount = 0;
|
||||
_affectedRowCount += (*extracts.begin())->numOfRowsHandled();
|
||||
}
|
||||
else if (SQLITE_DONE == _nextResponse)
|
||||
{
|
||||
throw Poco::Data::DataException("No data received");
|
||||
}
|
||||
else
|
||||
{
|
||||
Utility::throwException(_nextResponse, std::string("Iterator Error: trying to access the next value"));
|
||||
}
|
||||
|
||||
return 1u;
|
||||
}
|
||||
|
||||
|
||||
std::size_t SQLiteStatementImpl::columnsReturned() const
|
||||
{
|
||||
return (std::size_t) _columns[currentDataSet()].size();
|
||||
}
|
||||
|
||||
|
||||
const MetaColumn& SQLiteStatementImpl::metaColumn(std::size_t pos) const
|
||||
{
|
||||
std::size_t curDataSet = currentDataSet();
|
||||
poco_assert (pos >= 0 && pos <= _columns[curDataSet].size());
|
||||
return _columns[curDataSet][pos];
|
||||
}
|
||||
|
||||
|
||||
int SQLiteStatementImpl::affectedRowCount() const
|
||||
{
|
||||
if (_affectedRowCount != POCO_SQLITE_INV_ROW_CNT) return _affectedRowCount;
|
||||
return _pStmt == 0 || sqlite3_stmt_readonly(_pStmt) ? 0 : sqlite3_changes(_pDB);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
@ -1,272 +0,0 @@
|
||||
//
|
||||
// SessionImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SessionImpl.cpp#5 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SessionImpl
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SessionImpl.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteStatementImpl.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/ActiveMethod.h"
|
||||
#include "Poco/ActiveResult.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
#ifndef SQLITE_OPEN_URI
|
||||
#define SQLITE_OPEN_URI 0
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const std::string SessionImpl::DEFERRED_BEGIN_TRANSACTION("BEGIN DEFERRED");
|
||||
const std::string SessionImpl::COMMIT_TRANSACTION("COMMIT");
|
||||
const std::string SessionImpl::ABORT_TRANSACTION("ROLLBACK");
|
||||
|
||||
|
||||
SessionImpl::SessionImpl(const std::string& fileName, std::size_t loginTimeout):
|
||||
Poco::Data::AbstractSessionImpl<SessionImpl>(fileName, loginTimeout),
|
||||
_connector(Connector::KEY),
|
||||
_pDB(0),
|
||||
_connected(false),
|
||||
_isTransaction(false)
|
||||
{
|
||||
open();
|
||||
setConnectionTimeout(CONNECTION_TIMEOUT_DEFAULT);
|
||||
setProperty("handle", _pDB);
|
||||
addFeature("autoCommit",
|
||||
&SessionImpl::autoCommit,
|
||||
&SessionImpl::isAutoCommit);
|
||||
addProperty("connectionTimeout", &SessionImpl::setConnectionTimeout, &SessionImpl::getConnectionTimeout);
|
||||
}
|
||||
|
||||
|
||||
SessionImpl::~SessionImpl()
|
||||
{
|
||||
try
|
||||
{
|
||||
close();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
poco_unexpected();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Poco::Data::StatementImpl* SessionImpl::createStatementImpl()
|
||||
{
|
||||
poco_check_ptr (_pDB);
|
||||
return new SQLiteStatementImpl(*this, _pDB);
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::begin()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(DEFERRED_BEGIN_TRANSACTION);
|
||||
tmp.execute();
|
||||
_isTransaction = true;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::commit()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(COMMIT_TRANSACTION);
|
||||
tmp.execute();
|
||||
_isTransaction = false;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::rollback()
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
SQLiteStatementImpl tmp(*this, _pDB);
|
||||
tmp.add(ABORT_TRANSACTION);
|
||||
tmp.execute();
|
||||
_isTransaction = false;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::setTransactionIsolation(Poco::UInt32 ti)
|
||||
{
|
||||
if (ti != Session::TRANSACTION_READ_COMMITTED)
|
||||
throw Poco::InvalidArgumentException("setTransactionIsolation()");
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt32 SessionImpl::getTransactionIsolation()
|
||||
{
|
||||
return Session::TRANSACTION_READ_COMMITTED;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::hasTransactionIsolation(Poco::UInt32 ti)
|
||||
{
|
||||
if (ti == Session::TRANSACTION_READ_COMMITTED) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isTransactionIsolation(Poco::UInt32 ti)
|
||||
{
|
||||
if (ti == Session::TRANSACTION_READ_COMMITTED) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
class ActiveConnector
|
||||
{
|
||||
public:
|
||||
ActiveConnector(const std::string& connectString, sqlite3** ppDB):
|
||||
connect(this, &ActiveConnector::connectImpl),
|
||||
_connectString(connectString),
|
||||
_ppDB(ppDB)
|
||||
{
|
||||
poco_check_ptr(_ppDB);
|
||||
}
|
||||
|
||||
ActiveMethod<int, void, ActiveConnector> connect;
|
||||
|
||||
private:
|
||||
ActiveConnector();
|
||||
|
||||
inline int connectImpl()
|
||||
{
|
||||
return sqlite3_open_v2(_connectString.c_str(), _ppDB, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI, NULL);
|
||||
}
|
||||
|
||||
std::string _connectString;
|
||||
sqlite3** _ppDB;
|
||||
};
|
||||
|
||||
|
||||
void SessionImpl::open(const std::string& connect)
|
||||
{
|
||||
if (connect != connectionString())
|
||||
{
|
||||
if (isConnected())
|
||||
throw InvalidAccessException("Session already connected");
|
||||
|
||||
if (!connect.empty())
|
||||
setConnectionString(connect);
|
||||
}
|
||||
|
||||
poco_assert_dbg (!connectionString().empty());
|
||||
|
||||
try
|
||||
{
|
||||
ActiveConnector connector(connectionString(), &_pDB);
|
||||
ActiveResult<int> result = connector.connect();
|
||||
if (!result.tryWait(getLoginTimeout() * 1000))
|
||||
throw ConnectionFailedException("Timed out.");
|
||||
|
||||
int rc = result.data();
|
||||
if (rc != 0)
|
||||
{
|
||||
close();
|
||||
Utility::throwException(rc);
|
||||
}
|
||||
}
|
||||
catch (SQLiteException& ex)
|
||||
{
|
||||
throw ConnectionFailedException(ex.displayText());
|
||||
}
|
||||
|
||||
_connected = true;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::close()
|
||||
{
|
||||
if (_pDB)
|
||||
{
|
||||
sqlite3_close(_pDB);
|
||||
_pDB = 0;
|
||||
}
|
||||
|
||||
_connected = false;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isConnected()
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::setConnectionTimeout(std::size_t timeout)
|
||||
{
|
||||
int tout = 1000 * timeout;
|
||||
int rc = sqlite3_busy_timeout(_pDB, tout);
|
||||
if (rc != 0) Utility::throwException(rc);
|
||||
_timeout = tout;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::setConnectionTimeout(const std::string& prop, const Poco::Any& value)
|
||||
{
|
||||
setConnectionTimeout(Poco::RefAnyCast<std::size_t>(value));
|
||||
}
|
||||
|
||||
|
||||
Poco::Any SessionImpl::getConnectionTimeout(const std::string& prop)
|
||||
{
|
||||
return Poco::Any(_timeout/1000);
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::autoCommit(const std::string&, bool)
|
||||
{
|
||||
// The problem here is to decide whether to call commit or rollback
|
||||
// when autocommit is set to true. Hence, it is best not to implement
|
||||
// this explicit call and only implicitly support autocommit setting.
|
||||
throw NotImplementedException(
|
||||
"SQLite autocommit is implicit with begin/commit/rollback.");
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isAutoCommit(const std::string&)
|
||||
{
|
||||
Poco::Mutex::ScopedLock l(_mutex);
|
||||
return (0 != sqlite3_get_autocommit(_pDB));
|
||||
}
|
||||
|
||||
|
||||
// NOTE: Utility::dbHandle() has been moved here from Utility.cpp
|
||||
// as a workaround for a failing AnyCast with Clang.
|
||||
// See <https://github.com/pocoproject/poco/issues/578>
|
||||
// for a discussion.
|
||||
sqlite3* Utility::dbHandle(const Session& session)
|
||||
{
|
||||
return AnyCast<sqlite3*>(session.getProperty("handle"));
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
@ -1,325 +0,0 @@
|
||||
//
|
||||
// Utility.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Utility.cpp#5 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Utility
|
||||
//
|
||||
// Implementation of Utility
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/Exception.h"
|
||||
#if defined(POCO_UNBUNDLED)
|
||||
#include <sqlite3.h>
|
||||
#else
|
||||
#include "sqlite3.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef SQLITE_OPEN_URI
|
||||
#define SQLITE_OPEN_URI 0
|
||||
#endif
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const int Utility::THREAD_MODE_SINGLE = SQLITE_CONFIG_SINGLETHREAD;
|
||||
const int Utility::THREAD_MODE_MULTI = SQLITE_CONFIG_MULTITHREAD;
|
||||
const int Utility::THREAD_MODE_SERIAL = SQLITE_CONFIG_SERIALIZED;
|
||||
int Utility::_threadMode =
|
||||
#if (SQLITE_THREADSAFE == 0)
|
||||
SQLITE_CONFIG_SINGLETHREAD;
|
||||
#elif (SQLITE_THREADSAFE == 1)
|
||||
SQLITE_CONFIG_SERIALIZED;
|
||||
#elif (SQLITE_THREADSAFE == 2)
|
||||
SQLITE_CONFIG_MULTITHREAD;
|
||||
#endif
|
||||
|
||||
const int Utility::OPERATION_INSERT = SQLITE_INSERT;
|
||||
const int Utility::OPERATION_DELETE = SQLITE_DELETE;
|
||||
const int Utility::OPERATION_UPDATE = SQLITE_UPDATE;
|
||||
|
||||
const std::string Utility::SQLITE_DATE_FORMAT = "%Y-%m-%d";
|
||||
const std::string Utility::SQLITE_TIME_FORMAT = "%H:%M:%S";
|
||||
Utility::TypeMap Utility::_types;
|
||||
Poco::Mutex Utility::_mutex;
|
||||
|
||||
|
||||
Utility::Utility()
|
||||
{
|
||||
if (_types.empty())
|
||||
{
|
||||
_types.insert(TypeMap::value_type("", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("BOOL", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("BOOLEAN", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("BIT", MetaColumn::FDT_BOOL));
|
||||
_types.insert(TypeMap::value_type("UINT8", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("UTINY", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("UINTEGER8", MetaColumn::FDT_UINT8));
|
||||
_types.insert(TypeMap::value_type("INT8", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("TINY", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("INTEGER8", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("UINT16", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("USHORT", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("UINTEGER16", MetaColumn::FDT_UINT16));
|
||||
_types.insert(TypeMap::value_type("INT16", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("SHORT", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("INTEGER16", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("UINT", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("UINT32", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("UINTEGER32", MetaColumn::FDT_UINT32));
|
||||
_types.insert(TypeMap::value_type("INT", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INT32", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INTEGER", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("INTEGER32", MetaColumn::FDT_INT32));
|
||||
_types.insert(TypeMap::value_type("UINT64", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("ULONG", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("UINTEGER64", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("INT64", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("LONG", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("INTEGER64", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("TINYINT", MetaColumn::FDT_INT8));
|
||||
_types.insert(TypeMap::value_type("SMALLINT", MetaColumn::FDT_INT16));
|
||||
_types.insert(TypeMap::value_type("BIGINT", MetaColumn::FDT_INT64));
|
||||
_types.insert(TypeMap::value_type("COUNTER", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("AUTOINCREMENT", MetaColumn::FDT_UINT64));
|
||||
_types.insert(TypeMap::value_type("REAL", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("FLOA", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("FLOAT", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("DOUB", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("DOUBLE", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("DECIMAL", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("NUMERIC", MetaColumn::FDT_DOUBLE));
|
||||
_types.insert(TypeMap::value_type("CHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("CLOB", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("TEXT", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("VARCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NCLOB", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NTEXT", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("NVARCHAR", MetaColumn::FDT_STRING));
|
||||
_types.insert(TypeMap::value_type("BLOB", MetaColumn::FDT_BLOB));
|
||||
_types.insert(TypeMap::value_type("DATE", MetaColumn::FDT_DATE));
|
||||
_types.insert(TypeMap::value_type("TIME", MetaColumn::FDT_TIME));
|
||||
_types.insert(TypeMap::value_type("DATETIME", MetaColumn::FDT_TIMESTAMP));
|
||||
_types.insert(TypeMap::value_type("TIMESTAMP", MetaColumn::FDT_TIMESTAMP));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string Utility::lastError(sqlite3* pDB)
|
||||
{
|
||||
return std::string(sqlite3_errmsg(pDB));
|
||||
}
|
||||
|
||||
|
||||
MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size_t pos)
|
||||
{
|
||||
poco_assert_dbg (pStmt);
|
||||
|
||||
// Ensure statics are initialized
|
||||
{
|
||||
Poco::Mutex::ScopedLock lock(_mutex);
|
||||
static Utility u;
|
||||
}
|
||||
|
||||
const char* pc = sqlite3_column_decltype(pStmt, (int) pos);
|
||||
std::string sqliteType = pc ? pc : "";
|
||||
Poco::toUpperInPlace(sqliteType);
|
||||
sqliteType = sqliteType.substr(0, sqliteType.find_first_of(" ("));
|
||||
|
||||
TypeMap::const_iterator it = _types.find(Poco::trimInPlace(sqliteType));
|
||||
if (_types.end() == it) throw Poco::NotFoundException();
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
void Utility::throwException(int rc, const std::string& addErrMsg)
|
||||
{
|
||||
switch (rc)
|
||||
{
|
||||
case SQLITE_OK:
|
||||
break;
|
||||
case SQLITE_ERROR:
|
||||
throw InvalidSQLStatementException(std::string("SQL error or missing database"), addErrMsg);
|
||||
case SQLITE_INTERNAL:
|
||||
throw InternalDBErrorException(std::string("An internal logic error in SQLite"), addErrMsg);
|
||||
case SQLITE_PERM:
|
||||
throw DBAccessDeniedException(std::string("Access permission denied"), addErrMsg);
|
||||
case SQLITE_ABORT:
|
||||
throw ExecutionAbortedException(std::string("Callback routine requested an abort"), addErrMsg);
|
||||
case SQLITE_BUSY:
|
||||
case SQLITE_BUSY_RECOVERY:
|
||||
case SQLITE_BUSY_SNAPSHOT:
|
||||
throw DBLockedException(std::string("The database file is locked"), addErrMsg);
|
||||
case SQLITE_LOCKED:
|
||||
throw TableLockedException(std::string("A table in the database is locked"), addErrMsg);
|
||||
case SQLITE_NOMEM:
|
||||
throw NoMemoryException(std::string("A malloc() failed"), addErrMsg);
|
||||
case SQLITE_READONLY:
|
||||
throw ReadOnlyException(std::string("Attempt to write a readonly database"), addErrMsg);
|
||||
case SQLITE_INTERRUPT:
|
||||
throw InterruptException(std::string("Operation terminated by sqlite_interrupt()"), addErrMsg);
|
||||
case SQLITE_IOERR:
|
||||
throw IOErrorException(std::string("Some kind of disk I/O error occurred"), addErrMsg);
|
||||
case SQLITE_CORRUPT:
|
||||
throw CorruptImageException(std::string("The database disk image is malformed"), addErrMsg);
|
||||
case SQLITE_NOTFOUND:
|
||||
throw TableNotFoundException(std::string("Table or record not found"), addErrMsg);
|
||||
case SQLITE_FULL:
|
||||
throw DatabaseFullException(std::string("Insertion failed because database is full"), addErrMsg);
|
||||
case SQLITE_CANTOPEN:
|
||||
throw CantOpenDBFileException(std::string("Unable to open the database file"), addErrMsg);
|
||||
case SQLITE_PROTOCOL:
|
||||
throw LockProtocolException(std::string("Database lock protocol error"), addErrMsg);
|
||||
case SQLITE_EMPTY:
|
||||
throw InternalDBErrorException(std::string("(Internal Only) Database table is empty"), addErrMsg);
|
||||
case SQLITE_SCHEMA:
|
||||
throw SchemaDiffersException(std::string("The database schema changed"), addErrMsg);
|
||||
case SQLITE_TOOBIG:
|
||||
throw RowTooBigException(std::string("Too much data for one row of a table"), addErrMsg);
|
||||
case SQLITE_CONSTRAINT:
|
||||
throw ConstraintViolationException(std::string("Abort due to constraint violation"), addErrMsg);
|
||||
case SQLITE_MISMATCH:
|
||||
throw DataTypeMismatchException(std::string("Data type mismatch"), addErrMsg);
|
||||
case SQLITE_MISUSE:
|
||||
throw InvalidLibraryUseException(std::string("Library used incorrectly"), addErrMsg);
|
||||
case SQLITE_NOLFS:
|
||||
throw OSFeaturesMissingException(std::string("Uses OS features not supported on host"), addErrMsg);
|
||||
case SQLITE_AUTH:
|
||||
throw AuthorizationDeniedException(std::string("Authorization denied"), addErrMsg);
|
||||
case SQLITE_FORMAT:
|
||||
throw CorruptImageException(std::string("Auxiliary database format error"), addErrMsg);
|
||||
case SQLITE_NOTADB:
|
||||
throw CorruptImageException(std::string("File opened that is not a database file"), addErrMsg);
|
||||
case SQLITE_RANGE:
|
||||
throw InvalidSQLStatementException(std::string("Bind Parameter out of range (Access of invalid position 0? bind starts with 1!)"), addErrMsg);
|
||||
case SQLITE_ROW:
|
||||
break; // sqlite_step() has another row ready
|
||||
case SQLITE_DONE:
|
||||
break; // sqlite_step() has finished executing
|
||||
default:
|
||||
throw SQLiteException(std::string("Unknown error code: ") + Poco::NumberFormatter::format(rc), addErrMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Utility::fileToMemory(sqlite3* pInMemory, const std::string& fileName)
|
||||
{
|
||||
int rc;
|
||||
sqlite3* pFile;
|
||||
sqlite3_backup* pBackup;
|
||||
|
||||
rc = sqlite3_open_v2(fileName.c_str(), &pFile, SQLITE_OPEN_READONLY | SQLITE_OPEN_URI, NULL);
|
||||
if(rc == SQLITE_OK )
|
||||
{
|
||||
pBackup = sqlite3_backup_init(pInMemory, "main", pFile, "main");
|
||||
if( pBackup )
|
||||
{
|
||||
sqlite3_backup_step(pBackup, -1);
|
||||
sqlite3_backup_finish(pBackup);
|
||||
}
|
||||
rc = sqlite3_errcode(pFile);
|
||||
}
|
||||
|
||||
sqlite3_close(pFile);
|
||||
return SQLITE_OK == rc;
|
||||
}
|
||||
|
||||
|
||||
bool Utility::memoryToFile(const std::string& fileName, sqlite3* pInMemory)
|
||||
{
|
||||
int rc;
|
||||
sqlite3* pFile;
|
||||
sqlite3_backup* pBackup;
|
||||
|
||||
rc = sqlite3_open_v2(fileName.c_str(), &pFile, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_URI, NULL);
|
||||
if(rc == SQLITE_OK )
|
||||
{
|
||||
pBackup = sqlite3_backup_init(pFile, "main", pInMemory, "main");
|
||||
if( pBackup )
|
||||
{
|
||||
sqlite3_backup_step(pBackup, -1);
|
||||
sqlite3_backup_finish(pBackup);
|
||||
}
|
||||
rc = sqlite3_errcode(pFile);
|
||||
}
|
||||
|
||||
sqlite3_close(pFile);
|
||||
return SQLITE_OK == rc;
|
||||
}
|
||||
|
||||
|
||||
bool Utility::isThreadSafe()
|
||||
{
|
||||
return 0 != sqlite3_threadsafe();
|
||||
}
|
||||
|
||||
|
||||
int Utility::getThreadMode()
|
||||
{
|
||||
return _threadMode;
|
||||
}
|
||||
|
||||
|
||||
bool Utility::setThreadMode(int mode)
|
||||
{
|
||||
#if (SQLITE_THREADSAFE != 0)
|
||||
if (SQLITE_OK == sqlite3_shutdown())
|
||||
{
|
||||
if (SQLITE_OK == sqlite3_config(mode))
|
||||
{
|
||||
_threadMode = mode;
|
||||
if (SQLITE_OK == sqlite3_initialize())
|
||||
return true;
|
||||
}
|
||||
sqlite3_initialize();
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void* Utility::eventHookRegister(sqlite3* pDB, UpdateCallbackType callbackFn, void* pParam)
|
||||
{
|
||||
typedef void(*pF)(void*, int, const char*, const char*, sqlite3_int64);
|
||||
return sqlite3_update_hook(pDB, reinterpret_cast<pF>(callbackFn), pParam);
|
||||
}
|
||||
|
||||
|
||||
void* Utility::eventHookRegister(sqlite3* pDB, CommitCallbackType callbackFn, void* pParam)
|
||||
{
|
||||
return sqlite3_commit_hook(pDB, callbackFn, pParam);
|
||||
}
|
||||
|
||||
|
||||
void* Utility::eventHookRegister(sqlite3* pDB, RollbackCallbackType callbackFn, void* pParam)
|
||||
{
|
||||
return sqlite3_rollback_hook(pDB, callbackFn, pParam);
|
||||
}
|
||||
|
||||
|
||||
// NOTE: Utility::dbHandle() has been moved to SessionImpl.cpp,
|
||||
// as a workaround for a failing AnyCast with Clang.
|
||||
// See <https://github.com/pocoproject/poco/issues/578>
|
||||
// for a discussion.
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
set(TESTUNIT "${LIBNAME}-testrunner")
|
||||
|
||||
# Sources
|
||||
file(GLOB SRCS_G "src/*.cpp")
|
||||
POCO_SOURCES_AUTO( TEST_SRCS ${SRCS_G})
|
||||
|
||||
# Headers
|
||||
file(GLOB_RECURSE HDRS_G "src/*.h" )
|
||||
POCO_HEADERS_AUTO( TEST_SRCS ${HDRS_G})
|
||||
|
||||
POCO_SOURCES_AUTO_PLAT( TEST_SRCS OFF
|
||||
src/WinDriver.cpp
|
||||
)
|
||||
|
||||
POCO_SOURCES_AUTO_PLAT( TEST_SRCS WINCE
|
||||
src/WinCEDriver.cpp
|
||||
)
|
||||
|
||||
add_executable( ${TESTUNIT} ${TEST_SRCS} )
|
||||
add_test(NAME ${LIBNAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${TESTUNIT} -all)
|
||||
target_link_libraries( ${TESTUNIT} PocoDataSQLite PocoData PocoFoundation CppUnit )
|
@ -1,19 +0,0 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/Driver.cpp#2 $
|
||||
//
|
||||
// Console-based test driver for Poco SQLite.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "SQLiteTestSuite.h"
|
||||
|
||||
|
||||
CppUnitMain(SQLiteTestSuite)
|
File diff suppressed because it is too large
Load Diff
@ -1,165 +0,0 @@
|
||||
//
|
||||
// SQLiteTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTest.h#4 $
|
||||
//
|
||||
// Definition of the SQLiteTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLiteTest_INCLUDED
|
||||
#define SQLiteTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
class Session;
|
||||
|
||||
} }
|
||||
|
||||
|
||||
class SQLiteTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SQLiteTest(const std::string& name);
|
||||
~SQLiteTest();
|
||||
|
||||
void testBinding();
|
||||
void testZeroRows();
|
||||
void testSimpleAccess();
|
||||
void testInMemory();
|
||||
void testNullCharPointer();
|
||||
void testInsertCharPointer();
|
||||
void testInsertCharPointer2();
|
||||
void testComplexType();
|
||||
void testSimpleAccessVector();
|
||||
void testComplexTypeVector();
|
||||
void testSharedPtrComplexTypeVector();
|
||||
void testInsertVector();
|
||||
void testInsertEmptyVector();
|
||||
void testAffectedRows();
|
||||
void testInsertSingleBulk();
|
||||
void testInsertSingleBulkVec();
|
||||
|
||||
void testLimit();
|
||||
void testLimitOnce();
|
||||
void testLimitPrepare();
|
||||
void testLimitZero();
|
||||
void testPrepare();
|
||||
|
||||
void testSetSimple();
|
||||
void testSetComplex();
|
||||
void testSetComplexUnique();
|
||||
void testMultiSetSimple();
|
||||
void testMultiSetComplex();
|
||||
void testMapComplex();
|
||||
void testMapComplexUnique();
|
||||
void testMultiMapComplex();
|
||||
void testSelectIntoSingle();
|
||||
void testSelectIntoSingleStep();
|
||||
void testSelectIntoSingleFail();
|
||||
void testLowerLimitOk();
|
||||
void testLowerLimitFail();
|
||||
void testCombinedLimits();
|
||||
void testCombinedIllegalLimits();
|
||||
void testRange();
|
||||
void testIllegalRange();
|
||||
void testSingleSelect();
|
||||
void testEmptyDB();
|
||||
|
||||
void testCLOB();
|
||||
|
||||
void testTuple1();
|
||||
void testTupleVector1();
|
||||
void testTuple2();
|
||||
void testTupleVector2();
|
||||
void testTuple3();
|
||||
void testTupleVector3();
|
||||
void testTuple4();
|
||||
void testTupleVector4();
|
||||
void testTuple5();
|
||||
void testTupleVector5();
|
||||
void testTuple6();
|
||||
void testTupleVector6();
|
||||
void testTuple7();
|
||||
void testTupleVector7();
|
||||
void testTuple8();
|
||||
void testTupleVector8();
|
||||
void testTuple9();
|
||||
void testTupleVector9();
|
||||
void testTuple10();
|
||||
void testTupleVector10();
|
||||
|
||||
void testDateTime();
|
||||
|
||||
void testInternalExtraction();
|
||||
void testPrimaryKeyConstraint();
|
||||
void testNullable();
|
||||
void testNulls();
|
||||
void testRowIterator();
|
||||
void testAsync();
|
||||
|
||||
void testAny();
|
||||
void testDynamicAny();
|
||||
void testPair();
|
||||
|
||||
void testSQLChannel();
|
||||
void testSQLLogger();
|
||||
|
||||
void testExternalBindingAndExtraction();
|
||||
void testBindingCount();
|
||||
void testMultipleResults();
|
||||
|
||||
void testReconnect();
|
||||
|
||||
void testThreadModes();
|
||||
|
||||
void testUpdateCallback();
|
||||
void testCommitCallback();
|
||||
void testRollbackCallback();
|
||||
void testNotifier();
|
||||
|
||||
void testSessionTransaction();
|
||||
void testTransaction();
|
||||
void testTransactor();
|
||||
|
||||
void testFTS3();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static void sqliteUpdateCallbackFn(void*, int, const char*, const char*, Poco::Int64);
|
||||
static int sqliteCommitCallbackFn(void*);
|
||||
static void sqliteRollbackCallbackFn(void*);
|
||||
|
||||
void onInsert(const void* pSender);
|
||||
void onUpdate(const void* pSender);
|
||||
void onDelete(const void* pSender);
|
||||
void onCommit(const void* pSender);
|
||||
void onRollback(const void* pSender);
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void setTransactionIsolation(Poco::Data::Session& session, Poco::UInt32 ti);
|
||||
|
||||
static int _insertCounter;
|
||||
static int _updateCounter;
|
||||
static int _deleteCounter;
|
||||
|
||||
int _commitCounter;
|
||||
int _rollbackCounter;
|
||||
};
|
||||
|
||||
|
||||
#endif // SQLiteTest_INCLUDED
|
@ -1,24 +0,0 @@
|
||||
//
|
||||
// SQLiteTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "SQLiteTestSuite.h"
|
||||
#include "SQLiteTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* SQLiteTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SQLiteTestSuite");
|
||||
|
||||
pSuite->addTest(SQLiteTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
//
|
||||
// SQLiteTestSuite.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the SQLiteTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLiteTestSuite_INCLUDED
|
||||
#define SQLiteTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class SQLiteTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // SQLiteTestSuite_INCLUDED
|
@ -1,32 +0,0 @@
|
||||
//
|
||||
// WinCEDriver.cpp
|
||||
//
|
||||
// $Id: //poco/1.3-WinCE/Net/testsuite/src/WinCEDriver.cpp#2 $
|
||||
//
|
||||
// Console-based test driver for Windows CE.
|
||||
//
|
||||
// Copyright (c) 2004-2010, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "SQLiteTestSuite.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
int wmain(int argc, wchar_t* argv[])
|
||||
{
|
||||
std::vector<std::string> args;
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
char buffer[1024];
|
||||
std::wcstombs(buffer, argv[i], sizeof(buffer));
|
||||
args.push_back(std::string(buffer));
|
||||
}
|
||||
CppUnit::TestRunner runner;
|
||||
runner.addTest("SQLiteTestSuite", SQLiteTestSuite::suite());
|
||||
return runner.run(args) ? 0 : 1;
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
//
|
||||
// WinDriver.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/WinDriver.cpp#2 $
|
||||
//
|
||||
// Windows test driver for Poco SQLite.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
//
|
||||
|
||||
|
||||
#include "WinTestRunner/WinTestRunner.h"
|
||||
#include "SQLiteTestSuite.h"
|
||||
|
||||
|
||||
class TestDriver: public CppUnit::WinTestRunnerApp
|
||||
{
|
||||
void TestMain()
|
||||
{
|
||||
CppUnit::WinTestRunner runner;
|
||||
runner.addTest(SQLiteTestSuite::suite());
|
||||
runner.run();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TestDriver theDriver;
|
@ -124,7 +124,7 @@ inline const std::string& AbstractBinding::name() const
|
||||
|
||||
inline AbstractBinder::Direction AbstractBinding::getDirection() const
|
||||
{
|
||||
return (AbstractBinder::Direction) _direction;
|
||||
return static_cast<AbstractBinder::Direction>(_direction);
|
||||
}
|
||||
|
||||
|
||||
|
@ -390,7 +390,7 @@ public:
|
||||
/// to start iteration from beginning or end,
|
||||
/// depending on the position requested.
|
||||
{
|
||||
if (row <= (std::size_t) (_pData->size() / 2))
|
||||
if (row <= static_cast<std::size_t>(_pData->size() / 2))
|
||||
{
|
||||
Iterator it = _pData->begin();
|
||||
Iterator end = _pData->end();
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
LIMIT_UNLIMITED = ~((SizeT) 0)
|
||||
LIMIT_UNLIMITED = ~(static_cast<SizeT>(0))
|
||||
};
|
||||
|
||||
Limit(SizeT value, bool hardLimit = false, bool isLowerLimit = false);
|
||||
|
@ -91,7 +91,7 @@ inline int PooledSessionHolder::idle() const
|
||||
{
|
||||
Poco::FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
return (int) (_lastUsed.elapsed()/Poco::Timestamp::resolution());
|
||||
return static_cast<int>(_lastUsed.elapsed()/Poco::Timestamp::resolution());
|
||||
}
|
||||
|
||||
|
||||
|
@ -176,10 +176,10 @@ struct poco_static_assert_test
|
||||
#if defined(__GNUC__) && (__GNUC__ == 3) && ((__GNUC_MINOR__ == 3) || (__GNUC_MINOR__ == 4))
|
||||
#define poco_static_assert(B) \
|
||||
typedef char POCO_JOIN(poco_static_assert_typedef_, __LINE__) \
|
||||
[POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>::value]
|
||||
[POCO_STATIC_ASSERTION_FAILURE<static_cast<bool>(B)>::value]
|
||||
#else
|
||||
#define poco_static_assert(B) \
|
||||
typedef poco_static_assert_test<sizeof(POCO_STATIC_ASSERTION_FAILURE<(bool) (B)>)> \
|
||||
typedef poco_static_assert_test<sizeof(POCO_STATIC_ASSERTION_FAILURE<static_cast<bool>(B)>)> \
|
||||
POCO_JOIN(poco_static_assert_typedef_, __LINE__)
|
||||
#endif
|
||||
|
||||
|
@ -87,7 +87,7 @@ inline bool FPEnvironmentImpl::isInfiniteImpl(double value)
|
||||
|
||||
inline bool FPEnvironmentImpl::isInfiniteImpl(long double value)
|
||||
{
|
||||
return std::isinf((double) value) != 0;
|
||||
return std::isinf(static_cast<double>(value)) != 0;
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ inline bool FPEnvironmentImpl::isNaNImpl(double value)
|
||||
|
||||
inline bool FPEnvironmentImpl::isNaNImpl(long double value)
|
||||
{
|
||||
return std::isnan((double) value) != 0;
|
||||
return std::isnan(static_cast<double>(value)) != 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -368,13 +368,13 @@ inline Timestamp LocalDateTime::timestamp() const
|
||||
|
||||
inline Timestamp::UtcTimeVal LocalDateTime::utcTime() const
|
||||
{
|
||||
return _dateTime.utcTime() - ((Timestamp::TimeDiff) _tzd)*10000000;
|
||||
return _dateTime.utcTime() - (static_cast<Timestamp::TimeDiff>(_tzd))*10000000;
|
||||
}
|
||||
|
||||
|
||||
inline void LocalDateTime::adjustForTzd()
|
||||
{
|
||||
_dateTime += Timespan(((Timestamp::TimeDiff) _tzd)*Timespan::SECONDS);
|
||||
_dateTime += Timespan((static_cast<Timestamp::TimeDiff>(_tzd))*Timespan::SECONDS);
|
||||
}
|
||||
|
||||
|
||||
|
@ -132,7 +132,7 @@ public:
|
||||
|
||||
if (newoff + off < 0 || (this->epptr() - this->pbase()) < newoff + off)
|
||||
return fail;
|
||||
this->pbump((int)(newoff + off - (this->pptr() - this->pbase())));
|
||||
this->pbump(static_cast<int>(newoff + off - (this->pptr() - this->pbase())));
|
||||
}
|
||||
|
||||
return newoff;
|
||||
|
@ -26,6 +26,8 @@
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/Event.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
|
||||
@ -140,7 +142,7 @@ private:
|
||||
std::string _name;
|
||||
TaskManager* _pOwner;
|
||||
float _progress;
|
||||
TaskState _state;
|
||||
std::atomic<TaskState> _state;
|
||||
Event _cancelEvent;
|
||||
mutable FastMutex _mutex;
|
||||
|
||||
|
@ -129,7 +129,7 @@ inline int TaskManager::count() const
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
|
||||
return (int) _taskList.size();
|
||||
return static_cast<int>(_taskList.size());
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
#include "Poco/Task.h"
|
||||
#include "Poco/TaskManager.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace Poco {
|
||||
|
||||
@ -61,8 +61,17 @@ void Task::run()
|
||||
pOwner->taskStarted(this);
|
||||
try
|
||||
{
|
||||
_state = TASK_RUNNING;
|
||||
runTask();
|
||||
/** Task can be already cancelled.
|
||||
* To prevent endless executing already cancelled task _state is assigned to TASK_RUNNING only if _state != TASK_CANCELLING
|
||||
*/
|
||||
std::array<TaskState, 3> allowed_states{TASK_IDLE, TASK_STARTING, TASK_FINISHED};
|
||||
for (auto & expected : allowed_states)
|
||||
if (_state.compare_exchange_strong(expected, TASK_RUNNING))
|
||||
break;
|
||||
|
||||
if (_state == TASK_RUNNING)
|
||||
runTask();
|
||||
|
||||
}
|
||||
catch (Exception& exc)
|
||||
{
|
||||
|
@ -115,7 +115,7 @@ inline const XMLString& CharacterData::getData() const
|
||||
|
||||
inline unsigned long CharacterData::length() const
|
||||
{
|
||||
return (unsigned long) _data.length();
|
||||
return static_cast<unsigned long>(_data.length());
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,19 +9,24 @@ if ($ENV{DISABLE_MONGODB})
|
||||
set (DISABLE_MONGODB TRUE)
|
||||
endif()
|
||||
|
||||
if (${DISABLE_MONGODB})
|
||||
if (DISABLE_MONGODB)
|
||||
add_definitions(-D DISABLE_MONGODB)
|
||||
else()
|
||||
set (LINK_MONGOCLIENT libmongoclient.a libssl.a libcrypto.a libboost_thread.a)
|
||||
endif()
|
||||
|
||||
|
||||
add_library(string_utils
|
||||
include/DB/Common/StringUtils.h
|
||||
src/Common/StringUtils.cpp)
|
||||
|
||||
add_library (dbms
|
||||
src/Server/InterserverIOHTTPHandler.h
|
||||
src/Server/Server.h
|
||||
src/Server/TCPHandler.h
|
||||
src/Server/HTTPHandler.h
|
||||
src/Server/MetricsTransmitter.h
|
||||
src/Server/UsersConfigReloader.h
|
||||
src/Server/ConfigReloader.h
|
||||
src/Server/StatusFile.h
|
||||
src/Server/ReplicasStatusHandler.h
|
||||
src/Client/InterruptListener.h
|
||||
@ -58,6 +63,7 @@ add_library (dbms
|
||||
include/DB/Functions/FunctionsComparison.h
|
||||
include/DB/Functions/FunctionsHashing.h
|
||||
include/DB/Functions/FunctionsMath.h
|
||||
include/DB/Functions/FunctionsGeo.h
|
||||
include/DB/Functions/FunctionsMiscellaneous.h
|
||||
include/DB/Functions/FunctionsDateTime.h
|
||||
include/DB/Functions/IFunction.h
|
||||
@ -65,6 +71,7 @@ add_library (dbms
|
||||
include/DB/Functions/NumberTraits.h
|
||||
include/DB/Functions/DataTypeTraits.h
|
||||
include/DB/Functions/EnrichedDataTypePtr.h
|
||||
include/DB/Functions/ObjectPool.h
|
||||
include/DB/TableFunctions/TableFunctionRemote.h
|
||||
include/DB/TableFunctions/TableFunctionFactory.h
|
||||
include/DB/TableFunctions/TableFunctionMerge.h
|
||||
@ -322,7 +329,6 @@ add_library (dbms
|
||||
include/DB/Interpreters/AggregationCommon.h
|
||||
include/DB/Interpreters/ProcessList.h
|
||||
include/DB/Interpreters/AggregateDescription.h
|
||||
include/DB/Interpreters/reinterpretAsIdentifier.h
|
||||
include/DB/Interpreters/Cluster.h
|
||||
include/DB/Interpreters/loadMetadata.h
|
||||
include/DB/Interpreters/ExternalDictionaries.h
|
||||
@ -434,7 +440,6 @@ add_library (dbms
|
||||
include/DB/Common/getNumberOfPhysicalCPUCores.h
|
||||
include/DB/Common/BitHelpers.h
|
||||
include/DB/Common/BlockFilterCreator.h
|
||||
include/DB/Common/StringUtils.h
|
||||
include/DB/Common/randomSeed.h
|
||||
include/DB/Common/unaligned.h
|
||||
include/DB/Common/ThreadPool.h
|
||||
@ -608,8 +613,8 @@ add_library (dbms
|
||||
src/Common/ShellCommand.cpp
|
||||
src/Common/isLocalAddress.cpp
|
||||
src/Common/getNumberOfPhysicalCPUCores.cpp
|
||||
src/Common/StringUtils.cpp
|
||||
src/Common/randomSeed.cpp
|
||||
src/Common/ThreadPool.cpp
|
||||
|
||||
src/Core/Field.cpp
|
||||
src/Core/FieldVisitors.cpp
|
||||
@ -632,6 +637,7 @@ add_library (dbms
|
||||
src/IO/ReadBufferFromFileBase.cpp
|
||||
src/IO/WriteBufferFromFileBase.cpp
|
||||
src/IO/InterserverWriteBuffer.cpp
|
||||
src/IO/ReadBufferFromHTTP.cpp
|
||||
|
||||
src/Columns/ColumnConst.cpp
|
||||
src/Columns/ColumnArray.cpp
|
||||
@ -763,7 +769,6 @@ add_library (dbms
|
||||
src/DataStreams/SquashingBlockInputStream.cpp
|
||||
src/DataStreams/SquashingBlockOutputStream.cpp
|
||||
src/DataStreams/MaterializingBlockInputStream.cpp
|
||||
src/DataStreams/MaterializingBlockOutputStream.cpp
|
||||
src/DataStreams/NullableAdapterBlockInputStream.cpp
|
||||
|
||||
src/DataTypes/DataTypeString.cpp
|
||||
@ -848,7 +853,6 @@ add_library (dbms
|
||||
src/Interpreters/evaluateMissingDefaults.cpp
|
||||
src/Interpreters/evaluateConstantExpression.cpp
|
||||
src/Interpreters/convertFieldToType.cpp
|
||||
src/Interpreters/reinterpretAsIdentifier.cpp
|
||||
src/Interpreters/Set.cpp
|
||||
src/Interpreters/Join.cpp
|
||||
src/Interpreters/Quota.cpp
|
||||
@ -890,8 +894,10 @@ add_library (dbms
|
||||
src/Functions/FunctionsURL.cpp
|
||||
src/Functions/FunctionsVisitParam.cpp
|
||||
src/Functions/FunctionsMath.cpp
|
||||
src/Functions/FunctionsGeo.cpp
|
||||
src/Functions/FunctionsMiscellaneous.cpp
|
||||
src/Functions/FunctionsTransform.cpp
|
||||
src/Functions/FunctionsCharset.cpp
|
||||
src/Functions/Conditional/getArrayType.cpp
|
||||
src/Functions/Conditional/ArgsInfo.cpp
|
||||
src/Functions/Conditional/CondSource.cpp
|
||||
@ -933,39 +939,42 @@ add_library (dbms
|
||||
src/Client/MultiplexedConnections.cpp
|
||||
)
|
||||
|
||||
# Не генерируем отладочную информацию для файлов с большим количеством инстанцирований шаблонов
|
||||
# - для более быстрой линковки и меньшего размера бинарника.
|
||||
SET_SOURCE_FILES_PROPERTIES(
|
||||
src/Functions/FunctionsArithmetic.cpp
|
||||
src/Functions/FunctionsArray.cpp
|
||||
src/Functions/FunctionsCoding.cpp
|
||||
src/Functions/FunctionsComparison.cpp
|
||||
src/Functions/FunctionsConditional.cpp
|
||||
src/Functions/FunctionsConversion.cpp
|
||||
src/Functions/FunctionsDateTime.cpp
|
||||
src/Functions/FunctionsDictionaries.cpp
|
||||
src/Functions/FunctionsFormatting.cpp
|
||||
src/Functions/FunctionsHashing.cpp
|
||||
src/Functions/FunctionsHigherOrder.cpp
|
||||
src/Functions/FunctionsLogical.cpp
|
||||
src/Functions/FunctionsRandom.cpp
|
||||
src/Functions/FunctionsReinterpret.cpp
|
||||
src/Functions/FunctionsRound.cpp
|
||||
src/Functions/FunctionsString.cpp
|
||||
src/Functions/FunctionsStringArray.cpp
|
||||
src/Functions/FunctionsStringSearch.cpp
|
||||
src/Functions/FunctionsURL.cpp
|
||||
src/Functions/FunctionsVisitParam.cpp
|
||||
src/Functions/FunctionsMath.cpp
|
||||
src/Functions/FunctionsMiscellaneous.cpp
|
||||
src/Functions/FunctionsTransform.cpp
|
||||
src/Dictionaries/FlatDictionary.cpp
|
||||
src/Dictionaries/HashedDictionary.cpp
|
||||
src/Dictionaries/CacheDictionary.cpp
|
||||
src/Dictionaries/RangeHashedDictionary.cpp
|
||||
src/Dictionaries/ComplexKeyHashedDictionary.cpp
|
||||
src/Dictionaries/ComplexKeyCacheDictionary.cpp
|
||||
PROPERTIES COMPILE_FLAGS -g0)
|
||||
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# Не генерируем отладочную информацию для файлов с большим количеством инстанцирований шаблонов
|
||||
# - для более быстрой линковки и меньшего размера бинарника.
|
||||
SET_SOURCE_FILES_PROPERTIES(
|
||||
src/Functions/FunctionsArithmetic.cpp
|
||||
src/Functions/FunctionsArray.cpp
|
||||
src/Functions/FunctionsCoding.cpp
|
||||
src/Functions/FunctionsComparison.cpp
|
||||
src/Functions/FunctionsConditional.cpp
|
||||
src/Functions/FunctionsConversion.cpp
|
||||
src/Functions/FunctionsDateTime.cpp
|
||||
src/Functions/FunctionsDictionaries.cpp
|
||||
src/Functions/FunctionsFormatting.cpp
|
||||
src/Functions/FunctionsHashing.cpp
|
||||
src/Functions/FunctionsHigherOrder.cpp
|
||||
src/Functions/FunctionsLogical.cpp
|
||||
src/Functions/FunctionsRandom.cpp
|
||||
src/Functions/FunctionsReinterpret.cpp
|
||||
src/Functions/FunctionsRound.cpp
|
||||
src/Functions/FunctionsString.cpp
|
||||
src/Functions/FunctionsStringArray.cpp
|
||||
src/Functions/FunctionsStringSearch.cpp
|
||||
src/Functions/FunctionsURL.cpp
|
||||
src/Functions/FunctionsVisitParam.cpp
|
||||
src/Functions/FunctionsMath.cpp
|
||||
src/Functions/FunctionsGeo.cpp
|
||||
src/Functions/FunctionsMiscellaneous.cpp
|
||||
src/Functions/FunctionsTransform.cpp
|
||||
src/Dictionaries/FlatDictionary.cpp
|
||||
src/Dictionaries/HashedDictionary.cpp
|
||||
src/Dictionaries/CacheDictionary.cpp
|
||||
src/Dictionaries/RangeHashedDictionary.cpp
|
||||
src/Dictionaries/ComplexKeyHashedDictionary.cpp
|
||||
src/Dictionaries/ComplexKeyCacheDictionary.cpp
|
||||
PROPERTIES COMPILE_FLAGS -g0)
|
||||
endif()
|
||||
|
||||
IF (NOT AARCH64)
|
||||
SET(LINK_LIBRARIES_ONLY_ON_X86_64 cpuid)
|
||||
@ -977,6 +986,7 @@ target_link_libraries(dbms
|
||||
mysqlxx
|
||||
cityhash farmhash metrohash
|
||||
lz4 zstd
|
||||
string_utils
|
||||
double-conversion
|
||||
${LINK_LIBRARIES_ONLY_ON_X86_64}
|
||||
re2 re2_st
|
||||
|
@ -83,7 +83,7 @@ public:
|
||||
return nested_func->alignOfData();
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||
{
|
||||
const IColumn * nested[num_agruments];
|
||||
|
||||
@ -97,12 +97,12 @@ public:
|
||||
size_t end = offsets[row_num];
|
||||
|
||||
for (size_t i = begin; i < end; ++i)
|
||||
nested_func->add(place, nested, i);
|
||||
nested_func->add(place, nested, i, nullptr);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
nested_func->merge(place, rhs);
|
||||
nested_func->merge(place, rhs, arena);
|
||||
}
|
||||
|
||||
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
||||
@ -110,9 +110,9 @@ public:
|
||||
nested_func->serialize(place, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena * arena) const override
|
||||
{
|
||||
nested_func->deserialize(place, buf);
|
||||
nested_func->deserialize(place, buf, arena);
|
||||
}
|
||||
|
||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||
@ -120,9 +120,9 @@ public:
|
||||
nested_func->insertResultInto(place, to);
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const AggregateFunctionArray &>(*that).add(place, columns, row_num);
|
||||
static_cast<const AggregateFunctionArray &>(*that).add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
||||
|
@ -42,13 +42,13 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).sum += static_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
||||
++this->data(place).count;
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).sum += this->data(rhs).sum;
|
||||
this->data(place).count += this->data(rhs).count;
|
||||
@ -60,7 +60,7 @@ public:
|
||||
writeVarUInt(this->data(place).count, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
readBinary(this->data(place).sum, buf);
|
||||
readVarUInt(this->data(place).count, buf);
|
||||
|
@ -36,7 +36,7 @@ public:
|
||||
++data(place).count;
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
data(place).count += data(rhs).count;
|
||||
}
|
||||
@ -46,7 +46,7 @@ public:
|
||||
writeVarUInt(data(place).count, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
readVarUInt(data(place).count, buf);
|
||||
}
|
||||
|
@ -51,12 +51,12 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).value.push_back(static_cast<const ColumnVector<T> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).value.insert(this->data(rhs).value.begin(), this->data(rhs).value.end());
|
||||
}
|
||||
@ -69,7 +69,7 @@ public:
|
||||
buf.write(reinterpret_cast<const char *>(&value[0]), size * sizeof(value[0]));
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
size_t size = 0;
|
||||
readVarUInt(size, buf);
|
||||
@ -128,13 +128,13 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
data(place).value.push_back(Array::value_type());
|
||||
column.get(row_num, data(place).value.back());
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
data(place).value.insert(data(place).value.end(), data(rhs).value.begin(), data(rhs).value.end());
|
||||
}
|
||||
@ -148,7 +148,7 @@ public:
|
||||
type->serializeBinary(value[i], buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
size_t size = 0;
|
||||
readVarUInt(size, buf);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include <DB/DataTypes/DataTypeArray.h>
|
||||
#include <DB/DataTypes/DataTypesNumberFixed.h>
|
||||
#include <DB/DataTypes/DataTypeString.h>
|
||||
|
||||
#include <DB/Columns/ColumnArray.h>
|
||||
|
||||
@ -23,12 +24,12 @@ template <typename T>
|
||||
struct AggregateFunctionGroupUniqArrayData
|
||||
{
|
||||
/// При создании, хэш-таблица должна быть небольшой.
|
||||
typedef HashSet<
|
||||
using Set = HashSet<
|
||||
T,
|
||||
DefaultHash<T>,
|
||||
HashTableGrower<4>,
|
||||
HashTableAllocatorWithStackMemory<sizeof(T) * (1 << 4)>
|
||||
> Set;
|
||||
>;
|
||||
|
||||
Set value;
|
||||
};
|
||||
@ -55,26 +56,26 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).value.insert(static_cast<const ColumnVector<T> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).value.merge(this->data(rhs).value);
|
||||
}
|
||||
|
||||
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
||||
{
|
||||
const typename State::Set & set = this->data(place).value;
|
||||
auto & set = this->data(place).value;
|
||||
size_t size = set.size();
|
||||
writeVarUInt(size, buf);
|
||||
for (typename State::Set::const_iterator it = set.begin(); it != set.end(); ++it)
|
||||
writeIntBinary(*it, buf);
|
||||
for (auto & elem : set)
|
||||
writeIntBinary(elem, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).value.read(buf);
|
||||
}
|
||||
@ -94,11 +95,159 @@ public:
|
||||
data_to.resize(old_size + size);
|
||||
|
||||
size_t i = 0;
|
||||
for (typename State::Set::const_iterator it = set.begin(); it != set.end(); ++it, ++i)
|
||||
for (auto it = set.begin(); it != set.end(); ++it, ++i)
|
||||
data_to[old_size + i] = *it;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// Generic implementation, it uses serialized representation as object descriptor.
|
||||
struct AggreagteFunctionGroupUniqArrayGenericData
|
||||
{
|
||||
static constexpr size_t INIT_ELEMS = 2; /// adjustable
|
||||
static constexpr size_t ELEM_SIZE = sizeof(HashSetCellWithSavedHash<StringRef, StringRefHash>);
|
||||
using Set = HashSetWithSavedHash<StringRef, StringRefHash, HashTableGrower<INIT_ELEMS>, HashTableAllocatorWithStackMemory<INIT_ELEMS * ELEM_SIZE>>;
|
||||
|
||||
Set value;
|
||||
};
|
||||
|
||||
/** Template parameter with true value should be used for columns that store their elements in memory continuously.
|
||||
* For such columns groupUniqArray() can be implemented more efficently (especially for small numeric arrays).
|
||||
*/
|
||||
template <bool is_plain_column = false>
|
||||
class AggreagteFunctionGroupUniqArrayGeneric : public IUnaryAggregateFunction<AggreagteFunctionGroupUniqArrayGenericData, AggreagteFunctionGroupUniqArrayGeneric<is_plain_column>>
|
||||
{
|
||||
DataTypePtr input_data_type;
|
||||
|
||||
using State = AggreagteFunctionGroupUniqArrayGenericData;
|
||||
|
||||
static StringRef getSerialization(const IColumn & column, size_t row_num, Arena & arena);
|
||||
|
||||
static void deserializeAndInsert(StringRef str, IColumn & data_to);
|
||||
|
||||
public:
|
||||
|
||||
String getName() const override { return "groupUniqArray"; }
|
||||
|
||||
void setArgument(const DataTypePtr & argument)
|
||||
{
|
||||
input_data_type = argument;
|
||||
}
|
||||
|
||||
DataTypePtr getReturnType() const override
|
||||
{
|
||||
return std::make_shared<DataTypeArray>(input_data_type->clone());
|
||||
}
|
||||
|
||||
bool allocatesMemoryInArena() const override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
||||
{
|
||||
auto & set = this->data(place).value;
|
||||
writeVarUInt(set.size(), buf);
|
||||
|
||||
for (const auto & elem : set)
|
||||
{
|
||||
writeStringBinary(elem, buf);
|
||||
}
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena * arena) const override
|
||||
{
|
||||
auto & set = this->data(place).value;
|
||||
size_t size;
|
||||
readVarUInt(size, buf);
|
||||
//TODO: set.reserve(size);
|
||||
|
||||
for (size_t i = 0; i < size; i++)
|
||||
{
|
||||
set.insert(readStringBinaryInto(*arena, buf));
|
||||
}
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena * arena) const
|
||||
{
|
||||
auto & set = this->data(place).value;
|
||||
|
||||
bool inserted;
|
||||
State::Set::iterator it;
|
||||
|
||||
StringRef str_serialized = getSerialization(column, row_num, *arena);
|
||||
set.emplace(str_serialized, it, inserted);
|
||||
|
||||
if (!is_plain_column)
|
||||
{
|
||||
if (!inserted)
|
||||
arena->rollback(str_serialized.size);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (inserted)
|
||||
it->data = arena->insert(str_serialized.data, str_serialized.size);
|
||||
}
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
auto & cur_set = this->data(place).value;
|
||||
auto & rhs_set = this->data(rhs).value;
|
||||
|
||||
bool inserted;
|
||||
State::Set::iterator it;
|
||||
for (auto & rhs_elem : rhs_set)
|
||||
{
|
||||
cur_set.emplace(rhs_elem, it, inserted);
|
||||
if (inserted)
|
||||
it->data = arena->insert(it->data, it->size);
|
||||
}
|
||||
}
|
||||
|
||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||
{
|
||||
ColumnArray & arr_to = static_cast<ColumnArray &>(to);
|
||||
ColumnArray::Offsets_t & offsets_to = arr_to.getOffsets();
|
||||
IColumn & data_to = arr_to.getData();
|
||||
|
||||
auto & set = this->data(place).value;
|
||||
offsets_to.push_back((offsets_to.size() == 0 ? 0 : offsets_to.back()) + set.size());
|
||||
|
||||
for (auto & elem : set)
|
||||
{
|
||||
deserializeAndInsert(elem, data_to);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
inline StringRef AggreagteFunctionGroupUniqArrayGeneric<false>::getSerialization(const IColumn & column, size_t row_num, Arena & arena)
|
||||
{
|
||||
const char * begin = nullptr;
|
||||
return column.serializeValueIntoArena(row_num, arena, begin);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline StringRef AggreagteFunctionGroupUniqArrayGeneric<true>::getSerialization(const IColumn & column, size_t row_num, Arena &)
|
||||
{
|
||||
return column.getDataAt(row_num);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void AggreagteFunctionGroupUniqArrayGeneric<false>::deserializeAndInsert(StringRef str, IColumn & data_to)
|
||||
{
|
||||
data_to.deserializeAndInsertFromArena(str.data);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void AggreagteFunctionGroupUniqArrayGeneric<true>::deserializeAndInsert(StringRef str, IColumn & data_to)
|
||||
{
|
||||
data_to.insertData(str.data, str.size);
|
||||
}
|
||||
|
||||
|
||||
#undef AGGREGATE_FUNCTION_GROUP_ARRAY_UNIQ_MAX_SIZE
|
||||
|
||||
}
|
||||
|
@ -77,15 +77,15 @@ public:
|
||||
return nested_func->alignOfData();
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||
{
|
||||
if (static_cast<const ColumnUInt8 &>(*columns[num_agruments - 1]).getData()[row_num])
|
||||
nested_func->add(place, columns, row_num);
|
||||
nested_func->add(place, columns, row_num, nullptr);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
nested_func->merge(place, rhs);
|
||||
nested_func->merge(place, rhs, arena);
|
||||
}
|
||||
|
||||
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
||||
@ -93,9 +93,9 @@ public:
|
||||
nested_func->serialize(place, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena * arena) const override
|
||||
{
|
||||
nested_func->deserialize(place, buf);
|
||||
nested_func->deserialize(place, buf, arena);
|
||||
}
|
||||
|
||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||
@ -103,9 +103,9 @@ public:
|
||||
nested_func->insertResultInto(place, to);
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const AggregateFunctionIf &>(*that).add(place, columns, row_num);
|
||||
static_cast<const AggregateFunctionIf &>(*that).add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
||||
|
@ -79,14 +79,14 @@ public:
|
||||
return nested_func->alignOfData();
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
||||
{
|
||||
nested_func->merge(place, static_cast<const ColumnAggregateFunction &>(*columns[0]).getData()[row_num]);
|
||||
nested_func->merge(place, static_cast<const ColumnAggregateFunction &>(*columns[0]).getData()[row_num], arena);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
nested_func->merge(place, rhs);
|
||||
nested_func->merge(place, rhs, arena);
|
||||
}
|
||||
|
||||
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
||||
@ -94,9 +94,9 @@ public:
|
||||
nested_func->serialize(place, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena * arena) const override
|
||||
{
|
||||
nested_func->deserialize(place, buf);
|
||||
nested_func->deserialize(place, buf, arena);
|
||||
}
|
||||
|
||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||
@ -104,9 +104,9 @@ public:
|
||||
nested_func->insertResultInto(place, to);
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const AggregateFunctionMerge &>(*that).add(place, columns, row_num);
|
||||
static_cast<const AggregateFunctionMerge &>(*that).add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
||||
|
@ -95,7 +95,7 @@ public:
|
||||
return nested_function->alignOfData();
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
||||
{
|
||||
/// This container stores the columns we really pass to the nested function.
|
||||
const IColumn * passed_columns[argument_count];
|
||||
@ -117,12 +117,12 @@ public:
|
||||
passed_columns[i] = columns[i];
|
||||
}
|
||||
|
||||
nested_function->add(place, passed_columns, row_num);
|
||||
nested_function->add(place, passed_columns, row_num, arena);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
nested_function->merge(place, rhs);
|
||||
nested_function->merge(place, rhs, arena);
|
||||
}
|
||||
|
||||
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
||||
@ -130,9 +130,9 @@ public:
|
||||
nested_function->serialize(place, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena * arena) const override
|
||||
{
|
||||
nested_function->deserialize(place, buf);
|
||||
nested_function->deserialize(place, buf, arena);
|
||||
}
|
||||
|
||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||
@ -140,9 +140,10 @@ public:
|
||||
nested_function->insertResultInto(place, to);
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place,
|
||||
const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const AggregateFunctionNull &>(*that).add(place, columns, row_num);
|
||||
return static_cast<const AggregateFunctionNull &>(*that).add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
AddFunc getAddressOfAddFunction() const override
|
||||
|
@ -68,12 +68,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).sample.insert(static_cast<const ColumnVector<ArgumentFieldType> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).sample.merge(this->data(rhs).sample);
|
||||
}
|
||||
@ -83,7 +83,7 @@ public:
|
||||
this->data(place).sample.write(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).sample.read(buf);
|
||||
}
|
||||
@ -145,12 +145,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).sample.insert(static_cast<const ColumnVector<ArgumentFieldType> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).sample.merge(this->data(rhs).sample);
|
||||
}
|
||||
@ -160,7 +160,7 @@ public:
|
||||
this->data(place).sample.write(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).sample.read(buf);
|
||||
}
|
||||
|
@ -74,13 +74,13 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, const IColumn & determinator, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, const IColumn & determinator, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).sample.insert(static_cast<const ColumnVector<ArgumentFieldType> &>(column).getData()[row_num],
|
||||
determinator.get64(row_num));
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).sample.merge(this->data(rhs).sample);
|
||||
}
|
||||
@ -90,7 +90,7 @@ public:
|
||||
this->data(place).sample.write(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).sample.read(buf);
|
||||
}
|
||||
@ -158,13 +158,13 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, const IColumn & determinator, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, const IColumn & determinator, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).sample.insert(static_cast<const ColumnVector<ArgumentFieldType> &>(column).getData()[row_num],
|
||||
determinator.get64(row_num));
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).sample.merge(this->data(rhs).sample);
|
||||
}
|
||||
@ -174,7 +174,7 @@ public:
|
||||
this->data(place).sample.write(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).sample.read(buf);
|
||||
}
|
||||
|
@ -68,12 +68,12 @@ public:
|
||||
level = apply_visitor(FieldVisitorConvertToNumber<Float64>(), params[0]);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).array.push_back(static_cast<const ColumnVector<T> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).array.insert(this->data(rhs).array.begin(), this->data(rhs).array.end());
|
||||
}
|
||||
@ -87,7 +87,7 @@ public:
|
||||
buf.write(reinterpret_cast<const char *>(&array[0]), size * sizeof(array[0]));
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
auto & array = this->data(place).array;
|
||||
|
||||
@ -150,12 +150,12 @@ public:
|
||||
levels.set(params);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).array.push_back(static_cast<const ColumnVector<T> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).array.insert(this->data(rhs).array.begin(), this->data(rhs).array.end());
|
||||
}
|
||||
@ -169,7 +169,7 @@ public:
|
||||
buf.write(reinterpret_cast<const char *>(&array[0]), size * sizeof(array[0]));
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
auto & array = this->data(place).array;
|
||||
|
||||
|
@ -74,14 +74,14 @@ public:
|
||||
level = apply_visitor(FieldVisitorConvertToNumber<Float64>(), params[0]);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place)
|
||||
.map[static_cast<const ColumnVector<ValueType> &>(column_value).getData()[row_num]]
|
||||
+= static_cast<const ColumnVector<WeightType> &>(column_weight).getData()[row_num];
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
auto & map = this->data(place).map;
|
||||
const auto & rhs_map = this->data(rhs).map;
|
||||
@ -95,7 +95,7 @@ public:
|
||||
this->data(place).map.write(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
typename AggregateFunctionQuantileExactWeightedData<ValueType>::Map::Reader reader(buf);
|
||||
|
||||
@ -189,14 +189,14 @@ public:
|
||||
levels.set(params);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place)
|
||||
.map[static_cast<const ColumnVector<ValueType> &>(column_value).getData()[row_num]]
|
||||
+= static_cast<const ColumnVector<WeightType> &>(column_weight).getData()[row_num];
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
auto & map = this->data(place).map;
|
||||
const auto & rhs_map = this->data(rhs).map;
|
||||
@ -210,7 +210,7 @@ public:
|
||||
this->data(place).map.write(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
typename AggregateFunctionQuantileExactWeightedData<ValueType>::Map::Reader reader(buf);
|
||||
|
||||
|
@ -382,12 +382,12 @@ public:
|
||||
level = apply_visitor(FieldVisitorConvertToNumber<Float32>(), params[0]);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).digest.add(params, static_cast<const ColumnVector<T> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).digest.merge(params, this->data(rhs).digest);
|
||||
}
|
||||
@ -397,7 +397,7 @@ public:
|
||||
this->data(const_cast<AggregateDataPtr>(place)).digest.write(params, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).digest.read(params, buf);
|
||||
}
|
||||
@ -449,14 +449,14 @@ public:
|
||||
level = apply_visitor(FieldVisitorConvertToNumber<Float32>(), params[0]);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).digest.add(params,
|
||||
static_cast<const ColumnVector<T> &>(column_value).getData()[row_num],
|
||||
static_cast<const ColumnVector<Weight> &>(column_weight).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).digest.merge(params, this->data(rhs).digest);
|
||||
}
|
||||
@ -466,7 +466,7 @@ public:
|
||||
this->data(const_cast<AggregateDataPtr>(place)).digest.write(params, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).digest.read(params, buf);
|
||||
}
|
||||
@ -513,12 +513,12 @@ public:
|
||||
levels.set(params);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).digest.add(params, static_cast<const ColumnVector<T> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).digest.merge(params, this->data(rhs).digest);
|
||||
}
|
||||
@ -528,7 +528,7 @@ public:
|
||||
this->data(const_cast<AggregateDataPtr>(place)).digest.write(params, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).digest.read(params, buf);
|
||||
}
|
||||
@ -593,14 +593,14 @@ public:
|
||||
levels.set(params);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).digest.add(params,
|
||||
static_cast<const ColumnVector<T> &>(column_value).getData()[row_num],
|
||||
static_cast<const ColumnVector<Weight> &>(column_weight).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).digest.merge(params, this->data(rhs).digest);
|
||||
}
|
||||
@ -610,7 +610,7 @@ public:
|
||||
this->data(const_cast<AggregateDataPtr>(place)).digest.write(params, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).digest.read(params, buf);
|
||||
}
|
||||
|
@ -815,12 +815,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).insert(static_cast<const ColumnVector<ArgumentFieldType> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).merge(this->data(rhs));
|
||||
}
|
||||
@ -830,7 +830,7 @@ public:
|
||||
this->data(place).serialize(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).deserialize(buf);
|
||||
}
|
||||
@ -873,14 +873,14 @@ public:
|
||||
level = apply_visitor(FieldVisitorConvertToNumber<Float64>(), params[0]);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).insertWeighted(
|
||||
static_cast<const ColumnVector<ArgumentFieldType> &>(column_value).getData()[row_num],
|
||||
static_cast<const ColumnVector<WeightFieldType> &>(column_weight).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).merge(this->data(rhs));
|
||||
}
|
||||
@ -890,7 +890,7 @@ public:
|
||||
this->data(place).serialize(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).deserialize(buf);
|
||||
}
|
||||
@ -930,12 +930,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).insert(static_cast<const ColumnVector<ArgumentFieldType> &>(column).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).merge(this->data(rhs));
|
||||
}
|
||||
@ -945,7 +945,7 @@ public:
|
||||
this->data(place).serialize(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).deserialize(buf);
|
||||
}
|
||||
@ -991,14 +991,14 @@ public:
|
||||
levels.set(params);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_value, const IColumn & column_weight, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).insertWeighted(
|
||||
static_cast<const ColumnVector<ArgumentFieldType> &>(column_value).getData()[row_num],
|
||||
static_cast<const ColumnVector<WeightFieldType> &>(column_weight).getData()[row_num]);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).merge(this->data(rhs));
|
||||
}
|
||||
@ -1008,7 +1008,7 @@ public:
|
||||
this->data(place).serialize(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).deserialize(buf);
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ public:
|
||||
parsePattern();
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num) const override
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena *) const override
|
||||
{
|
||||
const auto timestamp = static_cast<const ColumnUInt32 *>(columns[0])->getData()[row_num];
|
||||
|
||||
@ -206,7 +206,7 @@ public:
|
||||
data(place).add(timestamp, events);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
data(place).merge(data(rhs));
|
||||
}
|
||||
@ -216,7 +216,7 @@ public:
|
||||
data(place).serialize(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
data(place).deserialize(buf);
|
||||
}
|
||||
@ -234,9 +234,9 @@ public:
|
||||
static_cast<ColumnUInt8 &>(to).getData().push_back(match(events_it, events_end));
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const AggregateFunctionSequenceMatch &>(*that).add(place, columns, row_num);
|
||||
static_cast<const AggregateFunctionSequenceMatch &>(*that).add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
||||
|
@ -72,14 +72,14 @@ public:
|
||||
return nested_func->alignOfData();
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override
|
||||
{
|
||||
nested_func->add(place, columns, row_num);
|
||||
nested_func->add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
nested_func->merge(place, rhs);
|
||||
nested_func->merge(place, rhs, arena);
|
||||
}
|
||||
|
||||
void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const override
|
||||
@ -87,9 +87,9 @@ public:
|
||||
nested_func->serialize(place, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena * arena) const override
|
||||
{
|
||||
nested_func->deserialize(place, buf);
|
||||
nested_func->deserialize(place, buf, arena);
|
||||
}
|
||||
|
||||
void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const override
|
||||
@ -102,9 +102,9 @@ public:
|
||||
|
||||
AggregateFunctionPtr getNestedFunction() const { return nested_func_owner; }
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const AggregateFunctionState &>(*that).add(place, columns, row_num);
|
||||
static_cast<const AggregateFunctionState &>(*that).add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
||||
|
@ -40,12 +40,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).sum += static_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).sum += this->data(rhs).sum;
|
||||
}
|
||||
@ -55,7 +55,7 @@ public:
|
||||
writeBinary(this->data(place).sum, buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
readBinary(this->data(place).sum, buf);
|
||||
}
|
||||
|
@ -340,12 +340,12 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
detail::OneAdder<T, Data>::addImpl(this->data(place), column, row_num);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).set.merge(this->data(rhs).set);
|
||||
}
|
||||
@ -355,7 +355,7 @@ public:
|
||||
this->data(place).set.write(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).set.read(buf);
|
||||
}
|
||||
@ -395,12 +395,12 @@ public:
|
||||
num_args = arguments.size();
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||
{
|
||||
this->data(place).set.insert(UniqVariadicHash<is_exact, argument_is_tuple>::apply(num_args, columns, row_num));
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).set.merge(this->data(rhs).set);
|
||||
}
|
||||
@ -410,7 +410,7 @@ public:
|
||||
this->data(place).set.write(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).set.read(buf);
|
||||
}
|
||||
@ -420,9 +420,9 @@ public:
|
||||
static_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).set.size());
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const AggregateFunctionUniqVariadic &>(*that).add(place, columns, row_num);
|
||||
static_cast<const AggregateFunctionUniqVariadic &>(*that).add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
||||
|
@ -151,12 +151,12 @@ public:
|
||||
threshold = threshold_param;
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).addImpl(column, row_num, threshold);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).merge(this->data(rhs), threshold);
|
||||
}
|
||||
@ -166,7 +166,7 @@ public:
|
||||
this->data(place).write(buf, threshold);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).read(buf, threshold);
|
||||
}
|
||||
@ -224,12 +224,12 @@ public:
|
||||
threshold = threshold_param;
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override
|
||||
{
|
||||
this->data(place).insert(UniqVariadicHash<false, argument_is_tuple>::apply(num_args, columns, row_num), threshold);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).merge(this->data(rhs), threshold);
|
||||
}
|
||||
@ -239,7 +239,7 @@ public:
|
||||
this->data(place).write(buf, threshold);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).read(buf, threshold);
|
||||
}
|
||||
@ -249,9 +249,9 @@ public:
|
||||
static_cast<ColumnUInt64 &>(to).getData().push_back(this->data(place).size());
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *arena)
|
||||
{
|
||||
return static_cast<const AggregateFunctionUniqUpToVariadic &>(*that).add(place, columns, row_num);
|
||||
static_cast<const AggregateFunctionUniqUpToVariadic &>(*that).add(place, columns, row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
||||
|
@ -41,13 +41,13 @@ public:
|
||||
type_val = arguments[1];
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_arg, const IColumn & column_max, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_arg, const IColumn & column_max, size_t row_num, Arena *) const
|
||||
{
|
||||
if (this->data(place).value.changeIfBetter(column_max, row_num))
|
||||
this->data(place).result.change(column_arg, row_num);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
if (this->data(place).value.changeIfBetter(this->data(rhs).value))
|
||||
this->data(place).result.change(this->data(rhs).result);
|
||||
@ -59,7 +59,7 @@ public:
|
||||
this->data(place).value.write(buf, *type_val.get());
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).result.read(buf, *type_res.get());
|
||||
this->data(place).value.read(buf, *type_val.get());
|
||||
|
@ -62,6 +62,7 @@ struct SingleValueDataFixed
|
||||
value = static_cast<const ColumnVector<T> &>(column).getData()[row_num];
|
||||
}
|
||||
|
||||
/// Assuming to.has()
|
||||
void change(const Self & to)
|
||||
{
|
||||
has_value = true;
|
||||
@ -81,7 +82,24 @@ struct SingleValueDataFixed
|
||||
|
||||
bool changeFirstTime(const Self & to)
|
||||
{
|
||||
if (!has())
|
||||
if (!has() && to.has())
|
||||
{
|
||||
change(to);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changeEveryTime(const IColumn & column, size_t row_num)
|
||||
{
|
||||
change(column, row_num);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool changeEveryTime(const Self & to)
|
||||
{
|
||||
if (to.has())
|
||||
{
|
||||
change(to);
|
||||
return true;
|
||||
@ -239,7 +257,7 @@ struct __attribute__((__packed__, __aligned__(1))) SingleValueDataString
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Assuming to.has()
|
||||
void changeImpl(StringRef value)
|
||||
{
|
||||
Int32 value_size = value.size;
|
||||
@ -292,7 +310,24 @@ struct __attribute__((__packed__, __aligned__(1))) SingleValueDataString
|
||||
|
||||
bool changeFirstTime(const Self & to)
|
||||
{
|
||||
if (!has())
|
||||
if (!has() && to.has())
|
||||
{
|
||||
change(to);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changeEveryTime(const IColumn & column, size_t row_num)
|
||||
{
|
||||
change(column, row_num);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool changeEveryTime(const Self & to)
|
||||
{
|
||||
if (to.has())
|
||||
{
|
||||
change(to);
|
||||
return true;
|
||||
@ -424,7 +459,24 @@ struct SingleValueDataGeneric
|
||||
|
||||
bool changeFirstTime(const Self & to)
|
||||
{
|
||||
if (!has())
|
||||
if (!has() && to.has())
|
||||
{
|
||||
change(to);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
bool changeEveryTime(const IColumn & column, size_t row_num)
|
||||
{
|
||||
change(column, row_num);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool changeEveryTime(const Self & to)
|
||||
{
|
||||
if (to.has())
|
||||
{
|
||||
change(to);
|
||||
return true;
|
||||
@ -552,8 +604,8 @@ struct AggregateFunctionAnyLastData : Data
|
||||
{
|
||||
using Self = AggregateFunctionAnyLastData<Data>;
|
||||
|
||||
bool changeIfBetter(const IColumn & column, size_t row_num) { this->change(column, row_num); return true; }
|
||||
bool changeIfBetter(const Self & to) { this->change(to); return true; }
|
||||
bool changeIfBetter(const IColumn & column, size_t row_num) { return this->changeEveryTime(column, row_num); }
|
||||
bool changeIfBetter(const Self & to) { return this->changeEveryTime(to); }
|
||||
|
||||
static const char * name() { return "anyLast"; }
|
||||
};
|
||||
@ -649,12 +701,12 @@ public:
|
||||
}
|
||||
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).changeIfBetter(column, row_num);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).changeIfBetter(this->data(rhs));
|
||||
}
|
||||
@ -664,7 +716,7 @@ public:
|
||||
this->data(place).write(buf, *type.get());
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).read(buf, *type.get());
|
||||
}
|
||||
|
@ -129,12 +129,12 @@ public:
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).update(column, row_num);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).mergeWith(this->data(rhs));
|
||||
}
|
||||
@ -144,7 +144,7 @@ public:
|
||||
this->data(place).serialize(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).deserialize(buf);
|
||||
}
|
||||
@ -397,12 +397,12 @@ public:
|
||||
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||||
}
|
||||
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_left, const IColumn & column_right, size_t row_num) const
|
||||
void addImpl(AggregateDataPtr place, const IColumn & column_left, const IColumn & column_right, size_t row_num, Arena *) const
|
||||
{
|
||||
this->data(place).update(column_left, column_right, row_num);
|
||||
}
|
||||
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const override
|
||||
void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const override
|
||||
{
|
||||
this->data(place).mergeWith(this->data(rhs));
|
||||
}
|
||||
@ -412,7 +412,7 @@ public:
|
||||
this->data(place).serialize(buf);
|
||||
}
|
||||
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf) const override
|
||||
void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena *) const override
|
||||
{
|
||||
this->data(place).deserialize(buf);
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <DB/Core/Row.h>
|
||||
#include <DB/DataTypes/IDataType.h>
|
||||
#include <DB/Common/typeid_cast.h>
|
||||
#include <DB/Common/Arena.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
@ -76,19 +77,29 @@ public:
|
||||
/// Как должна быть выровнена структура с данными. NOTE: Сейчас не используется (структуры с состоянием агрегации кладутся без выравнивания).
|
||||
virtual size_t alignOfData() const = 0;
|
||||
|
||||
/// Добавить значение. columns - столбцы, содержащие аргументы, row_num - номер строки в столбцах.
|
||||
virtual void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const = 0;
|
||||
/** Adds a value into aggregation data on which place points to.
|
||||
* columns points to columns containing arguments of aggregation function.
|
||||
* row_num is number of row which should be added.
|
||||
* Additional parameter arena should be used instead of standard memory allocator if the addition requires memory allocation.
|
||||
*/
|
||||
virtual void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const = 0;
|
||||
|
||||
/// Объединить состояние с другим состоянием.
|
||||
virtual void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs) const = 0;
|
||||
/// Merges state (on which place points to) with other state of current aggregation function.
|
||||
virtual void merge(AggregateDataPtr place, ConstAggregateDataPtr rhs, Arena * arena) const = 0;
|
||||
|
||||
/// Сериализовать состояние (например, для передачи по сети).
|
||||
/// Serializes state (to transmit it over the network, for example).
|
||||
virtual void serialize(ConstAggregateDataPtr place, WriteBuffer & buf) const = 0;
|
||||
|
||||
/// Десериализовать состояние. Вызывается для пустого (только что созданного) состояния.
|
||||
virtual void deserialize(AggregateDataPtr place, ReadBuffer & buf) const = 0;
|
||||
/// Deserializes state. This function is called only for empty (just created) states.
|
||||
virtual void deserialize(AggregateDataPtr place, ReadBuffer & buf, Arena * arena) const = 0;
|
||||
|
||||
/// Вставить результат в столбец.
|
||||
/// Returns true if a function requires Arena to handle own states (see add(), merge(), deserialize()).
|
||||
virtual bool allocatesMemoryInArena() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Inserts results into a column.
|
||||
virtual void insertResultInto(ConstAggregateDataPtr place, IColumn & to) const = 0;
|
||||
|
||||
/** Возвращает true для агрегатных функций типа -State.
|
||||
@ -103,7 +114,7 @@ public:
|
||||
* Это даёт падение производительности на простых запросах в районе 12%.
|
||||
* После появления более хороших компиляторов, код можно будет убрать.
|
||||
*/
|
||||
using AddFunc = void (*)(const IAggregateFunction *, AggregateDataPtr, const IColumn **, size_t);
|
||||
using AddFunc = void (*)(const IAggregateFunction *, AggregateDataPtr, const IColumn **, size_t, Arena *);
|
||||
virtual AddFunc getAddressOfAddFunction() const = 0;
|
||||
};
|
||||
|
||||
|
@ -25,14 +25,14 @@ public:
|
||||
getDerived().setArgumentsImpl(arguments);
|
||||
}
|
||||
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num) const override final
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, const size_t row_num, Arena * arena) const override final
|
||||
{
|
||||
getDerived().addImpl(place, *columns[0], *columns[1], row_num);
|
||||
getDerived().addImpl(place, *columns[0], *columns[1], row_num, arena);
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const Derived &>(*that).addImpl(place, *columns[0], *columns[1], row_num);
|
||||
static_cast<const Derived &>(*that).addImpl(place, *columns[0], *columns[1], row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override final { return &addFree; }
|
||||
|
@ -26,12 +26,12 @@ public:
|
||||
}
|
||||
|
||||
/// Добавить значение.
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override final
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *) const override final
|
||||
{
|
||||
getDerived().addImpl(place);
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena *)
|
||||
{
|
||||
return static_cast<const Derived &>(*that).addImpl(place);
|
||||
}
|
||||
|
@ -27,14 +27,14 @@ public:
|
||||
}
|
||||
|
||||
/// Добавить значение.
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num) const override final
|
||||
void add(AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena) const override final
|
||||
{
|
||||
getDerived().addImpl(place, *columns[0], row_num);
|
||||
getDerived().addImpl(place, *columns[0], row_num, arena);
|
||||
}
|
||||
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num)
|
||||
static void addFree(const IAggregateFunction * that, AggregateDataPtr place, const IColumn ** columns, size_t row_num, Arena * arena)
|
||||
{
|
||||
return static_cast<const Derived &>(*that).addImpl(place, *columns[0], row_num);
|
||||
static_cast<const Derived &>(*that).addImpl(place, *columns[0], row_num, arena);
|
||||
}
|
||||
|
||||
IAggregateFunction::AddFunc getAddressOfAddFunction() const override { return &addFree; }
|
||||
|
@ -159,7 +159,8 @@ public:
|
||||
/// Объединить состояние в последней строке с заданным
|
||||
void insertMergeFrom(const IColumn & src, size_t n)
|
||||
{
|
||||
func->merge(getData().back(), static_cast<const ColumnAggregateFunction &>(src).getData()[n]);
|
||||
Arena & arena = createOrGetArena();
|
||||
func->merge(getData().back(), static_cast<const ColumnAggregateFunction &>(src).getData()[n], &arena);
|
||||
}
|
||||
|
||||
Arena & createOrGetArena()
|
||||
@ -178,7 +179,7 @@ public:
|
||||
getData().push_back(arena.alloc(function->sizeOfData()));
|
||||
function->create(getData().back());
|
||||
ReadBufferFromString read_buffer(x.get<const String &>());
|
||||
function->deserialize(getData().back(), read_buffer);
|
||||
function->deserialize(getData().back(), read_buffer, &arena);
|
||||
}
|
||||
|
||||
void insertDefault() override
|
||||
|
@ -119,43 +119,71 @@ public:
|
||||
void insert(const Field & x) override
|
||||
{
|
||||
const String & s = DB::get<const String &>(x);
|
||||
size_t old_size = chars.size();
|
||||
size_t size_to_append = s.size() + 1;
|
||||
const size_t old_size = chars.size();
|
||||
const size_t size_to_append = s.size() + 1;
|
||||
const size_t new_size = old_size + size_to_append;
|
||||
|
||||
chars.resize(old_size + size_to_append);
|
||||
chars.resize(new_size);
|
||||
memcpy(&chars[old_size], s.c_str(), size_to_append);
|
||||
offsets.push_back((offsets.size() == 0 ? 0 : offsets.back()) + size_to_append);
|
||||
offsets.push_back(new_size);
|
||||
}
|
||||
|
||||
void insertFrom(const IColumn & src_, size_t n) override
|
||||
{
|
||||
const ColumnString & src = static_cast<const ColumnString &>(src_);
|
||||
size_t old_size = chars.size();
|
||||
size_t size_to_append = src.sizeAt(n);
|
||||
size_t offset = src.offsetAt(n);
|
||||
|
||||
chars.resize(old_size + size_to_append);
|
||||
memcpySmallAllowReadWriteOverflow15(&chars[old_size], &src.chars[offset], size_to_append);
|
||||
offsets.push_back((offsets.size() == 0 ? 0 : offsets.back()) + size_to_append);
|
||||
if (n != 0)
|
||||
{
|
||||
const size_t size_to_append = src.offsets[n] - src.offsets[n - 1];
|
||||
|
||||
if (size_to_append == 1)
|
||||
{
|
||||
/// shortcut for empty string
|
||||
chars.push_back(0);
|
||||
offsets.push_back(chars.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t old_size = chars.size();
|
||||
const size_t offset = src.offsets[n - 1];
|
||||
const size_t new_size = old_size + size_to_append;
|
||||
|
||||
chars.resize(new_size);
|
||||
memcpySmallAllowReadWriteOverflow15(&chars[old_size], &src.chars[offset], size_to_append);
|
||||
offsets.push_back(new_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
const size_t old_size = chars.size();
|
||||
const size_t size_to_append = src.offsets[0];
|
||||
const size_t new_size = old_size + size_to_append;
|
||||
|
||||
chars.resize(new_size);
|
||||
memcpySmallAllowReadWriteOverflow15(&chars[old_size], &src.chars[0], size_to_append);
|
||||
offsets.push_back(new_size);
|
||||
}
|
||||
}
|
||||
|
||||
void insertData(const char * pos, size_t length) override
|
||||
{
|
||||
size_t old_size = chars.size();
|
||||
const size_t old_size = chars.size();
|
||||
const size_t new_size = old_size + length + 1;
|
||||
|
||||
chars.resize(old_size + length + 1);
|
||||
chars.resize(new_size);
|
||||
memcpy(&chars[old_size], pos, length);
|
||||
chars[old_size + length] = 0;
|
||||
offsets.push_back((offsets.size() == 0 ? 0 : offsets.back()) + length + 1);
|
||||
offsets.push_back(new_size);
|
||||
}
|
||||
|
||||
void insertDataWithTerminatingZero(const char * pos, size_t length) override
|
||||
{
|
||||
size_t old_size = chars.size();
|
||||
const size_t old_size = chars.size();
|
||||
const size_t new_size = old_size + length;
|
||||
|
||||
chars.resize(old_size + length);
|
||||
chars.resize(new_size);
|
||||
memcpy(&chars[old_size], pos, length);
|
||||
offsets.push_back((offsets.size() == 0 ? 0 : offsets.back()) + length);
|
||||
offsets.push_back(new_size);
|
||||
}
|
||||
|
||||
void popBack(size_t n) override
|
||||
@ -182,14 +210,15 @@ public:
|
||||
|
||||
const char * deserializeAndInsertFromArena(const char * pos) override
|
||||
{
|
||||
size_t string_size = *reinterpret_cast<const size_t *>(pos);
|
||||
const size_t string_size = *reinterpret_cast<const size_t *>(pos);
|
||||
pos += sizeof(string_size);
|
||||
|
||||
size_t old_size = chars.size();
|
||||
chars.resize(old_size + string_size);
|
||||
const size_t old_size = chars.size();
|
||||
const size_t new_size = old_size + string_size;
|
||||
chars.resize(new_size);
|
||||
memcpy(&chars[old_size], pos, string_size);
|
||||
|
||||
offsets.push_back((offsets.size() == 0 ? 0 : offsets.back()) + string_size);
|
||||
offsets.push_back(new_size);
|
||||
return pos + string_size;
|
||||
}
|
||||
|
||||
|
@ -279,6 +279,16 @@ public:
|
||||
res = typename NearestFieldType<T>::Type(data[n]);
|
||||
}
|
||||
|
||||
const T & getElement(size_t n) const
|
||||
{
|
||||
return data[n];
|
||||
}
|
||||
|
||||
T & getElement(size_t n)
|
||||
{
|
||||
return data[n];
|
||||
}
|
||||
|
||||
UInt64 get64(size_t n) const override
|
||||
{
|
||||
return unionCastToUInt64(data[n]);
|
||||
|
@ -1,12 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <queue>
|
||||
#include <type_traits>
|
||||
|
||||
#include <Poco/Mutex.h>
|
||||
#include <Poco/Semaphore.h>
|
||||
|
||||
#include <DB/Core/Types.h>
|
||||
|
||||
namespace detail
|
||||
{
|
||||
template <class T, bool is_nothrow_move_assignable = std::is_nothrow_move_assignable<T>::value>
|
||||
struct MoveOrCopyIfThrow;
|
||||
|
||||
template <class T>
|
||||
struct MoveOrCopyIfThrow<T, true>
|
||||
{
|
||||
void operator()(T && src, T & dst) const
|
||||
{
|
||||
dst = std::forward<T>(src);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct MoveOrCopyIfThrow<T, false>
|
||||
{
|
||||
void operator()(T && src, T & dst) const
|
||||
{
|
||||
dst = src;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
void moveOrCopyIfThrow(T && src, T & dst)
|
||||
{
|
||||
MoveOrCopyIfThrow<T>()(std::forward<T>(src), dst);
|
||||
}
|
||||
};
|
||||
|
||||
/** Очень простая thread-safe очередь ограниченной длины.
|
||||
* Если пытаться вынуть элемент из пустой очереди, то поток блокируется, пока очередь не станет непустой.
|
||||
@ -36,12 +66,23 @@ public:
|
||||
fill_count.set();
|
||||
}
|
||||
|
||||
template <class ... Args>
|
||||
void emplace(Args && ... args)
|
||||
{
|
||||
empty_count.wait();
|
||||
{
|
||||
Poco::ScopedLock<Poco::FastMutex> lock(mutex);
|
||||
queue.emplace(std::forward<Args>(args)...);
|
||||
}
|
||||
fill_count.set();
|
||||
}
|
||||
|
||||
void pop(T & x)
|
||||
{
|
||||
fill_count.wait();
|
||||
{
|
||||
Poco::ScopedLock<Poco::FastMutex> lock(mutex);
|
||||
x = queue.front();
|
||||
detail::moveOrCopyIfThrow(std::move(queue.front()), x);
|
||||
queue.pop();
|
||||
}
|
||||
empty_count.set();
|
||||
@ -61,13 +102,28 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class ... Args>
|
||||
bool tryEmplace(DB::UInt64 milliseconds, Args && ... args)
|
||||
{
|
||||
if (empty_count.tryWait(milliseconds))
|
||||
{
|
||||
{
|
||||
Poco::ScopedLock<Poco::FastMutex> lock(mutex);
|
||||
queue.emplace(std::forward<Args>(args)...);
|
||||
}
|
||||
fill_count.set();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool tryPop(T & x, DB::UInt64 milliseconds = 0)
|
||||
{
|
||||
if (fill_count.tryWait(milliseconds))
|
||||
{
|
||||
{
|
||||
Poco::ScopedLock<Poco::FastMutex> lock(mutex);
|
||||
x = queue.front();
|
||||
detail::moveOrCopyIfThrow(std::move(queue.front()), x);
|
||||
queue.pop();
|
||||
}
|
||||
empty_count.set();
|
||||
|
@ -44,6 +44,12 @@ public:
|
||||
*/
|
||||
ConfigurationPtr loadConfig(const std::string & path);
|
||||
|
||||
public:
|
||||
|
||||
using Files = std::list<std::string>;
|
||||
|
||||
static Files getConfigMergeFiles(const std::string & config_path);
|
||||
|
||||
private:
|
||||
Logger * log;
|
||||
Poco::AutoPtr<Poco::Channel> channel_ptr;
|
||||
|
@ -124,9 +124,9 @@ public:
|
||||
void initReadBuffer()
|
||||
{
|
||||
if (file == "-")
|
||||
read_buffer.reset(new ReadBufferFromFileDescriptor(STDIN_FILENO));
|
||||
read_buffer = std::make_unique<ReadBufferFromFileDescriptor>(STDIN_FILENO);
|
||||
else
|
||||
read_buffer.reset(new ReadBufferFromFile(file));
|
||||
read_buffer = std::make_unique<ReadBufferFromFile>(file);
|
||||
}
|
||||
|
||||
/// Извлечение параметров из variables_map, которая строится по командной строке клиента
|
||||
|
@ -266,7 +266,7 @@ OptimizedRegularExpressionImpl<b>::OptimizedRegularExpressionImpl(const std::str
|
||||
if (is_dot_nl)
|
||||
options.set_dot_nl(true);
|
||||
|
||||
re2.reset(new RegexType(regexp_, options));
|
||||
re2 = std::make_unique<RegexType>(regexp_, options);
|
||||
if (!re2->ok())
|
||||
throw Poco::Exception("OptimizedRegularExpression: cannot compile re2: " + regexp_ + ", error: " + re2->error());
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <common/logger_useful.h>
|
||||
#include <DB/Common/Exception.h>
|
||||
|
||||
/// This type specifies the possible behaviors of an object pool allocator.
|
||||
enum class PoolMode
|
||||
@ -36,14 +37,14 @@ private:
|
||||
/** Объект с флагом, используется ли он сейчас. */
|
||||
struct PooledObject
|
||||
{
|
||||
PooledObject(std::condition_variable & available_, ObjectPtr object_)
|
||||
: object(object_), available(available_)
|
||||
PooledObject(ObjectPtr object_, PoolBase & pool_)
|
||||
: object(object_), pool(pool_)
|
||||
{
|
||||
}
|
||||
|
||||
ObjectPtr object;
|
||||
bool in_use = false;
|
||||
std::condition_variable & available;
|
||||
PoolBase & pool;
|
||||
};
|
||||
|
||||
using Objects = std::vector<std::shared_ptr<PooledObject>>;
|
||||
@ -54,7 +55,12 @@ private:
|
||||
struct PoolEntryHelper
|
||||
{
|
||||
PoolEntryHelper(PooledObject & data_) : data(data_) { data.in_use = true; }
|
||||
~PoolEntryHelper() { data.in_use = false; data.available.notify_one(); }
|
||||
~PoolEntryHelper()
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(data.pool.mutex);
|
||||
data.in_use = false;
|
||||
data.pool.available.notify_one();
|
||||
}
|
||||
|
||||
PooledObject & data;
|
||||
};
|
||||
@ -86,6 +92,13 @@ public:
|
||||
|
||||
bool isNull() const { return data == nullptr; }
|
||||
|
||||
PoolBase * getPool() const
|
||||
{
|
||||
if (!data)
|
||||
throw DB::Exception("attempt to get pool from uninitialized entry");
|
||||
return &data->data.pool;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<PoolEntryHelper> data;
|
||||
|
||||
@ -108,7 +121,7 @@ public:
|
||||
if (items.size() < max_items)
|
||||
{
|
||||
ObjectPtr object = allocObject();
|
||||
items.emplace_back(std::make_shared<PooledObject>(available, object));
|
||||
items.emplace_back(std::make_shared<PooledObject>(object, *this));
|
||||
return Entry(*items.back());
|
||||
}
|
||||
|
||||
@ -126,7 +139,7 @@ public:
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
while (items.size() < count)
|
||||
items.emplace_back(std::make_shared<PooledObject>(available, allocObject()));
|
||||
items.emplace_back(std::make_shared<PooledObject>(allocObject(), *this));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -110,6 +110,19 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
void reportError(const Entry & entry)
|
||||
{
|
||||
for (auto & pool : nested_pools)
|
||||
{
|
||||
if (pool.pool->contains(entry))
|
||||
{
|
||||
++pool.state.error_count;
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw DB::Exception("Can't find pool to report error.");
|
||||
}
|
||||
|
||||
/** Выделяет до указанного количества соединений для работы
|
||||
* Соединения предоставляют доступ к разным репликам одного шарда.
|
||||
*/
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
#define ROTL(x,b) (u64)( ((x) << (b)) | ( (x) >> (64 - (b))) )
|
||||
#define ROTL(x,b) static_cast<u64>( ((x) << (b)) | ( (x) >> (64 - (b))) )
|
||||
|
||||
#define SIPROUND \
|
||||
do \
|
||||
|
@ -45,9 +45,10 @@ inline bool endsWith(const std::string & s, const char * suffix)
|
||||
template <typename T>
|
||||
std::string getOrdinalSuffix(T n)
|
||||
{
|
||||
static_assert(std::is_integral<T>::value, "Integer value required");
|
||||
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
|
||||
"Unsigned integer value required");
|
||||
|
||||
auto val = n % 10;
|
||||
const auto val = n % 10;
|
||||
|
||||
bool is_th;
|
||||
if ((val >= 1) && (val <= 3))
|
||||
@ -64,7 +65,59 @@ std::string getOrdinalSuffix(T n)
|
||||
case 1: return "st";
|
||||
case 2: return "nd";
|
||||
case 3: return "rd";
|
||||
default: throw DB::Exception{"Internal error", DB::ErrorCodes::LOGICAL_ERROR};
|
||||
default: throw DB::Exception{"getOrdinalSuffix: internal error",
|
||||
DB::ErrorCodes::LOGICAL_ERROR};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// More efficient than libc, because doesn't respect locale.
|
||||
|
||||
inline bool isASCII(char c)
|
||||
{
|
||||
return static_cast<unsigned char>(c) < 0x80;
|
||||
}
|
||||
|
||||
inline bool isAlphaASCII(char c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
inline bool isNumericASCII(char c)
|
||||
{
|
||||
return (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
inline bool isAlphaNumericASCII(char c)
|
||||
{
|
||||
return isAlphaASCII(c)
|
||||
|| isNumericASCII(c);
|
||||
}
|
||||
|
||||
inline bool isWordCharASCII(char c)
|
||||
{
|
||||
return isAlphaNumericASCII(c)
|
||||
|| c == '_';
|
||||
}
|
||||
|
||||
inline bool isWhitespaceASCII(char c)
|
||||
{
|
||||
return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v';
|
||||
}
|
||||
|
||||
/// Works assuming isAlphaASCII.
|
||||
inline char toLowerIfAlphaASCII(char c)
|
||||
{
|
||||
return c | 0x20;
|
||||
}
|
||||
|
||||
inline char toUpperIfAlphaASCII(char c)
|
||||
{
|
||||
return c & (~0x20);
|
||||
}
|
||||
|
||||
inline char alternateCaseIfAlphaASCII(char c)
|
||||
{
|
||||
return c ^ 0x20;
|
||||
}
|
||||
|
@ -20,59 +20,27 @@ private:
|
||||
using Job = std::function<void()>;
|
||||
|
||||
public:
|
||||
ThreadPool(size_t m_size)
|
||||
: m_size(m_size)
|
||||
{
|
||||
threads.reserve(m_size);
|
||||
for (size_t i = 0; i < m_size; ++i)
|
||||
threads.emplace_back([this] { worker(); });
|
||||
}
|
||||
/// Size is constant, all threads are created immediately.
|
||||
ThreadPool(size_t m_size);
|
||||
|
||||
void schedule(Job job)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
has_free_thread.wait(lock, [this] { return active_jobs < m_size; });
|
||||
if (shutdown)
|
||||
return;
|
||||
/// Add new job. Locks until free thread in pool become available or exception in one of threads was thrown.
|
||||
/// If an exception in some thread was thrown, method silently returns, and exception will be rethrown only on call to 'wait' function.
|
||||
void schedule(Job job);
|
||||
|
||||
jobs.push(std::move(job));
|
||||
++active_jobs;
|
||||
}
|
||||
has_new_job_or_shutdown.notify_one();
|
||||
}
|
||||
/// Wait for all currently active jobs to be done.
|
||||
/// You may call schedule and wait many times in arbitary order.
|
||||
/// If any thread was throw an exception, first exception will be rethrown from this method,
|
||||
/// and exception will be cleared.
|
||||
void wait();
|
||||
|
||||
void wait()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
has_free_thread.wait(lock, [this] { return active_jobs == 0; });
|
||||
|
||||
if (!exceptions.empty())
|
||||
std::rethrow_exception(exceptions.front());
|
||||
}
|
||||
}
|
||||
|
||||
~ThreadPool()
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
shutdown = true;
|
||||
}
|
||||
|
||||
has_new_job_or_shutdown.notify_all();
|
||||
|
||||
for (auto & thread : threads)
|
||||
thread.join();
|
||||
}
|
||||
/// Waits for all threads. Doesn't rethrow exceptions (use 'wait' method to rethrow exceptions).
|
||||
/// You should not destroy object while calling schedule or wait methods from another threads.
|
||||
~ThreadPool();
|
||||
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
size_t active() const
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
return active_jobs;
|
||||
}
|
||||
/// Returns number of active jobs.
|
||||
size_t active() const;
|
||||
|
||||
private:
|
||||
mutable std::mutex mutex;
|
||||
@ -85,53 +53,9 @@ private:
|
||||
|
||||
std::queue<Job> jobs;
|
||||
std::vector<std::thread> threads;
|
||||
std::vector<std::exception_ptr> exceptions; /// NOTE Saving many exceptions but rethrow just first one.
|
||||
std::exception_ptr first_exception;
|
||||
|
||||
|
||||
void worker()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Job job;
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
has_new_job_or_shutdown.wait(lock, [this] { return shutdown || !jobs.empty(); });
|
||||
|
||||
if (!shutdown)
|
||||
{
|
||||
job = std::move(jobs.front());
|
||||
jobs.pop();
|
||||
}
|
||||
}
|
||||
|
||||
if (!job)
|
||||
return; /// shutdown
|
||||
|
||||
try
|
||||
{
|
||||
job();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
exceptions.push_back(std::current_exception());
|
||||
shutdown = true;
|
||||
--active_jobs;
|
||||
}
|
||||
has_free_thread.notify_one();
|
||||
has_new_job_or_shutdown.notify_all();
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
--active_jobs;
|
||||
}
|
||||
|
||||
has_free_thread.notify_one();
|
||||
}
|
||||
}
|
||||
void worker();
|
||||
};
|
||||
|
||||
|
@ -25,8 +25,10 @@ struct UInt128
|
||||
|
||||
struct UInt128Hash
|
||||
{
|
||||
DefaultHash<UInt64> hash64;
|
||||
size_t operator()(UInt128 x) const { return hash64(hash64(x.first) ^ x.second); }
|
||||
size_t operator()(UInt128 x) const
|
||||
{
|
||||
return Hash128to64({x.first, x.second});
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__x86_64__)
|
||||
@ -89,6 +91,15 @@ struct UInt256
|
||||
UInt256 & operator= (const UInt64 rhs) { a = rhs; b = 0; c = 0; d = 0; return *this; }
|
||||
};
|
||||
|
||||
struct UInt256Hash
|
||||
{
|
||||
size_t operator()(UInt256 x) const
|
||||
{
|
||||
/// NOTE suboptimal
|
||||
return Hash128to64({Hash128to64({x.a, x.b}), Hash128to64({x.c, x.d})});
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__x86_64__)
|
||||
|
||||
struct UInt256HashCRC32
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <DB/Common/StringSearcher.h>
|
||||
#include <DB/Common/StringUtils.h>
|
||||
#include <Poco/UTF8Encoding.h>
|
||||
#include <Poco/Unicode.h>
|
||||
#include <ext/range.hpp>
|
||||
@ -56,35 +57,6 @@ protected:
|
||||
static constexpr auto min_haystack_size_for_algorithm = 20000;
|
||||
const bool fallback; /// Нужно ли использовать fallback алгоритм.
|
||||
|
||||
|
||||
/// Эти функции эффективнее, чем соответствующие из libc, так как не учитывают локаль (что нам и надо).
|
||||
bool isascii(char c)
|
||||
{
|
||||
return static_cast<unsigned char>(c) < 0x80;
|
||||
}
|
||||
|
||||
bool isalpha(char c)
|
||||
{
|
||||
return (c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z');
|
||||
}
|
||||
|
||||
/// Работает корректно только при условии isalpha.
|
||||
char tolower(char c)
|
||||
{
|
||||
return c | 0x20;
|
||||
}
|
||||
|
||||
char toupper(char c)
|
||||
{
|
||||
return c & (~0x20);
|
||||
}
|
||||
|
||||
char alternate(char c)
|
||||
{
|
||||
return c ^ 0x20;
|
||||
}
|
||||
|
||||
public:
|
||||
/** haystack_size_hint - ожидаемый суммарный размер haystack при вызовах search. Можно не указывать.
|
||||
* Если указать его достаточно маленьким, то будет использован fallback алгоритм,
|
||||
@ -179,32 +151,32 @@ protected:
|
||||
|
||||
n = toNGram(pos);
|
||||
|
||||
const auto c0_al = isalpha(chars.c0);
|
||||
const auto c1_al = isalpha(chars.c1);
|
||||
const auto c0_al = isAlphaASCII(chars.c0);
|
||||
const auto c1_al = isAlphaASCII(chars.c1);
|
||||
|
||||
if (c0_al && c1_al)
|
||||
{
|
||||
/// 4 combinations: AB, aB, Ab, ab
|
||||
putNGramBase(n, offset);
|
||||
chars.c0 = alternate(chars.c0);
|
||||
chars.c0 = alternateCaseIfAlphaASCII(chars.c0);
|
||||
putNGramBase(n, offset);
|
||||
chars.c1 = alternate(chars.c1);
|
||||
chars.c1 = alternateCaseIfAlphaASCII(chars.c1);
|
||||
putNGramBase(n, offset);
|
||||
chars.c0 = alternate(chars.c0);
|
||||
chars.c0 = alternateCaseIfAlphaASCII(chars.c0);
|
||||
putNGramBase(n, offset);
|
||||
}
|
||||
else if (c0_al)
|
||||
{
|
||||
/// 2 combinations: A1, a1
|
||||
putNGramBase(n, offset);
|
||||
chars.c0 = alternate(chars.c0);
|
||||
chars.c0 = alternateCaseIfAlphaASCII(chars.c0);
|
||||
putNGramBase(n, offset);
|
||||
}
|
||||
else if (c1_al)
|
||||
{
|
||||
/// 2 combinations: 0B, 0b
|
||||
putNGramBase(n, offset);
|
||||
chars.c1 = alternate(chars.c1);
|
||||
chars.c1 = alternateCaseIfAlphaASCII(chars.c1);
|
||||
putNGramBase(n, offset);
|
||||
}
|
||||
else
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <DB/IO/ReadHelpers.h>
|
||||
#include <DB/Common/StringUtils.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
@ -19,7 +20,7 @@ inline std::string escapeForFileName(const std::string & s)
|
||||
{
|
||||
char c = *pos;
|
||||
|
||||
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (c == '_'))
|
||||
if (isWordCharASCII(c))
|
||||
res += c;
|
||||
else
|
||||
{
|
||||
|
@ -11,3 +11,9 @@ inline T unalignedLoad(const void * address)
|
||||
memcpy(&res, address, sizeof(res));
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void unalignedStore(void * address, const T & src)
|
||||
{
|
||||
memcpy(address, &src, sizeof(src));
|
||||
}
|
||||
|
@ -11,18 +11,18 @@ namespace DB
|
||||
{
|
||||
|
||||
|
||||
/** Прогресс выполнения запроса.
|
||||
* Передаваемые по сети значения представляют собой разницу - сколько было сделано после предыдущего отправленного значения.
|
||||
* Тот же объект используется для суммирования полученных значений.
|
||||
/** Progress of query execution.
|
||||
* Values, transferred over network are deltas - how much was done after previously sent value.
|
||||
* The same struct is also used for summarized values.
|
||||
*/
|
||||
struct Progress
|
||||
{
|
||||
std::atomic<size_t> rows {0}; /// Строк обработано.
|
||||
std::atomic<size_t> bytes {0}; /// Байт обработано.
|
||||
std::atomic<size_t> rows {0}; /// Rows (source) processed.
|
||||
std::atomic<size_t> bytes {0}; /// Bytes (uncompressed, source) processed.
|
||||
|
||||
/** Сколько ещё строк надо обработать, приблизительно. Передаётся не ноль, когда возникает информация о какой-то новой части работы.
|
||||
* Полученные значения надо суммровать, чтобы получить оценку общего количества строк для обработки.
|
||||
* Используется для отображения прогресс-бара на клиенте.
|
||||
/** How much rows must be processed, in total, approximately. Non-zero value is sent when there is information about some new part of job.
|
||||
* Received values must be summed to get estimate of total rows to process.
|
||||
* Used for rendering progress bar on client.
|
||||
*/
|
||||
std::atomic<size_t> total_rows {0};
|
||||
|
||||
@ -56,7 +56,7 @@ struct Progress
|
||||
writeVarUInt(total_rows, out);
|
||||
}
|
||||
|
||||
/// Каждое значение по-отдельности изменяется атомарно.
|
||||
/// Each value separately is changed atomically (but not whole object).
|
||||
void incrementPiecewiseAtomically(const Progress & rhs)
|
||||
{
|
||||
rows += rhs.rows;
|
||||
|
@ -161,6 +161,14 @@ inline bool operator> (StringRef lhs, StringRef rhs)
|
||||
* Подробнее см. hash_map_string_3.cpp
|
||||
*/
|
||||
|
||||
struct StringRefHash64
|
||||
{
|
||||
size_t operator() (StringRef x) const
|
||||
{
|
||||
return CityHash64(x.data, x.size);
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__x86_64__)
|
||||
|
||||
#ifdef __SSE4_1__
|
||||
@ -265,13 +273,7 @@ struct StringRefHash : CRC32Hash {};
|
||||
|
||||
#else
|
||||
|
||||
struct StringRefHash
|
||||
{
|
||||
size_t operator() (StringRef x) const
|
||||
{
|
||||
return CityHash64(x.data, x.size);
|
||||
}
|
||||
};
|
||||
struct StringRefHash : StringRefHash64 {};
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -1,13 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include <DB/Core/Block.h>
|
||||
#include <DB/IO/WriteBuffer.h>
|
||||
#include <DB/DataStreams/IRowOutputStream.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class IColumn;
|
||||
class IDataType;
|
||||
class WriteBuffer;
|
||||
|
||||
|
||||
/** Поток для вывода данных в бинарном построчном формате.
|
||||
*/
|
||||
class BinaryRowOutputStream : public IRowOutputStream
|
||||
@ -17,7 +20,7 @@ public:
|
||||
|
||||
void writeField(const IColumn & column, const IDataType & type, size_t row_num) override;
|
||||
|
||||
void flush() override { ostr.next(); }
|
||||
void flush() override;
|
||||
|
||||
String getContentType() const override { return "application/octet-stream"; }
|
||||
|
||||
|
@ -39,8 +39,6 @@ struct BlockIO
|
||||
{
|
||||
if (exception_callback)
|
||||
exception_callback();
|
||||
else
|
||||
tryLogCurrentException(__PRETTY_FUNCTION__);
|
||||
}
|
||||
|
||||
BlockIO & operator= (const BlockIO & rhs)
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
void setRowsBeforeLimit(size_t rows_before_limit) override;
|
||||
void setTotals(const Block & totals) override;
|
||||
void setExtremes(const Block & extremes) override;
|
||||
void onProgress(const Progress & progress) override;
|
||||
|
||||
String getContentType() const override { return row_output->getContentType(); }
|
||||
|
||||
|
@ -1,12 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <DB/IO/WriteBuffer.h>
|
||||
#include <DB/Core/Block.h>
|
||||
#include <DB/DataStreams/IRowOutputStream.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class WriteBuffer;
|
||||
|
||||
|
||||
/** Поток для вывода данных в формате csv.
|
||||
* Не соответствует https://tools.ietf.org/html/rfc4180 потому что использует LF, а не CR LF.
|
||||
*/
|
||||
@ -24,7 +27,7 @@ public:
|
||||
void writePrefix() override;
|
||||
void writeSuffix() override;
|
||||
|
||||
void flush() override { ostr.next(); }
|
||||
void flush() override;
|
||||
|
||||
void setTotals(const Block & totals_) override { totals = totals_; }
|
||||
void setExtremes(const Block & extremes_) override { extremes = extremes_; }
|
||||
|
@ -1,49 +1,54 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
#include <DB/Core/Block.h>
|
||||
#include <DB/Core/Row.h>
|
||||
#include <DB/Storages/IStorage.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class Block;
|
||||
struct Progress;
|
||||
|
||||
/** Интерфейс потока для записи данных в БД или в сеть, или в консоль и т. п.
|
||||
|
||||
/** Interface of stream for writing data (into table, filesystem, network, terminal, etc.)
|
||||
*/
|
||||
class IBlockOutputStream : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
IBlockOutputStream() {}
|
||||
|
||||
/** Записать блок.
|
||||
/** Write block.
|
||||
*/
|
||||
virtual void write(const Block & block) = 0;
|
||||
|
||||
/** Записать что-нибудь перед началом всех данных или после конца всех данных.
|
||||
/** Write or do something before all data or after all data.
|
||||
*/
|
||||
virtual void writePrefix() {}
|
||||
virtual void writeSuffix() {}
|
||||
|
||||
/** Сбросить имеющиеся буферы для записи.
|
||||
/** Flush output buffers if any.
|
||||
*/
|
||||
virtual void flush() {}
|
||||
|
||||
/** Методы для установки дополнительной информации для вывода в поддерживающих её форматах.
|
||||
/** Methods to set additional information for output in formats, that support it.
|
||||
*/
|
||||
virtual void setRowsBeforeLimit(size_t rows_before_limit) {}
|
||||
virtual void setTotals(const Block & totals) {}
|
||||
virtual void setExtremes(const Block & extremes) {}
|
||||
|
||||
/** Выставлять такой Content-Type при отдаче по HTTP.
|
||||
/** Notify about progress. Method could be called from different threads.
|
||||
* Passed value are delta, that must be summarized.
|
||||
*/
|
||||
virtual void onProgress(const Progress & progress) {}
|
||||
|
||||
/** Content-Type to set when sending HTTP response.
|
||||
*/
|
||||
virtual String getContentType() const { return "text/plain; charset=UTF-8"; }
|
||||
|
||||
virtual ~IBlockOutputStream() {}
|
||||
|
||||
/** Не давать изменить таблицу, пока жив поток блоков.
|
||||
/** Don't let to alter table while instance of stream is alive.
|
||||
*/
|
||||
void addTableLock(const IStorage::TableStructureReadLockPtr & lock) { table_locks.push_back(lock); }
|
||||
|
||||
|
@ -43,8 +43,8 @@ public:
|
||||
*/
|
||||
void readSuffix() override;
|
||||
|
||||
/// Получить информацию о скорости выполнения.
|
||||
const BlockStreamProfileInfo & getInfo() const { return info; }
|
||||
/// Get information about execution speed.
|
||||
const BlockStreamProfileInfo & getProfileInfo() const { return info; }
|
||||
|
||||
/** Получить "тотальные" значения.
|
||||
* Реализация по-умолчанию берёт их из себя или из первого дочернего источника, в котором они есть.
|
||||
|
@ -1,46 +1,58 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <memory>
|
||||
#include <DB/Core/Block.h>
|
||||
#include <cstdint>
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <DB/Core/Types.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
/** Интерфейс потока для записи данных по строкам (например, для вывода в консоль).
|
||||
class Block;
|
||||
class IColumn;
|
||||
class IDataType;
|
||||
struct Progress;
|
||||
|
||||
|
||||
/** Interface of stream for writing data by rows (for example: for output to terminal).
|
||||
*/
|
||||
class IRowOutputStream : private boost::noncopyable
|
||||
{
|
||||
public:
|
||||
|
||||
/** Записать строку.
|
||||
* Есть реализация по умолчанию, которая использует методы для записи одиночных значений и разделителей
|
||||
* (кроме разделителя между строк (writeRowBetweenDelimiter())).
|
||||
/** Write a row.
|
||||
* Default implementation calls methods to write single values and delimiters
|
||||
* (except delimiter between rows (writeRowBetweenDelimiter())).
|
||||
*/
|
||||
virtual void write(const Block & block, size_t row_num);
|
||||
|
||||
/** Записать значение. */
|
||||
/** Write single value. */
|
||||
virtual void writeField(const IColumn & column, const IDataType & type, size_t row_num) = 0;
|
||||
|
||||
/** Записать разделитель. */
|
||||
virtual void writeFieldDelimiter() {}; /// разделитель между значениями
|
||||
virtual void writeRowStartDelimiter() {}; /// разделитель перед каждой строкой
|
||||
virtual void writeRowEndDelimiter() {}; /// разделитель после каждой строки
|
||||
virtual void writeRowBetweenDelimiter() {}; /// разделитель между строками
|
||||
virtual void writePrefix() {}; /// разделитель перед началом результата
|
||||
virtual void writeSuffix() {}; /// разделитель после конца результата
|
||||
/** Write delimiter. */
|
||||
virtual void writeFieldDelimiter() {}; /// delimiter between values
|
||||
virtual void writeRowStartDelimiter() {}; /// delimiter before each row
|
||||
virtual void writeRowEndDelimiter() {}; /// delimiter after each row
|
||||
virtual void writeRowBetweenDelimiter() {}; /// delimiter between rows
|
||||
virtual void writePrefix() {}; /// delimiter before resultset
|
||||
virtual void writeSuffix() {}; /// delimiter after resultset
|
||||
|
||||
/** Сбросить имеющиеся буферы для записи. */
|
||||
/** Flush output buffers if any. */
|
||||
virtual void flush() {}
|
||||
|
||||
/** Методы для установки дополнительной информации для вывода в поддерживающих её форматах.
|
||||
/** Methods to set additional information for output in formats, that support it.
|
||||
*/
|
||||
virtual void setRowsBeforeLimit(size_t rows_before_limit) {}
|
||||
virtual void setTotals(const Block & totals) {}
|
||||
virtual void setExtremes(const Block & extremes) {}
|
||||
|
||||
/** Выставлять такой Content-Type при отдаче по HTTP. */
|
||||
/** Notify about progress. Method could be called from different threads.
|
||||
* Passed value are delta, that must be summarized.
|
||||
*/
|
||||
virtual void onProgress(const Progress & progress) {}
|
||||
|
||||
/** Content-Type to set when sending HTTP response. */
|
||||
virtual String getContentType() const { return "text/plain; charset=UTF-8"; }
|
||||
|
||||
virtual ~IRowOutputStream() {}
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user