diff --git a/src/Entity.jl b/src/Entity.jl index c1a259358379241f9f06455e73f3cc17de840d41..ef2ea915da9de96539fefbba550254af8f42b418 100644 --- a/src/Entity.jl +++ b/src/Entity.jl @@ -305,7 +305,7 @@ function create_property(; set_id(property, id) end - if value + if value != "" set_value(property, value) end @@ -805,7 +805,7 @@ function get_error(entity::Ref{_Entity}, index::Cint) Cint, (Ref{_Entity}, Cint), entity, - index - 1, + index - Cint(1), ) CaosDB.Exceptions.evaluate_return_code(err_code) @@ -817,6 +817,19 @@ function get_error(entity::Ref{_Entity}, index::Cint) return CaosDB.Exceptions.CaosDBMessage(message_text, code) end +""" + function get_error(entity::Ref{_Entity}, index::Integer) + +Convenience wrapper for `get_error(::Ref{_Entity}, ::Cint)`. Convert +`index` to Int32 and return the error at position `index` of the given +`entity`. +""" +function get_error(entity::Ref{_Entity}, index::Integer) + + return get_error(entity, Cint(index)) + +end + """ function get_warning(entity::Ref{_Entity}, index::Cint) @@ -832,7 +845,7 @@ function get_warning(entity::Ref{_Entity}, index::Cint) Cint, (Ref{_Entity}, Cint), entity, - index - 1, + index - Cint(1), ) CaosDB.Exceptions.evaluate_return_code(err_code) @@ -844,6 +857,18 @@ function get_warning(entity::Ref{_Entity}, index::Cint) return CaosDB.Exceptions.CaosDBMessage(message_text, code) end +""" + function get_warning(entity::Ref{_Entity}, index::Integer) + +Convenience wrapper for `get_warning(::Ref{_Entity}, ::Cint)`. Convert +`index` to Int32 and return the warning at position `index` of the given +`entity`. +""" +function get_warning(entity::Ref{_Entity}, index::Integer) + + return get_warning(entity, Cint(index)) + +end """ function get_info(entity::Ref{_Entity}, index::Cint) @@ -860,7 +885,7 @@ function get_info(entity::Ref{_Entity}, index::Cint) Cint, (Ref{_Entity}, Cint), entity, - index - 1, + index - Cint(1), ) CaosDB.Exceptions.evaluate_return_code(err_code) @@ -872,6 +897,20 @@ function get_info(entity::Ref{_Entity}, index::Cint) return CaosDB.Exceptions.CaosDBMessage(message_text, code) end +""" + function get_info(entity::Ref{_Entity}, index::Integer) + +Convenience wrapper for `get_info(::Ref{_Entity}, ::Cint)`. Convert +`index` to Int32 and return the info at position `index` of the given +`entity`. +""" +function get_info(entity::Ref{_Entity}, index::Integer) + + return get_info(entity, Cint(index)) + +end + + """ function get_errors(entity::Ref{_Entity}) @@ -954,12 +993,16 @@ function get_parent(entity::Ref{_Entity}, index::Cint) parent = Ref{_Parent}(_Parent()) + println(index - Cint(1)) + println(typeof(index - Cint(1))) + err_code = ccall( (:caosdb_entity_entity_get_parent, CaosDB.library_name), Cint, - (Ref{_Entity}, Ref{Cint}), + (Ref{_Entity}, Ref{_Parent}, Ref{Cint}), entity, - index - 1, + parent, + index - Cint(1), ) CaosDB.Exceptions.evaluate_return_code(err_code) @@ -967,6 +1010,20 @@ function get_parent(entity::Ref{_Entity}, index::Cint) return parent end +""" + function get_parent(entity::Ref{_Entity}, index::Integer) + +Convenience wrapper for `get_parent(::Ref{_Entity}, ::Cint)`. Convert +`index` to Int32 and return the parent at position `index` of the given +`entity`. +""" +function get_parent(entity::Ref{_Entity}, index::Integer) + + return get_parent(entity, Cint(index)) + +end + + """ function get_parents(entity::Ref{_Entity}) @@ -1003,9 +1060,10 @@ function get_property(entity::Ref{_Entity}, index::Cint) err_code = ccall( (:caosdb_entity_entity_get_property, CaosDB.library_name), Cint, - (Ref{_Entity}, Ref{Cint}), + (Ref{_Entity}, Ref{_Property}, Ref{Cint}), entity, - index - 1, + property, + index - Cint(1), ) CaosDB.Exceptions.evaluate_return_code(err_code) @@ -1013,6 +1071,21 @@ function get_property(entity::Ref{_Entity}, index::Cint) return property end + +""" + function get_property(entity::Ref{_Entity}, index::Integer) + +Convenience wrapper for `get_property(::Ref{_Entity}, ::Cint)`. Convert +`index` to Int32 and return the property at position `index` of the given +`entity`. +""" +function get_property(entity::Ref{_Entity}, index::Integer) + + return get_property(entity, Cint(index)) + +end + + """ function get_properties(entity::Ref{_Entity}) @@ -1339,7 +1412,7 @@ function remove_parent(entity::Ref{_Entity}, index::Cint) Cint, (Ref{_Entity}, Cint), entity, - index - 1, + index - Cint(1), ) CaosDB.Exceptions.evaluate_return_code(err_code) @@ -1391,7 +1464,7 @@ function remove_property(entity::Ref{_Entity}, index::Cint) Cint, (Ref{_Entity}, Cint), entity, - index - 1, + index - Cint(1), ) CaosDB.Exceptions.evaluate_return_code(err_code) diff --git a/test/runtests.jl b/test/runtests.jl index 6350b16b02f1bd36013117a61c6657be1ce88d88..cbb339ee74ce7b85b7aa744f1631e9d5cfa249f1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -116,11 +116,12 @@ using CaosDB par2 = CaosDB.Entity.create_parent(name = "Parent2", id = "id_of_parent_2") CaosDB.Entity.append_parents(rec_with_parent_and_props, [par1, par2]) @test length(CaosDB.Entity.get_parents(rec_with_parent_and_props)) == 2 + # Getting has to work with all Integers that can be cast to Cint @test CaosDB.Entity.get_name( CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(1)), ) == "Parent1" @test CaosDB.Entity.get_name( - CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(2)), + CaosDB.Entity.get_parent(rec_with_parent_and_props, 2), ) == "Parent2" @test CaosDB.Entity.get_id( CaosDB.Entity.get_parent(rec_with_parent_and_props, Cint(2)),