diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b58f19c15a34a7adc5ddc9d12859cf913b4e63e7..022ad3e1851857c97a5588d066b8783d7ad3f8de 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -182,6 +182,7 @@ trigger_inttest: -F "variables[TRIGGERED_BY_REF]=$TRIGGERED_BY_REF" -F "variables[TRIGGERED_BY_HASH]=$TRIGGERED_BY_HASH" -F "variables[JULIALIB_REGISTRY_IMAGE]=$JULIALIB_REGISTRY_IMAGE" + -F "variables[CPPLIB_REF]=${CPP_DEFAULT_BRANCH}" -F "variables[F_BRANCH]=${F_BRANCH}" -F ref=${JULIAINT_REF} $JULIAINTTEST_PIPELINE 2>HTTPCODE diff --git a/CHANGELOG.md b/CHANGELOG.md index 4134859fad83374c1666ce8a23d88d6b3d22df27..c0be7c0da9095f4876f5aeb2c5dcc34f287544fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,5 +26,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed * `get_value` functions for properties and entities +* `retrieve` function (no SegFaults anymore) ### Security diff --git a/docs/src/api.md b/docs/src/api.md index c355666e6806bd2ad15b7b67f3dff008b985b4f0..3c52343029ab41c669fd10019c0caabc7749e7af 100644 --- a/docs/src/api.md +++ b/docs/src/api.md @@ -12,7 +12,7 @@ Order = [:module, :function, :macro, :type, :constant] ## Public API ```@autodocs -Modules=[CaosDB, CaosDB.Exceptions, CaosDB.Info, CaosDB.Utility, +Modules=[CaosDB, CaosDB.Exceptions, CaosDB.Constants, CaosDB.Info, CaosDB.Utility, CaosDB.Connection, CaosDB.Authentication, CaosDB.Entity, CaosDB.Transaction] Private=false @@ -21,7 +21,7 @@ Private=false ## Expert-use only API functions ```@autodocs -Modules=[CaosDB, CaosDB.Exceptions, CaosDB.Info, CaosDB.Utility, +Modules=[CaosDB, CaosDB.Exceptions, CaosDB.Constants, CaosDB.Info, CaosDB.Utility, CaosDB.Connection, CaosDB.Authentication, CaosDB.Entity, CaosDB.Transaction] Public=false diff --git a/src/CaosDB.jl b/src/CaosDB.jl index 6122a0baf4541346ebc67436956ad0594dc92bab..e15b46db7c84354f7c72d818ce83fc57dee117b6 100644 --- a/src/CaosDB.jl +++ b/src/CaosDB.jl @@ -28,8 +28,11 @@ module CaosDB export evaluate_return_code, CaosDBException, ClientException, GenericCaosDBException, CaosDBMessage +# Exports from module Constants +export MIN_CCAOSDB_VERSION + # Exports from module Utility -export get_env_fallback +export get_ccaosdb_version, get_env_fallback # Export from module Connection export connect, connect_manually @@ -122,6 +125,8 @@ end include("Exceptions.jl") +include("Constants.jl") + include("Info.jl") include("Utility.jl") @@ -134,6 +139,7 @@ include("Entity.jl") include("Transaction.jl") -using .Exceptions, .Info, .Authentication, .Connection, .Utility, .Entity, .Transaction +using .Exceptions, + .Constants, .Info, .Authentication, .Connection, .Utility, .Entity, .Transaction end # CaosDB diff --git a/src/Constants.jl b/src/Constants.jl new file mode 100644 index 0000000000000000000000000000000000000000..b1e5db73dc4672aa719861d5cf58e5fc918d9939 --- /dev/null +++ b/src/Constants.jl @@ -0,0 +1,34 @@ +# ** header v3.0 +# This file is a part of the CaosDB Project. +# +# Copyright (C) 2021 Indiscale GmbH <info@indiscale.com> +# Copyright (C) 2021 Florian Spreckelsen <f.spreckelsen@indiscale.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public +# License along with this program. If not, see +# <https://www.gnu.org/licenses/>. +# +# ** end header +# + +module Constants + +export MIN_CCAOSDB_VERSION + +""" +The minimum version of CaosDB's cpplib and C interface that is +supported by this version of CaosDB.jl. +""" +const MIN_CCAOSDB_VERSION = v"0.0.16" + +end diff --git a/src/Transaction.jl b/src/Transaction.jl index d6889148229efd8752f55308cb9c73dc528c676b..1d837061e792cfa27f75cf16e6aae1c25b625d60 100644 --- a/src/Transaction.jl +++ b/src/Transaction.jl @@ -433,6 +433,44 @@ function get_result_at(results::Ref{_ResultSet}, index::Cint) return entity end +""" + function _release_result_at(results::Ref{_ResultSet}, index::Cint) + +Return the entity at position `index` of the given `results`. + +This function releases the entity from the result set and leaves the result set +in a corrupted state. It should only be used to release the entity from a +result set which is about to be destroyed anyway. +""" +function _release_result_at(results::Ref{_ResultSet}, index::Cint) + + size = get_result_size(results) + + if index > size + throw( + DomainError( + index, + "You tried to access the result at position $index but the result set only has $size results.", + ), + ) + end + + entity = Ref{CaosDB.Entity._Entity}(CaosDB.Entity._Entity()) + + err_code = ccall( + (:caosdb_transaction_result_set_release_at, CaosDB.library_name), + Cint, + (Ref{_ResultSet}, Ref{CaosDB.Entity._Entity}, Cint), + results, + entity, + index - Cint(1), + ) + + CaosDB.Exceptions.evaluate_return_code(err_code) + + return entity +end + """ function get_result_at(results::Ref{_ResultSet}, index::Integer) @@ -448,7 +486,7 @@ end """ function get_results(result_set::Ref{_ResultSet}) -Return al results of the given `result_set`. +Return all entities of the given `result_set`. """ function get_results(result_set::Ref{_ResultSet}) @@ -469,6 +507,39 @@ function get_results(transaction::Ref{_Transaction}) return get_results(result_set) end +""" + function _release_results(transaction::Ref{_Transaction}) + +Return all results fo the given `transaction`. + +This function also leaves the transaction object in a corrupted state and +should only be used to release the results from a transaction which is about to +be destroyed anyway. +""" +function _release_results(transaction::Ref{_Transaction}) + + result_set = get_result_set(transaction) + + return _release_results(result_set) +end + +""" + function _release_results(result_set::Ref{_ResultSet}) + +Return all entities of the given `result_set`. + +This function also leaves the result_set object in a corrupted state and +should only be used to release the entities from a result_set which is about to +be destroyed anyway. +""" +function _release_results(result_set::Ref{_ResultSet}) + + size = get_result_size(result_set) + + return [_release_result_at(result_set, Cint(ii)) for ii = 1:size] +end + + """ function execute_query( query::AbstractString, @@ -495,7 +566,7 @@ function execute_query(query::AbstractString, name::AbstractString = "default") execute(transaction) - return get_results(transaction) + return _release_results(transaction) end """ @@ -526,7 +597,7 @@ function execute_query( execute(transaction) - return get_results(transaction) + return _release_results(transaction) end """ @@ -544,7 +615,7 @@ function retrieve(id::AbstractString, name::AbstractString = "default") execute(transaction) - return get_results(transaction)[1] + return _release_results(transaction)[1] end """ @@ -561,7 +632,7 @@ function retrieve(id::AbstractString, connection::Ref{CaosDB.Connection._Connect execute(transaction) - return get_results(transaction)[1] + return _release_results(transaction)[1] end """ @@ -585,7 +656,7 @@ function retrieve( execute(transaction) - return get_results(transaction) + return _release_results(transaction) end """ @@ -608,7 +679,7 @@ function retrieve( execute(transaction) - return get_results(transaction) + return _release_results(transaction) end """ function insert_entity(entity::Ref{CaosDB.Entity._Entity}) @@ -620,7 +691,7 @@ function insert_entity(entity::Ref{CaosDB.Entity._Entity}) transaction = create_transaction() add_insert_entity(transaction, entity) execute(transaction) - return get_results(transaction) + return _release_results(transaction) end """ function update_entity(entity::Ref{CaosDB.Entity._Entity}) @@ -632,7 +703,7 @@ function update_entity(entity::Ref{CaosDB.Entity._Entity}) transaction = create_transaction() add_update_entity(transaction, entity) execute(transaction) - return get_results(transaction) + return _release_results(transaction) end """ function delete_by_id(id::AbstractString) @@ -644,7 +715,7 @@ function delete_by_id(id::AbstractString) transaction = create_transaction() add_delete_by_id(transaction, id) execute(transaction) - return get_results(transaction) + return _release_results(transaction) end """ function retrieve_and_download_file_by_id( @@ -659,7 +730,7 @@ function retrieve_and_download_file_by_id(id::AbstractString, download_path::Abs transaction = create_transaction() add_retrieve_and_download_file_by_id(transaction, id, download_path) execute(transaction) - return get_results(transaction) + return _release_results(transaction) end end # Transaction diff --git a/src/Utility.jl b/src/Utility.jl index 4f74dcdf06487fc7e5c4d1639294442fe1c02b1e..d9364e5bca0501001bd801d4d7b8ca2231e69416 100644 --- a/src/Utility.jl +++ b/src/Utility.jl @@ -22,7 +22,7 @@ # module Utility -export get_env_fallback +export get_ccaosdb_version, get_env_fallback using ..CaosDB @@ -47,4 +47,22 @@ function get_env_fallback(var::AbstractString, default::AbstractString = "") end +""" + function get_ccaosdb_version() + +Return the version of the CaosDB C interface that is used by +CaosDB.jl. +""" +function get_ccaosdb_version() + + major = + ccall((:caosdb_constants_LIBCAOSDB_VERSION_MAJOR, CaosDB.library_name), Cint, ()) + minor = + ccall((:caosdb_constants_LIBCAOSDB_VERSION_MINOR, CaosDB.library_name), Cint, ()) + patch = + ccall((:caosdb_constants_LIBCAOSDB_VERSION_PATCH, CaosDB.library_name), Cint, ()) + + return VersionNumber("$major.$minor.$patch") +end + end # Utility diff --git a/test/runtests.jl b/test/runtests.jl index b452f8f4d34797600b122315ffe9874f672f72ab..c2ae2face7fdc82805eab16055069ae4a33c5b04 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -24,6 +24,11 @@ using Test using CaosDB @testset "CaosDBUnitTests" begin + @testset "TestCaosdbCppLibVersion" begin + + @test CaosDB.Utility.get_ccaosdb_version() >= CaosDB.Constants.MIN_CCAOSDB_VERSION + end + @testset "TestUtility" begin if haskey(ENV, "SHELL") shell_var = ENV["SHELL"]