Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-julialib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-julialib
Commits
0e070706
Commit
0e070706
authored
3 years ago
by
florian
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Implement setting of typed values
parent
d3c7b051
No related branches found
No related tags found
1 merge request
!7
ENH: Implement queries and entity retrieval
Pipeline
#12513
failed
3 years ago
Stage: info
Stage: code-style
Stage: setup
Stage: test
Stage: deploy
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Entity.jl
+166
-20
166 additions, 20 deletions
src/Entity.jl
test/runtests.jl
+9
-4
9 additions, 4 deletions
test/runtests.jl
with
175 additions
and
24 deletions
src/Entity.jl
+
166
−
20
View file @
0e070706
...
@@ -1524,15 +1524,23 @@ function set_unit(property::Ref{_Property}, unit::AbstractString)
...
@@ -1524,15 +1524,23 @@ function set_unit(property::Ref{_Property}, unit::AbstractString)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
end
end
# TODO(henrik, daniel)
overload to choose
the correct
set
# TODO(henrik, daniel)
There is no check for
the correct
datatype
#
function.
#
here. Should we add this?
"""
"""
function set_value(entity::Ref{_Entity}, value::AbstractString)
function set_value(
entity::Ref{_Entity},
value::Union{AbstractString,Number,Bool,Vector{T}},
) where {T<:Union{AbstractString,Number,Bool}}
Set the value of the given `entity` object. Throw an error if it
Set the value of the given `entity` object. Throw an error if it
doesn't have the correct role.
doesn't have the correct role. The value must be either string,
Boolean, Integer, Float, or a vector thereof.
"""
"""
function
set_value
(
entity
::
Ref
{
_Entity
},
value
::
AbstractString
)
function
set_value
(
entity
::
Ref
{
_Entity
},
value
::
Union
{
AbstractString
,
Number
,
Bool
,
Vector
{
T
}},
)
where
{
T
<:
Union
{
AbstractString
,
Number
,
Bool
}}
if
get_role
(
entity
)
!=
"PROPERTY"
if
get_role
(
entity
)
!=
"PROPERTY"
throw
(
throw
(
...
@@ -1542,13 +1550,80 @@ function set_value(entity::Ref{_Entity}, value::AbstractString)
...
@@ -1542,13 +1550,80 @@ function set_value(entity::Ref{_Entity}, value::AbstractString)
)
)
end
end
err_code
=
ccall
(
in_type
=
typeof
(
value
)
(
:
caosdb_entity_entity_set_value
,
CaosDB
.
library_name
),
if
in_type
<:
AbstractString
Cint
,
err_code
=
ccall
(
(
Ref
{
_Entity
},
Cstring
),
(
:
caosdb_entity_entity_set_string_value
,
CaosDB
.
library_name
),
entity
,
Cint
,
value
,
(
Ref
{
_Entity
},
Cstring
),
)
entity
,
value
,
)
elseif
in_type
<:
Bool
err_code
=
ccall
(
(
:
caosdb_entity_entity_set_boolean_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Bool
),
entity
,
value
,
)
elseif
in_type
<:
Integer
err_code
=
ccall
(
(
:
caosdb_entity_entity_set_int_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Clong
),
entity
,
Clong
(
value
),
)
elseif
in_type
<:
Number
err_code
=
ccall
(
(
:
caosdb_entity_entity_set_int_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Cdouble
),
entity
,
Cdouble
(
value
),
)
else
# Type is a vector now
length
=
Cint
(
length
(
value
))
if
in_type
<:
Vector
{
T
}
where
{
T
<:
AbstractString
}
err_code
=
ccall
(
(
:
caosdb_entity_entity_set_string_list_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Ptr
{
Ptr
{
Cchar
}},
Cint
),
entity
,
value
,
length
,
)
elseif
in_type
<:
Vector
{
T
}
where
{
T
<:
Bool
}
err_code
=
ccall
(
(
:
caosdb_entity_entity_set_boolean_list_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Ptr
{
Bool
},
Cint
),
entity
,
value
,
length
,
)
elseif
in_type
<:
Vector
{
T
}
where
{
T
<:
Integer
}
err_code
=
ccall
(
(
:
caosdb_entity_entity_set_int_list_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Ptr
{
Clong
},
Cint
),
entity
,
Vector
{
Clong
}(
value
),
length
,
)
elseif
integer
<:
Vector
{
T
}
where
{
T
<:
Number
}
err_code
=
ccall
(
(
:
caosdb_entity_entity_set_int_list_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Entity
},
Ptr
{
Cdouble
},
Cint
),
entity
,
Vector
{
Cdouble
}(
value
),
length
,
)
end
end
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
end
end
...
@@ -1559,14 +1634,85 @@ end
...
@@ -1559,14 +1634,85 @@ end
Set the value of the given `property` object.
Set the value of the given `property` object.
"""
"""
function
set_value
(
property
::
Ref
{
_Property
},
value
::
AbstractString
)
function
set_value
(
err_code
=
ccall
(
property
::
Ref
{
_Property
},
(
:
caosdb_entity_property_set_value
,
CaosDB
.
library_name
),
value
::
Union
{
AbstractString
,
Number
,
Bool
,
Vector
{
T
}},
Cint
,
)
where
{
T
<:
Union
{
AbstractString
,
Number
,
Bool
}}
(
Ref
{
_Property
},
Cstring
),
property
,
in_type
=
typeof
(
value
)
value
,
if
in_type
<:
AbstractString
)
err_code
=
ccall
(
(
:
caosdb_entity_property_set_string_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Cstring
),
property
,
value
,
)
elseif
in_type
<:
Bool
err_code
=
ccall
(
(
:
caosdb_entity_property_set_boolean_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Bool
),
property
,
value
,
)
elseif
in_type
<:
Integer
err_code
=
ccall
(
(
:
caosdb_entity_property_set_int_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Clong
),
property
,
Clong
(
value
),
)
elseif
in_type
<:
Number
err_code
=
ccall
(
(
:
caosdb_entity_property_set_int_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Cdouble
),
property
,
Cdouble
(
value
),
)
else
# Type is a vector now
length
=
Cint
(
length
(
value
))
if
in_type
<:
Vector
{
T
}
where
{
T
<:
AbstractString
}
err_code
=
ccall
(
(
:
caosdb_entity_property_set_string_list_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Ptr
{
Ptr
{
Cchar
}},
Cint
),
property
,
value
,
length
,
)
elseif
in_type
<:
Vector
{
T
}
where
{
T
<:
Bool
}
err_code
=
ccall
(
(
:
caosdb_entity_property_set_boolean_list_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Ptr
{
Bool
},
Cint
),
property
,
value
,
length
,
)
elseif
in_type
<:
Vector
{
T
}
where
{
T
<:
Integer
}
err_code
=
ccall
(
(
:
caosdb_entity_property_set_int_list_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Ptr
{
Clong
},
Cint
),
property
,
Vector
{
Clong
}(
value
),
length
,
)
elseif
integer
<:
Vector
{
T
}
where
{
T
<:
Number
}
err_code
=
ccall
(
(
:
caosdb_entity_property_set_int_list_value
,
CaosDB
.
library_name
),
Cint
,
(
Ref
{
_Property
},
Ptr
{
Cdouble
},
Cint
),
property
,
Vector
{
Cdouble
}(
value
),
length
,
)
end
end
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
CaosDB
.
Exceptions
.
evaluate_return_code
(
err_code
)
end
end
...
...
This diff is collapsed.
Click to expand it.
test/runtests.jl
+
9
−
4
View file @
0e070706
...
@@ -138,10 +138,7 @@ using CaosDB
...
@@ -138,10 +138,7 @@ using CaosDB
CaosDB
.
Entity
.
get_parent
(
rec_with_parent_and_props
,
Cint
(
1
)),
CaosDB
.
Entity
.
get_parent
(
rec_with_parent_and_props
,
Cint
(
1
)),
)
==
"Parent2"
)
==
"Parent2"
# TODO(henrik, daniel) re-enable once values can be set again
prop1
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property1"
,
value
=
"2"
)
prop1
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property1"
,
# value = "2"
)
prop2
=
CaosDB
.
Entity
.
create_property
(
id
=
"id_of_property_2"
)
prop2
=
CaosDB
.
Entity
.
create_property
(
id
=
"id_of_property_2"
)
CaosDB
.
Entity
.
set_datatype
(
prop2
,
"TEXT"
)
CaosDB
.
Entity
.
set_datatype
(
prop2
,
"TEXT"
)
prop3
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property3"
)
prop3
=
CaosDB
.
Entity
.
create_property
(
name
=
"Property3"
)
...
@@ -168,4 +165,12 @@ using CaosDB
...
@@ -168,4 +165,12 @@ using CaosDB
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
2
],
CaosDB
.
Entity
.
get_properties
(
rec_with_parent_and_props
)[
2
],
)
==
"Property3"
)
==
"Property3"
end
end
@testset
"Datatype and values"
begin
# TODO(hernik, daniel) tests for some kinds of datatypes and
# values. We probably don't need all since the actual
# functions are already being tested in the C++ client but at
# least some strings, numbers, and lists thereof should be
# tested here, too
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment