Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ option(YDB_SDK_TESTS "Build YDB C++ SDK tests" Off)
option(YDB_SDK_EXAMPLES "Build YDB C++ SDK examples" On)
option(YDB_SDK_ENABLE_OTEL_METRICS "Build OpenTelemetry metrics plugin" Off)
option(YDB_SDK_ENABLE_OTEL_TRACE "Build OpenTelemetry trace plugin" Off)
option(YDB_SDK_ODBC "Build YDB ODBC driver" Off)
set(YDB_SDK_GOOGLE_COMMON_PROTOS_TARGET "" CACHE STRING "Name of cmake target preparing google common proto library")
option(YDB_SDK_USE_RAPID_JSON "Search for rapid json library in system" ON)

Expand Down Expand Up @@ -64,6 +65,10 @@ add_subdirectory(plugins)

#_ydb_sdk_validate_public_headers()

if (YDB_SDK_ODBC)
add_subdirectory(odbc)
endif()

if (YDB_SDK_EXAMPLES)
add_subdirectory(examples)
endif()
Expand Down
1 change: 1 addition & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"cacheVariables": {
"YDB_SDK_TESTS": "TRUE",
"YDB_SDK_EXAMPLES": "TRUE",
"YDB_SDK_ODBC": "TRUE",
"ARCADIA_ROOT": "..",
"ARCADIA_BUILD_ROOT": "."
}
Expand Down
12 changes: 9 additions & 3 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function(generate_enum_serilization Tgt Input)
endfunction()

function(add_global_library_for TgtName MainName)
add_library(${TgtName} STATIC ${ARGN})
_ydb_sdk_add_library(${TgtName} STATIC ${ARGN})
if(APPLE)
target_link_options(${MainName} INTERFACE "SHELL:-Wl,-force_load,$<TARGET_FILE:$<INSTALL_INTERFACE:YDB-CPP-SDK::>${TgtName}>")
else()
Expand Down Expand Up @@ -182,7 +182,7 @@ endfunction()

function(_ydb_sdk_add_library Tgt)
cmake_parse_arguments(ARG
"INTERFACE" "" ""
"INTERFACE;OBJECT;SHARED" "" ""
${ARGN}
)

Expand All @@ -192,6 +192,12 @@ function(_ydb_sdk_add_library Tgt)
set(libraryMode "INTERFACE")
set(includeMode "INTERFACE")
endif()
if (ARG_OBJECT)
set(libraryMode "OBJECT")
endif()
if (ARG_SHARED)
set(libraryMode "SHARED")
endif()
add_library(${Tgt} ${libraryMode})
target_include_directories(${Tgt} ${includeMode}
$<BUILD_INTERFACE:${YDB_SDK_SOURCE_DIR}>
Expand All @@ -201,6 +207,7 @@ function(_ydb_sdk_add_library Tgt)
target_compile_definitions(${Tgt} ${includeMode}
YDB_SDK_OSS
)
set_property(TARGET ${Tgt} PROPERTY POSITION_INDEPENDENT_CODE ON)
endfunction()

function(_ydb_sdk_validate_public_headers)
Expand Down Expand Up @@ -255,4 +262,3 @@ function(_ydb_sdk_validate_public_headers)
)
target_include_directories(validate_public_interface PUBLIC ${YDB_SDK_BINARY_DIR}/__validate_headers_dir/include)
endfunction()

4 changes: 4 additions & 0 deletions cmake/external_libs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ if (YDB_SDK_ENABLE_OTEL_METRICS OR YDB_SDK_ENABLE_OTEL_TRACE)
find_package(opentelemetry-cpp REQUIRED)
endif()

if (YDB_SDK_ODBC)
find_package(ODBC REQUIRED)
endif()

# RapidJSON
if (YDB_SDK_USE_RAPID_JSON)
find_package(RapidJSON REQUIRED)
Expand Down
32 changes: 32 additions & 0 deletions cmake/testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,35 @@ function(add_ydb_test)

vcs_info(${YDB_TEST_NAME})
endfunction()

if (YDB_SDK_ODBC)
function(add_odbc_test)
set(opts "")
set(oneval_args NAME WORKING_DIRECTORY OUTPUT_DIRECTORY)
set(multival_args SOURCES LINK_LIBRARIES LABELS)
cmake_parse_arguments(ODBC_TEST
"${opts}"
"${oneval_args}"
"${multival_args}"
${ARGN}
)

add_ydb_test(GTEST
NAME ${ODBC_TEST_NAME}
SOURCES ${ODBC_TEST_SOURCES}
LINK_LIBRARIES
${ODBC_TEST_LINK_LIBRARIES}
ODBC::ODBC
LABELS
integration
${ODBC_TEST_LABELS}
)

target_compile_definitions(${ODBC_TEST_NAME}
PRIVATE
ODBC_DRIVER_PATH="$<TARGET_FILE:ydb-odbc>"
)

add_dependencies(${ODBC_TEST_NAME} ydb-odbc)
endfunction()
endif()
30 changes: 30 additions & 0 deletions examples/odbc/erlang_client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Erlang ODBC Series Example

Minimal Erlang client for YDB ODBC. Mirrors the main scenario of the C++ `basic_example`: creates `series`, `seasons`, and `episodes` tables, fills them with test data, runs several queries, and drops the tables.

