Skip to content
Permalink
Browse files

Merge pull request #34988 from mrylov/hana-provider

[FEATURE] HANA database provider
  • Loading branch information
m-kuhn committed Jan 10, 2021
2 parents bbb4334 + 7f7bbae commit 60b884d4f4a802549c27c6bf807eb3a1715d0a66
Showing with 11,483 additions and 17 deletions.
  1. 0 .ci/travis/linux/docker-compose.travis.yml
  2. +7 −0 .ci/travis/linux/docker-variables.env
  3. +7 −0 .ci/travis/linux/scripts/docker-qgis-build.sh
  4. +22 −0 .ci/travis/linux/scripts/docker-qgis-test.sh
  5. +24 −0 .docker/qgis3-build-deps.dockerfile
  6. +5 −0 CMakeLists.txt
  7. +227 −0 cmake/FindODBC.cmake
  8. +48 −0 cmake/FindODBCCPP.cmake
  9. +24 −5 cmake/UsePythonTest.cmake
  10. +2 −0 cmake_templates/qgsconfig.h.in
  11. +2 −0 images/images.qrc
  12. +130 −0 images/themes/default/mActionAddHanaLayer.svg
  13. +102 −0 images/themes/default/mIconHana.svg
  14. +1 −0 python/gui/auto_generated/qgsmanageconnectionsdialog.sip.in
  15. +16 −0 src/app/qgisapp.cpp
  16. +154 −0 src/gui/qgsmanageconnectionsdialog.cpp
  17. +3 −0 src/gui/qgsmanageconnectionsdialog.h
  18. +7 −3 src/providers/CMakeLists.txt
  19. +135 −0 src/providers/hana/CMakeLists.txt
  20. +76 −0 src/providers/hana/qgshanacolumntypethread.cpp
  21. +49 −0 src/providers/hana/qgshanacolumntypethread.h
  22. +797 −0 src/providers/hana/qgshanaconnection.cpp
  23. +95 −0 src/providers/hana/qgshanaconnection.h
  24. +87 −0 src/providers/hana/qgshanaconnectionpool.cpp
  25. +107 −0 src/providers/hana/qgshanaconnectionpool.h
  26. +62 −0 src/providers/hana/qgshanaconnectionstringbuilder.cpp
  27. +86 −0 src/providers/hana/qgshanaconnectionstringbuilder.h
  28. +98 −0 src/providers/hana/qgshanacrsutils.cpp
  29. +31 −0 src/providers/hana/qgshanacrsutils.h
  30. +171 −0 src/providers/hana/qgshanadataitemguiprovider.cpp
  31. +47 −0 src/providers/hana/qgshanadataitemguiprovider.h
  32. +385 −0 src/providers/hana/qgshanadataitems.cpp
  33. +112 −0 src/providers/hana/qgshanadataitems.h
  34. +86 −0 src/providers/hana/qgshanadriver.cpp
  35. +44 −0 src/providers/hana/qgshanadriver.h
  36. +55 −0 src/providers/hana/qgshanaexception.h
  37. +229 −0 src/providers/hana/qgshanaexpressioncompiler.cpp
  38. +42 −0 src/providers/hana/qgshanaexpressioncompiler.h
  39. +494 −0 src/providers/hana/qgshanafeatureiterator.cpp
  40. +100 −0 src/providers/hana/qgshanafeatureiterator.h
  41. +350 −0 src/providers/hana/qgshananewconnection.cpp
  42. +65 −0 src/providers/hana/qgshananewconnection.h
  43. +310 −0 src/providers/hana/qgshanaprimarykeys.cpp
  44. +72 −0 src/providers/hana/qgshanaprimarykeys.h
  45. +1,878 −0 src/providers/hana/qgshanaprovider.cpp
  46. +216 −0 src/providers/hana/qgshanaprovider.h
  47. +405 −0 src/providers/hana/qgshanaproviderconnection.cpp
  48. +78 −0 src/providers/hana/qgshanaproviderconnection.h
  49. +68 −0 src/providers/hana/qgshanaprovidergui.cpp
  50. +211 −0 src/providers/hana/qgshanaresultset.cpp
  51. +61 −0 src/providers/hana/qgshanaresultset.h
  52. +222 −0 src/providers/hana/qgshanasettings.cpp
  53. +239 −0 src/providers/hana/qgshanasettings.h
  54. +675 −0 src/providers/hana/qgshanasourceselect.cpp
  55. +159 −0 src/providers/hana/qgshanasourceselect.h
  56. +330 −0 src/providers/hana/qgshanatablemodel.cpp
  57. +102 −0 src/providers/hana/qgshanatablemodel.h
  58. +509 −0 src/providers/hana/qgshanautils.cpp
  59. +77 −0 src/providers/hana/qgshanautils.h
  60. +13 −0 src/ui/qgisapp.ui
  61. +647 −0 src/ui/qgshananewconnectionbase.ui
  62. +6 −0 tests/src/python/CMakeLists.txt
  63. +125 −0 tests/src/python/test_hana_utils.py
  64. +366 −0 tests/src/python/test_provider_hana.py
  65. +9 −9 tests/src/python/test_qgsproviderconnection_base.py
  66. +121 −0 tests/src/python/test_qgsproviderconnection_hana.py
