I want to run the following sparql query at an endpoint:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT ?name WHERE{?person foaf:name ?name.FILTER regex(str(?name), "+ns+","i")}
I'm coding in C# on Visual Studio, and would send this query to the endpoint. It should check the results without any case-senstivity, but writing the query this way gives an error in visual studio. How do I correct it?
Update (based on author's clarification that "i" is where the problem lies):
You need to properly escape the " symbol so that it gets included in the SPARQL query string. Currently the ["] before [i] signals the end of the text string. No wonder you get an error message.
See MSDN: String literals for escaping rules:
either " escape as \" or make the string a C# verbatim literal and escape as ""
Check DotNetRdf documentation for Querying with SPARQL examples.
It shows both how to run SPARQL queries (using DotNetRdf) and how to inject variable values into queries (what you are trying to do with "+ns+" and "i").
Also:
answers.semanticweb.com is a good place to ask Semantic Web / RDF / SPARQL questions
please describe the error you are getting (what Ren asked in comments above)
Related
I have the following query in a MarkLogic XQuery file, and I am seeing the following error message returned
XDMP-ENTITYREF: (err:XPST0003) Invalid entity reference " " . See the MarkLogic server error log for further detail.
The following is the code I am using in the XQuery file.
xquery version "1.0-ml";
declare variable $query :=
cts:or-query
((
cts:element-word-query(xs:QName("lines"),"l&l"),
cts:element-word-query(xs:QName("lines"),"pool & cue"),
cts:element-word-query(xs:QName("lines"),"look")
));
declare function local:do-query(){
element xml {
for $i in cts:uris( (), (), $query)
let $item := doc($i)
return
element item {
element title { $item/title/string() }
}
}
};
local:do-query()
Obviously the 2x tags i am looking for are l&l and pool & cue. I have also looked into the repair-full suggestion in another question posted, but couldn't figure out how that fits into this query. If I removed the ones with special characters, it works as expected.
Any ideas?
Based on the additional info in the comments to the question, this is not an issue with the execution of the code, but rather with deployment of the code.
This happens often if you insert code using QConsole, or some other ways in which you evaluate XQuery code. The & get interpreted, and translated to the & character it represents. If you then write that into a .xqy file into some Modules database, it does not get escaped back into & again, since XQuery files are stored as plain text in MarkLogic, and & doesn't get escaped in plain text.
A better way to deploy code is by uploading or inserting from disk. That way characters like &, >, and { inside XML won't get interpreted, but preserved and inserted as is. There are tools like ml-gradle and Roxy that make deploying MarkLogic code very easy. Consider using these. Alternatively you could also look into using Curl against the Management REST api.
If you want to use QConsole after all, escape characters like & twice. E.g. & becomes &, and < becomes <.
HTH!
I've tried to search but didn't found an answer.
I've created with PL/SQL, HTML, CSS and Javascript a web application.
People can search for article and write a comment to These articles.
If they click the submit button it starts to search with the conditions of the customer.
I send the conditions as param and store them into variables.
After that I start my Statement and refresh the page with the new records.
If someone writes a comment with Special characters like
(&, %, ", ', _)
my page crashes because the Statement string isn't correct anymore.
The Statement Looks like
SELECT * FROM myTable
WHERE Name LIKE ('''%'||nameVar||'%''');
Excuse my english
Thanks
Ok, first your question about "ESCAPING" lead me to the wrong way, because you can define a "ESCAPE" character for a like Statement: This would take your % or _ in your Statement literal:
where ..... like '%\%%' ESCAPE '\'
should find a record with an % in the column.
BUT THATS NOT YOUR PROBLEM!
Your web application has to HTML encode your string - then you can store it in any database.
This has to be done by your frontend (whatever it is: ASP.NET, PHP, etc ...)
After a short Google search I found this: HTF Package, the HTF.ESCAPE_SC function encodes the string to be useable in SQL Statements.
Maybe this link helps you: https://docs.oracle.com/cd/B14099_19/web.1012/b15896/pshtp.htm
In the documentation for jsonapi for pagination is says the following:
For example, a page-based strategy might use query parameters such as
page[number] and page[size]
How would I represent this in the query string? http://localhost:4200/people?page[number]=1&page[size]=25, I don't think using a map link structure is a valid query string. Only the page parameter is reserved according to the documentation.
I don't think using a map link structure is a valid query string.
You're right technically, and that's why the spec has the note that says:
Note: The example query parameters above use unencoded [ and ] characters simply for readability. In practice, these characters must be percent-encoded, per the requirements in RFC 3986.
So, page[size] is really page%5Bsize%5D which is a valid query parameter name.
Only the page parameter is reserved according to the documentation.
When the spec text says that only page is reserved, it actually means that any page[......] style query parameter is reserved. (I can tell you that for sure as one of the spec's editors.) But it should say so more explicitly, so I'll open an issue for it.
What I don't really understand is the benefit of using '?' instead of '&' in urls:
It makes nobody's life easier if we use a different character as the first separator character.
Can you come up with a reasonable explanation?
EDIT: after more research I found that "&" can be a part of file name (terms&conditions.html) so "?" is a good separator. But still I think using "?" for separators makes lives easier (from url generators and parsers point of view):
Is there any advantage in using "&" which is not clear at the first glance?
From the URI spec's (RFC 3986) point of view, the only separator here is "?". the format of the query is opaque; the ampersands just are something that HTML happens to use for form submissions.
The answer's pretty much in this article - http://www.skorks.com/2010/05/what-every-developer-should-know-about-urls/ . To highlight it, here goes :
Query is the preferred way to send some parameters to a resource on
the server. These are key=value pairs and are separated from the rest
of the URL by a ? (question mark) character and are normally separated
from each other by & (ampersand) characters. What you may not know is
the fact that it is legal to separate them from each other by the ;
(semi-colon) character as well. The following URLs are equivalent:
http://www.blah.com/some/crazy/path.html?param1=foo¶m2=bar
http://www.blah.com/some/crazy/path.html?param1=foo;param2
The RFC 3896 (https://www.ietf.org/rfc/rfc3986.txt) defines general and sub delimiters ... '?' is a general, '&' and ';' are sub. The spec is pretty clear about that.
In this case the latter '?' chars would be treated as part of the query. If the query parser follows the spec strictly, it would then pass the whole query on to the app-destination. If the app-destination could choose to further process the query string in a manner which treats the ? as a param name-value pairs delimiter, that is up to the app's designers.
My guess is that this often 'just works' because code that splits query strings and the original uri uses all delimiters for matching: 1) first query is split on '?' then 2) query string is parsed using char match list that includes '?' (convenience only).... This could be occurring in ubiquitous parsing libraries already.
I am trying to access the following info using FQL in c# .However am getting an HTTP bad request error
string Frnds = api.Get("/fql?q=SELECT+uid+name+username+locale+affiliations+timezone+birthday+sex+proxied_email+current_location+FROM+user+WHERE+uid=me()");
Is there some problem with my query , It seems to look fine to me ?
Have you tried separating each field name with a comma (,) then urlencoding it
you can test out your query here - please note in the following link I added in ","
https://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20uid%2C%20name%2C%20username%2C%20locale%2C%20affiliations%2C%20timezone%2C%20birthday%2C%20sex%2C%20proxied_email%20%2Ccurrent_location%20FROM%20user%20WHERE%20uid%3Dme%28%29
your query can't parse the fields correctly
https://developers.facebook.com/tools/explorer?method=GET&path=fql%3Fq%3DSELECT%20uid%20name%20username%20locale%20affiliations%20timezone%20birthday%20sex%20proxied_email%20current_location%20FROM%20user%20WHERE%20uid%3Dme%28%29