## Requirements

- Erlang/OTP with the `odbc` module
- unixODBC
- Built and registered YDB ODBC driver
- Running YDB instance reachable via the connection string

Verify driver registration:

```bash
odbcinst -q -d
```

## Running

By default, `Driver=YDB;Endpoint=localhost:2136;Database=/local;` is used.

```bash
make run
```

With a different connection string:

```bash
make run CONN='...'
```
64 changes: 64 additions & 0 deletions examples/odbc/erlang_client/src/sample_data.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
-module(sample_data).
-export([series/0, seasons/0, episodes/0, format_date/1]).

series() ->
[
[1, "IT Crowd", "The IT Crowd is a British sitcom by Channel 4.", days_from_date({2006, 2, 3})],
[2, "Silicon Valley", "Silicon Valley is an American comedy series.", days_from_date({2014, 4, 6})]
].

seasons() ->
[
[1, 1, "Season 1", days_from_date({2006, 2, 3}), days_from_date({2006, 5, 5})],
[1, 2, "Season 2", days_from_date({2007, 8, 24}), days_from_date({2007, 11, 16})],
[1, 3, "Season 3", days_from_date({2008, 11, 21}), days_from_date({2008, 12, 26})],
[1, 4, "Season 4", days_from_date({2010, 6, 25}), days_from_date({2010, 7, 30})],
[2, 1, "Season 1", days_from_date({2014, 4, 6}), days_from_date({2014, 6, 15})],
[2, 2, "Season 2", days_from_date({2015, 4, 12}), days_from_date({2015, 6, 14})],
[2, 3, "Season 3", days_from_date({2016, 4, 24}), days_from_date({2016, 6, 26})],
[2, 4, "Season 4", days_from_date({2017, 4, 23}), days_from_date({2017, 6, 25})],
[2, 5, "Season 5", days_from_date({2018, 3, 25}), days_from_date({2018, 5, 13})],
[2, 6, "Season 6", days_from_date({2019, 10, 27}), days_from_date({2019, 12, 8})]
].

episodes() ->
[
[1, 1, 1, "Yesterday's Jam", days_from_date({2006, 2, 3})],
[1, 1, 2, "Calamity Jen", days_from_date({2006, 2, 10})],
[1, 1, 3, "Fifty-Fifty", days_from_date({2006, 2, 17})],
[1, 1, 4, "The Red Door", days_from_date({2006, 2, 24})],
[1, 1, 5, "The Haunting of Bill Crouse", days_from_date({2006, 3, 3})],
[1, 1, 6, "Aunt Irma Visits", days_from_date({2006, 3, 10})],
[1, 2, 1, "The Work Outing", days_from_date({2007, 8, 24})],
[1, 2, 2, "Return of the Golden Child", days_from_date({2007, 8, 31})],
[1, 2, 3, "Moss and the German", days_from_date({2007, 9, 7})],
[2, 1, 1, "Minimum Viable Product", days_from_date({2014, 4, 6})],
[2, 1, 2, "The Cap Table", days_from_date({2014, 4, 13})],
[2, 1, 3, "Articles of Incorporation", days_from_date({2014, 4, 20})],
[2, 1, 4, "Fiduciary Duties", days_from_date({2014, 4, 27})],
[2, 1, 5, "Signaling Risk", days_from_date({2014, 5, 4})],
[2, 3, 1, "Founder Friendly", days_from_date({2016, 4, 24})],
[2, 3, 2, "Two in the Box", days_from_date({2016, 5, 1})],
[2, 3, 3, "Meinertzhagen's Haversack", days_from_date({2016, 5, 8})],
[2, 3, 4, "Maleant Data Systems Solutions", days_from_date({2016, 5, 15})],
[2, 5, 1, "Grow Fast or Die Slow", days_from_date({2018, 3, 25})],
[2, 5, 2, "Reorientation", days_from_date({2018, 4, 1})],
[2, 5, 3, "Chief Operating Officer", days_from_date({2018, 4, 8})],
[2, 5, 4, "Tech Evangelist", days_from_date({2018, 4, 15})],
[2, 5, 5, "Facial Recognition", days_from_date({2018, 4, 22})],
[2, 6, 1, "Artificial Emotional Intelligence", days_from_date({2019, 10, 27})],
[2, 6, 2, "Blood Money", days_from_date({2019, 11, 3})],
[2, 6, 3, "Hooli Smokes!", days_from_date({2019, 11, 10})],
[2, 6, 4, "Maximizing Alphaness", days_from_date({2019, 11, 17})],
[2, 6, 5, "Tethics", days_from_date({2019, 11, 24})],
[2, 6, 6, "RussFest", days_from_date({2019, 12, 1})],
[2, 6, 7, "Exit Event", days_from_date({2019, 12, 8})]
].

days_from_date({Year, Month, Day}) ->
calendar:date_to_gregorian_days(Year, Month, Day) - calendar:date_to_gregorian_days(1970, 1, 1).

format_date(Days) ->
Date = calendar:gregorian_days_to_date(Days + calendar:date_to_gregorian_days(1970, 1, 1)),
{Year, Month, Day} = Date,
io_lib:format("~4..0B-~2..0B-~2..0B", [Year, Month, Day]).
Loading
Loading