Empty file.
@@ -22,3 +22,10 @@ CTEST_BUILD_DIR=/root/QGIS

# Other var
QGIS_NO_OVERRIDE_IMPORT=1

# HANA provider settings
HANA_TESTS=true
HANA_HOST=9e69e18b-99de-4134-a6ab-ccde13d8c60a.hana.canary-eu10.hanacloud.ondemand.com
HANA_PORT=443
HANA_USER=QGIS_CI
HANA_PASSWORD="3w8dkX:NDrs&"
@@ -33,6 +33,11 @@ echo "${bold}Running cmake...${endbold}"
export CC=/usr/lib/ccache/clang
export CXX=/usr/lib/ccache/clang++

HANA_TESTS_ENABLED=OFF
if [ ${HANA_TESTS} == "true" ] ; then
HANA_TESTS_ENABLED=ON
fi

cmake \
-GNinja \
-DUSE_CCACHE=OFF \
@@ -45,6 +50,8 @@ cmake \
-DENABLE_PGTEST=ON \
-DENABLE_SAGA_TESTS=ON \
-DENABLE_MSSQLTEST=ON \
-DENABLE_HANATEST=$HANA_TESTS_ENABLED \
-DWITH_HANA=ON \
-DWITH_QSPATIALITE=ON \
-DWITH_QWTPOLAR=OFF \
-DWITH_APIDOC=OFF \
@@ -7,6 +7,28 @@ set -e
# cat /tmp/cache.debug
# echo "travis_fold:end:ccache-debug"

##################################
# Prepare HANA database connection
##################################

if [ ${HANA_TESTS} == "true" ] ; then
echo "travis_fold:start:hana"
echo "${bold}Load HANA database...${endbold}"

export QGIS_HANA_TEST_DB='driver='/usr/sap/hdbclient/libodbcHDB.so' host='${HANA_HOST}' port='${HANA_PORT}' user='${HANA_USER}' password='${HANA_PASSWORD}' sslEnabled=true sslValidateCertificate=False'

# wait for the DB to be available
echo "Wait a moment while trying to connect to a HANA database."
while ! echo exit | hdbsql -n '${HANA_HOST}:${HANA_PORT}' -u '${HANA_USER}' -p '${HANA_PASSWORD}' &> /dev/null
do
printf "."
sleep 1
done
echo " done"

echo "travis_fold:end:hana"
fi

############################
# Restore postgres test data
############################
@@ -131,6 +131,7 @@ RUN apt-get update \
sphinx \
requests \
six \
hdbcli \
&& apt-get clean

# Oracle : client side
@@ -145,6 +146,29 @@ RUN unzip instantclient-sqlplus-linux.x64-19.3.0.0.0dbru.zip
ENV PATH="/instantclient_19_3:${PATH}"
ENV LD_LIBRARY_PATH="/instantclient_19_3:${LD_LIBRARY_PATH}"

