Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CaosDB Octave library
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 Octave library
Commits
15087d94
Commit
15087d94
authored
3 years ago
by
Daniel Hornung
Browse files
Options
Downloads
Patches
Plain Diff
ENH: Support for COUNT queries.
parent
70aa4c4e
No related branches found
No related tags found
1 merge request
!2
ENH: Retrieving single entities works on the mex side.
Pipeline
#11982
passed with warnings
3 years ago
Stage: setup
Stage: test
Stage: deploy
Pipeline: caosdb-octaveinttest
#12039
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Caosdb.m
+6
-2
6 additions, 2 deletions
src/Caosdb.m
src/private/maox_query.cpp
+18
-7
18 additions, 7 deletions
src/private/maox_query.cpp
with
24 additions
and
9 deletions
src/Caosdb.m
+
6
−
2
View file @
15087d94
...
...
@@ -123,6 +123,7 @@ classdef Caosdb < handle
%
Execute
a
query
%
%
entities
=
Caosdb
.
query
(
"FIND Record Foo WITH bar=baz"
)
%
entities
=
Caosdb
.
query
(
"COUNT Record Foo WITH bar=baz"
)
%
%
Parameters
%
----------
...
...
@@ -133,7 +134,7 @@ classdef Caosdb < handle
%
Returns
%
-------
%
entities
:
cell
array
%
The
retrieved
entities
.
%
The
retrieved
entities
.
If
the
query
was
a
COUNT
query
,
the
result
is
an
int64
instead
.
function
entities
=
query
(
obj
,
query_str
)
%
Ensure
that
QUERY
is
a
string
.
assert
(
ischar
(
query_str
),
"maox:InvalidArgument"
,
"QUERY must be a string, was:
\n
%s"
,
...
...
...
@@ -142,8 +143,11 @@ classdef Caosdb < handle
%
disp
(
"query:"
);
%
disp
(
query_str
);
try
collection
=
maox_query
(
obj
.
connection
,
query_str
);
[
collection
,
count_results
]
=
maox_query
(
obj
.
connection
,
query_str
);
entities
=
maox_convert_collection
(
collection
);
if
(
count_results
>=
0
)
entities
=
count_results
;
end
catch
%
disp
(
"error handling in Caosdb.m"
);
%
disp
(
lasterror
());
...
...
This diff is collapsed.
Click to expand it.
src/private/maox_query.cpp
+
18
−
7
View file @
15087d94
...
...
@@ -19,14 +19,16 @@ using std::string;
*
* @details This function returns the entities as a cell array.
*
* @param connection_name A string with the connection name. May be omitted or
* an empty string.
* @param connection_name A string with the connection name. May be omitted or an empty string.
*
* @param query The query string.
* @param query
The query string.
*
* @return collection A struct with the entities.
* @return resultSet A struct with the entities.
*
* @return countResult The result of a COUNT query, is -1 if zero or more than one COUNT queries
* were given.
*/
void
mexFunction
(
int
/*
nlhs
*/
,
mxArray
*
plhs
[],
int
nrhs
,
const
mxArray
*
prhs
[])
{
void
mexFunction
(
int
nlhs
,
mxArray
*
plhs
[],
int
nrhs
,
const
mxArray
*
prhs
[])
{
string
conn_name
;
string
query
;
...
...
@@ -41,6 +43,14 @@ void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs, const mxArray *prhs[])
mexErrMsgIdAndTxt
(
"maox:TooManyArguments"
,
"Need 2 arguments: connection_name and a query string."
);
}
if
(
nlhs
<
2
)
{
mexErrMsgIdAndTxt
(
"maox:InsufficientReturnArguments"
,
"Need 2 return arguments: resultSet and queryCount."
);
}
if
(
nlhs
>
2
)
{
mexErrMsgIdAndTxt
(
"maox:TooManyReturnArguments"
,
"Need 2 return arguments: resultSet and queryCount."
);
}
if
(
!
mxIsChar
(
prhs
[
1
]))
{
mexErrMsgIdAndTxt
(
"maox:InvalidArgument"
,
"The second argument must be a string."
);
}
...
...
@@ -65,10 +75,11 @@ void mexFunction(int /*nlhs*/, mxArray *plhs[], int nrhs, const mxArray *prhs[])
auto
t_stat
=
transaction
->
WaitForIt
();
maoxdb
::
throwOctExceptionIfError
(
transaction
.
get
());
// Status must be OK or GENERIC_TRANSACTION_ERROR now.
const
auto
&
results
=
transaction
->
GetResultSet
();
// std::cout << "size: " << results.Size() << std::endl;
const
auto
&
results
=
transaction
->
GetResultSet
();
auto
*
mxResults
=
maoxdb
::
mxFromResultSet
(
results
);
auto
*
mxCountResults
=
maoxdb
::
mxScalarINT64
(
transaction
->
GetCountResult
());
plhs
[
0
]
=
mxDuplicateArray
(
mxResults
);
plhs
[
1
]
=
mxCountResults
;
}
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