Hi, For the record, the best "solution" I found so far is to use the following test condition, but I am sure there must be a better way I am missing, here:
typeof val.xxx === 'object' && xdmp.describe(val.xxx) === 'null' Regards, -- Florent Georges http://fgeorges.org/ http://h2oconsulting.be/ On 2 August 2016 at 00:39, Florent Georges wrote: > Hi, > > How is a missing optional value from SPARQL represented in JavaScript? > If I execute the following JavaScript code on a database with a triple > ":foo :bar 42" but nothing like ":foo :xxx 42": > > var sem = require('/MarkLogic/semantics'); > var res = sem.sparql( > 'PREFIX : <http://example.org/foo#> \ > SELECT * WHERE { \ > :foo :bar ?bar . \ > OPTIONAL { :foo :xxx ?xxx } \ > }'); > var val = res.next().value; > if ( val.xxx ) 'true'; else 'false'; > > then it returns "true" anyway. Even though xdmp.describe(val.xxx) > returns "null". > > What is the exact type of val.xxx? How can I test whether a variable > in an optional graph pattern has been bound or not, in JavaScript? > > Regards, > > -- > Florent Georges > http://fgeorges.org/ > http://h2oconsulting.be/ > > >
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