# HANA: client side
# Install hdbsql tool
RUN curl -v -j -k -L -H "Cookie: eula_3_1_agreed=tools.hana.ondemand.com/developer-license-3_1.txt" https://tools.hana.ondemand.com/additional/hanaclient-latest-linux-x64.tar.gz --output hanaclient-latest-linux-x64.tar.gz \
&& tar -xvf hanaclient-latest-linux-x64.tar.gz \
&& mkdir /usr/sap \
&& ./client/hdbinst -a client --sapmnt=/usr/sap \
&& rm -rf client \
&& rm hanaclient*
ENV PATH="/usr/sap/hdbclient:${PATH}"
# Install cmake version 3.12 required by odbc-cpp-wrapper
RUN curl -LJO https://cmake.org/files/v3.12/cmake-3.12.4-Linux-x86_64.tar.gz \
&& tar -xvf cmake-3.12.4-Linux-x86_64.tar.gz && cp cmake-3.12.4-Linux-x86_64/bin/cmake /usr/local/bin \
&& mkdir -p /usr/local/share/cmake-3.12 \
&& cp -r cmake-3.12.4-Linux-x86_64/share/cmake-3.12/* /usr/local/share/cmake-3.12 \
&& rm -rf cmake-3.12.4-Linux-x86_64*
# Download and compile odbc-cpp-wrapper
RUN git clone --branch v0.2 --depth 1 https://github.com/SAP/odbc-cpp-wrapper.git \
&& mkdir odbc-cpp-wrapper/build \
&& cd odbc-cpp-wrapper/build \
&& cmake .. \
&& make -j 2 \
&& make install

# MSSQL: client side
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | tee /etc/apt/sources.list.d/msprod.list
@@ -240,6 +240,11 @@ if(WITH_CORE)
set(ORACLE_LIBDIR "" CACHE STRING "Path to OCI libraries")
endif()

SET (WITH_HANA FALSE CACHE BOOL "Determines whether SAP HANA Spatial support should be built")
IF(WITH_HANA)
SET(HAVE_HANA TRUE)
ENDIF(WITH_HANA)

set (WITH_PDAL FALSE CACHE BOOL "Determines whether PDAL support should be built")
if(WITH_PDAL)
set(HAVE_PDAL TRUE)
@@ -0,0 +1,227 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.

#[=======================================================================[.rst:
FindODBC
--------

Find an Open Database Connectivity (ODBC) include directory and library.

On Windows, when building with Visual Studio, this module assumes the ODBC
library is provided by the available Windows SDK.

On Unix, this module allows searching for ODBC library provided by
unixODBC or iODBC implementations of ODBC API.
This module reads hint about location of the config program:

.. variable:: ODBC_CONFIG

Location of odbc_config or iodbc-config program

Otherwise, this module tries to find the config program,
first from unixODBC, then from iODBC.
If no config program found, this module searches for ODBC header
and library in list of known locations.

Imported targets
^^^^^^^^^^^^^^^^

This module defines the following :prop_tgt:`IMPORTED` targets:

.. variable:: ODBC::ODBC

Imported target for using the ODBC library, if found.

Result variables
^^^^^^^^^^^^^^^^

.. variable:: ODBC_FOUND

Set to true if ODBC library found, otherwise false or undefined.

.. variable:: ODBC_INCLUDE_DIRS

Paths to include directories listed in one variable for use by ODBC client.
May be empty on Windows, where the include directory corresponding to the
expected Windows SDK is already available in the compilation environment.

.. variable:: ODBC_LIBRARIES

Paths to libraries to linked against to use ODBC.
May just a library name on Windows, where the library directory corresponding
to the expected Windows SDK is already available in the compilation environment.

.. variable:: ODBC_CONFIG

Path to unixODBC or iODBC config program, if found or specified.

Cache variables
^^^^^^^^^^^^^^^

For users who wish to edit and control the module behavior, this module
reads hints about search locations from the following variables:

.. variable:: ODBC_INCLUDE_DIR

Path to ODBC include directory with ``sql.h`` header.

.. variable:: ODBC_LIBRARY

Path to ODBC library to be linked.

These variables should not be used directly by project code.

Limitations
^^^^^^^^^^^

On Windows, this module does not search for iODBC.
On Unix, there is no way to prefer unixODBC over iODBC, or vice versa,
other than providing the config program location using the ``ODBC_CONFIG``.
This module does not allows searching for a specific ODBC driver.

#]=======================================================================]

# Define lists used internally
set(_odbc_include_paths)
set(_odbc_lib_paths)
set(_odbc_lib_names)
set(_odbc_required_libs_names)

### Try Windows Kits ##########################################################
if(WIN32)
# List names of ODBC libraries on Windows
set(ODBC_LIBRARY odbc32.lib)
set(_odbc_lib_names odbc32;)

# List additional libraries required to use ODBC library
if(MSVC OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
set(_odbc_required_libs_names odbccp32;ws2_32)
elseif(MINGW)
set(_odbc_required_libs_names odbccp32)
endif()
endif()

### Try unixODBC or iODBC config program ######################################
if (UNIX)
find_program(ODBC_CONFIG
NAMES odbc_config iodbc-config
DOC "Path to unixODBC or iODBC config program")
mark_as_advanced(ODBC_CONFIG)
endif()

if (UNIX AND ODBC_CONFIG)
# unixODBC and iODBC accept unified command line options
execute_process(COMMAND ${ODBC_CONFIG} --cflags
OUTPUT_VARIABLE _cflags OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${ODBC_CONFIG} --libs
OUTPUT_VARIABLE _libs OUTPUT_STRIP_TRAILING_WHITESPACE)

# Collect paths of include directories from CFLAGS
separate_arguments(_cflags NATIVE_COMMAND "${_cflags}")
foreach(arg IN LISTS _cflags)
if("${arg}" MATCHES "^-I(.*)$")
list(APPEND _odbc_include_paths "${CMAKE_MATCH_1}")
endif()
endforeach()
unset(_cflags)

# Collect paths of library names and directories from LIBS
separate_arguments(_libs NATIVE_COMMAND "${_libs}")
foreach(arg IN LISTS _libs)
if("${arg}" MATCHES "^-L(.*)$")
list(APPEND _odbc_lib_paths "${CMAKE_MATCH_1}")
elseif("${arg}" MATCHES "^-l(.*)$")
set(_lib_name ${CMAKE_MATCH_1})
string(REGEX MATCH "odbc" _is_odbc ${_lib_name})
if(_is_odbc)
list(APPEND _odbc_lib_names ${_lib_name})
else()
list(APPEND _odbc_required_libs_names ${_lib_name})
endif()
unset(_lib_name)
endif()
endforeach()
unset(_libs)
endif()

### Try unixODBC or iODBC in include/lib filesystems ##########################
if (UNIX AND NOT ODBC_CONFIG)
# List names of both ODBC libraries, unixODBC and iODBC
set(_odbc_lib_names odbc;iodbc;unixodbc;)
endif()

### Find include directories ##################################################
find_path(ODBC_INCLUDE_DIR
NAMES sql.h
PATHS ${_odbc_include_paths})

if(NOT ODBC_INCLUDE_DIR AND WIN32)
set(ODBC_INCLUDE_DIR "")
endif()

### Find libraries ############################################################
if(NOT ODBC_LIBRARY)
find_library(ODBC_LIBRARY
NAMES ${_odbc_lib_names}
PATHS ${_odbc_lib_paths}
PATH_SUFFIXES odbc)

foreach(_lib IN LISTS _odbc_required_libs_names)
find_library(_lib_path
NAMES ${_lib}
PATHS ${_odbc_lib_paths} # system parths or collected from ODBC_CONFIG
PATH_SUFFIXES odbc)
if(_lib_path)
list(APPEND _odbc_required_libs_paths ${_lib_path})
endif()
unset(_lib_path CACHE)
endforeach()
endif()

# Unset internal lists as no longer used
unset(_odbc_include_paths)
unset(_odbc_lib_paths)
unset(_odbc_lib_names)
unset(_odbc_required_libs_names)

### Set result variables ######################################################
set(_odbc_required_vars ODBC_LIBRARY)
if(NOT WIN32)
list(APPEND _odbc_required_vars ODBC_INCLUDE_DIR)
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ODBC DEFAULT_MSG ${_odbc_required_vars})

unset(_odbc_required_vars)

mark_as_advanced(ODBC_LIBRARY ODBC_INCLUDE_DIR)

set(ODBC_INCLUDE_DIRS ${ODBC_INCLUDE_DIR})
list(APPEND ODBC_LIBRARIES ${ODBC_LIBRARY})
list(APPEND ODBC_LIBRARIES ${_odbc_required_libs_paths})

### Import targets ############################################################
if(ODBC_FOUND)
if(NOT TARGET ODBC::ODBC)
if(IS_ABSOLUTE "${ODBC_LIBRARY}")
add_library(ODBC::ODBC UNKNOWN IMPORTED)
set_target_properties(ODBC::ODBC PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${ODBC_LIBRARY}")
else()
add_library(ODBC::ODBC INTERFACE IMPORTED)
set_target_properties(ODBC::ODBC PROPERTIES
IMPORTED_LIBNAME "${ODBC_LIBRARY}")
endif()
set_target_properties(ODBC::ODBC PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${ODBC_INCLUDE_DIR}")

if(_odbc_required_libs_paths)
set_property(TARGET ODBC::ODBC APPEND PROPERTY
INTERFACE_LINK_LIBRARIES "${_odbc_required_libs_paths}")
endif()
endif()
endif()

unset(_odbc_required_libs_paths)
@@ -0,0 +1,48 @@
# Find odbc-cpp-wrapper
# ~~~~~~~~~~~~~~~
# CMake module to search for C++ Wrapper for ODBC from:
# https://github.com/SAP/odbc-cpp-wrapper

FIND_PACKAGE(ODBC REQUIRED)

IF (NOT ODBCCPP_INCLUDE_DIR)
FIND_PATH(ODBCCPP_INCLUDE_DIR odbc/Environment.h
PATHS
/usr/local/include
/usr/include
c:/msys/local/include
"$ENV{LIB_DIR}/include"
$ENV{INCLUDE}
"$ENV{ODBCCPP_PATH}/include"
)
ENDIF (NOT ODBCCPP_INCLUDE_DIR)

IF (NOT ODBCCPP_LIBRARY)
FIND_LIBRARY(ODBCCPP_LIBRARY odbccpp_static
PATHS
/usr/lib
/usr/local/lib
c:/msys/local/lib
"$ENV{LIB_DIR}/lib"
$ENV{LIB}
"$ENV{ODBCCPP_PATH}/lib"
)
ENDIF (NOT ODBCCPP_LIBRARY)

IF (ODBCCPP_INCLUDE_DIR AND ODBCCPP_LIBRARY)
SET(ODBCCPP_FOUND TRUE)
ENDIF (ODBCCPP_INCLUDE_DIR AND ODBCCPP_LIBRARY)

IF (ODBCCPP_FOUND)
IF (NOT ODBCCPP_FIND_QUIETLY)
MESSAGE(STATUS "Found odbc-cpp: ${ODBCCPP_LIBRARY}")
ENDIF (NOT ODBCCPP_FIND_QUIETLY)
ELSE (ODBCCPP_FOUND)
IF (ODBCCPP_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find odbc-cpp library")
ELSE (ODBCCPP_FIND_REQUIRED)
IF (NOT ODBCCPP_FIND_QUIETLY)
MESSAGE(STATUS "Could not find odbc-cpp library")
ENDIF (NOT ODBCCPP_FIND_QUIETLY)
ENDIF (ODBCCPP_FIND_REQUIRED)
ENDIF (ODBCCPP_FOUND)

0 comments on commit 60b884d

Please sign in to comment.
You can’t perform that action at this time.