Character "+" removed from query when heredoc is used in bash script to run sparql queries

#1

Dear all,

I use heredoc in a bash script to run sparql queries and it works fine except when I use the character “+” inside of a heredoc block. It seems that the character “+” is removed by the exec parameter before to run the query. The bash script is this:

#!/bin/bash
/usr/local/virtuoso-opensource/bin/isql-v 1111 dba dba <<'EOF' exec="
select ?s ?t year(?d) as ?enroll_year count(distinct ?tst) as ?nb_test
where {?e sides:correspond_to_student ?s.
?e sides:correspond_to_training ?t.
?e sides:has_for_registration_date ?d.
?ata sides:done_during ?tst.
?ata sides:is_part_of ?a.
?a sides:done_by ?s.
?a sides:has_for_timestamp ?ds.
filter(year(?ds)=year(?d)+1).
}
group by ?s ?e ?t year(?d)
order by ?s ?t
" > /download/output.txt 
EOF

When I run the bash script, the query

select ?s ?t year(?d) as ?enroll_year count(distinct ?tst) as ?nb_test
where {?e sides:correspond_to_student ?s.
?e sides:correspond_to_training ?t.
?e sides:has_for_registration_date ?d.
?ata sides:done_during ?tst.
?ata sides:is_part_of ?a.
?a sides:done_by ?s.
?a sides:has_for_timestamp ?ds.
filter(year(?ds)=year(?d)+1).
}
group by ?s ?e ?t year(?d)
order by ?s ?t

becomes

select ?s ?t year(?d) as ?enroll_year count(distinct ?tst) as ?nb_test
where {?e sides:correspond_to_student ?s.
?e sides:correspond_to_training ?t.
?e sides:has_for_registration_date ?d.
?ata sides:done_during ?tst.
?ata sides:is_part_of ?a.
?a sides:done_by ?s.
?a sides:has_for_timestamp ?ds.
filter(year(?ds)=year(?d) 1).
}
group by ?s ?e ?t year(?d)
order by ?s ?t

as you notice, the character “+” is removed in the second query.

Any idea about this?

Thanks in advance

Adam

0 Likes

#2

The problem with the ‘+’ character is that the iSQL program in the past was both used as a command line tool as well as a CGI binary. For this second use, a number of strings are parsed and certain special chars are changed.

As the code of isql.c is rather archaic, i will have to think about a way to fix this issue, however there is a more common heredoc method you can use in your script that does not suffer from the same replacement:

#!/bin/bash
/usr/local/virtuoso-opensource/bin/isql-v 1111 dba dba <<EOF >/download/output.txt
SPARQL
select ?s ?t year(?d) as ?enroll_year count(distinct ?tst) as ?nb_test
where {?e sides:correspond_to_student ?s.
?e sides:correspond_to_training ?t.
?e sides:has_for_registration_date ?d.
?ata sides:done_during ?tst.
?ata sides:is_part_of ?a.
?a sides:done_by ?s.
?a sides:has_for_timestamp ?ds.
filter(year(?ds)=year(?d)+1).
}
group by ?s ?e ?t year(?d)
order by ?s ?t
;
EOF

Please note that as you are trying to run a SPARQL query using isql, you have to put the sparql
keyword in front of your select statement.

0 Likes