exist-db cardinality for parameter - exist-db

I am new in exist-db and XQuery.
In exist-db I have this site map: The catalog "registranten" contains the catalog "data" (with xml-files) and the two files "regBasic.xql" and "regSearch.xql".
I am trying to search in the xml-files using the script regSearch.xql:
xquery version "3.0";
declare option exist:serialize "method=xhtml media-type=text/html";
declare variable $pageTitle := "Resultat";
declare variable $searchphrase := request:get-parameter("searchphrase", ());
<html>
<head>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=UTF-8"/>
<title>{$pageTitle}</title>
</head>
<body>
<h1>{$pageTitle}</h1>
<p>Søgestreng eller søgeord: "{$searchphrase}"</p>
<ul>
{
for $p in collection("/db/registranten/data")//grundtvig/indholdsregest/p[ft:query(., $searchphrase)]
return
<li>
from: {string(root($p)/grundtvig/filnavn)}<br/>
<i>$p</i>
</li>
}
</ul>
</body>
</html>
When I evaluate the script I get this error: "exerr:ERROR XPTY0004: The actual cardinality for parameter 2 does not match the cardinality declared in the function's signature: ft:query($nodes as node(), $query as item()) node(). Expected cardinality: exactly one, got 0. [at line 17, column 100, source: /db/apps/registranten/regSearch.xql]"
What does that mean and what is wrong with the script?

Your $searchphrase variable is an empty sequence, which likely suggests that you did not set the request parameter which you are asking for with request:get-parameter().

Related

sharing variables across freemarker files

I have 2 ftl files ( helloworld2.ftl and helloworld4.ftl ). I am trying to understand the variables sharing between ftl files. In helloworld4.ftl i have declared SharedVar and i am trying to access that varible in included file ie helloworld2.ftl. Am able to access. But at the end one set of extra error message im getting. why is it so?
I have used global instead of assign still same behaviour.
Contents of them follows
helloworld2.ftl :
<html>
<head>
<title>new file
</head>
<body>
<h1>${sharedVar}</h1>
</body>
</html>
helloworld4.ftl
<#assign sharedVar="sharedVar">
**********************
<#include "t2">
**********************
${sharedVar}*
ftl loading part,
Map<String, String> m = new HashMap<>();
m.put("t2", readFile("E://workspace//example//src//main//resources//templates//helloworld2.ftl"));
m.put("t4", readFile("E://workspace//example//src//main//resources//templates//helloworld4.ftl"));
for (Map.Entry<String, String> n : m.entrySet()) {
stringLoader.putTemplate(n.getKey(), n.getValue());
}
Output follows,
**********************
<html>
<head>
<title>new file
</head>
<body>
<h1>sharedVar</h1>
</body>
</html>
**********************
sharedVar*Aug 07, 2022 3:08:56 PM freemarker.log._JULLoggerFactory$JULLogger error
SEVERE: Error executing FreeMarker template
FreeMarker template error:
The following has evaluated to null or missing:
==> sharedVar [in template "t2" at line 7, column 17]

Explain the routing code calling signature for ESPAsyncWebServer

Here is one of the routes in my ESP32 app that is for ESPAsyncWebServer to interpret:
// Route to delete the data log file
server.on("/deletedata", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(SPIFFS, "/index.html", "text/html", false, processor);
DeleteFile(data_logfile);
});
Having had examples to inform me, my initial set of routes is working fine. But I am expanding with new pages and want to more fully understand what the method params are actually doing. For example, what is the full signature of request->send()? In particular, the second parameter ("/index.html") ? This is the origin file of the request as it turns out, but I don't understand why that is needed. Also, what is "processor"? The other params I understand pretty well. "DeleteFile(data_logfile);" calls a method in the ESP32 code that carries out the action indicated by the HTTP /deletedata request.
ESPAsyncWebServer works great but isn't that well-documented (that I can find).
request-send() accepts a file system type, a route to a page in the file system, a content type for the handled page, a flag indicating that the client should download that file or not and a processor function which will be called as the page gets send out to the client.
The processor function will be called as soon as the send() function finds a pair of two signal characters which is default to "%" in the asyncWebserver's case.
It is used for building a dynamic webpage with templates. If you have let's say an index.html file with templates, you can replace your template parameters with values using the Processor function.
Here is an example:
Index.html Page:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Example page</title>
</head>
<body>
<h1> %variableFromESP% </h1>
</body>
</html>
ESP endpoint:
/*
This processor function will be called if the server finds
something between two controll characters.
In this case: %variableFromESP%.
This processor function is used to replace this character
with whatever value.
*/
String processor( const String& var ){
if( var == "variableFromESP" ){
return "Hello World";
}
return "";
}
// Using LittleFs as a file system, a testPage.html route,text/html type
// do not download this file, and passing the processor function.
server.on("/testPage", HTTP_GET, [](AsyncWebServerRequest *request) {
request->send(LittleFs, "/testPage.html", "text/html", false, processor);
});

How to format HTML returned by Verify.PlayWright for better comparison

I am using Verify.PlayWright and to take HTML element snapshots. When the compare opens, all the HTML is on one line. This makes it hard to see the differences. Is there a way to format the HTML in order to get a nicer comparison?
var root = await page.QuerySelectorAsync("#sectionContainer .tree-root");
await Verifier.Verify(root);
You can use Verify.AngleSharp. It has a feature that ppretty prints html](https://github.com/VerifyTests/Verify.AngleSharp#pretty-print) for comparison purposes.
install https://nuget.org/packages/Verify.AngleSharp/
Call VerifyAngleSharpDiffing.Initialize() once at assembly load time.
use PrettyPrintHtml in your test:
[Test]
public Task PrettyPrintHtml()
{
var html = #"<!DOCTYPE html>
<html><body><h1>My First Heading</h1>
<p>My first paragraph.</p></body></html>";
return Verifier.Verify(html)
.UseExtension("html")
.PrettyPrintHtml();
}
which will produce a verified file containing
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>

How to view data retrieved in the controller in the view?

I'm trying to retrieve data in my controller using sqlsrv database connection and I want to view the result in my test.blade.php
public function index()
{
$cout_achat = DB::table('[DWH_SOVAC_PROD_KIT_LIFE_CYCLE]')
->select( DB::raw('SUM([MONTANT_LC]) as cout_achat'))
->get();
return view('test', ['test' => $cout_achat]);
}
and the code in the view
<html lang="{{ config('app.locale') }}">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600"
rel="stylesheet" type="text/css">
</head>
<body>
echo {{$cout_achat}};
</body>
</html>
but when I try to access myapp/test I get : ** Use of undefined constant test - assumed 'test' (this will throw an Error in a future version of PHP) (View: C:\wamp64\www\projetSovac\resources\views\test.blade.php) –**
About 404 the route you have provided is completely ok, can you please tell us how you are calling this route.
And please double check any typo in controller name.
Now I would like to talk about some improvement in your code
First of all is that when you return the view like this in your controller
return view('test', ['test' => $cout_achat]);
The $cout_achat will be available with name $test in your blade file. So you should try to use the same naming convention like
return view('test', ['cout_achat' => $cout_achat]);
Or simple you can use compact() laravels helper function like this
return view('test', compact(cout_achat));
It will automatically pass $cout_achat in blade.
Now for echoing the variable in balde you don't need to use echo explicitly like
echo {{$cout_achat}};
You can echo variables like
{{$cout_achat}}
Anything else will be handled automatically by blade compiler.
Hope this will help.

Read/write to Parse Core db from Google Apps Script

I'm just starting to use Parse Core (as Google'e ScriptDB is being decommissioned soon) and am having some trouble.
So I'm able to get Parse Core db to read/write using just a standard HTML page as shown below:
<!doctype html>
<head>
<meta charset="utf-8">
<title>My Parse App</title>
<meta name="description" content="My Parse App">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/styles.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://www.parsecdn.com/js/parse-1.2.18.min.js"></script>
</head>
<body>
<div id="main">
<h1>You're ready to use Parse!</h1>
<p>Read the documentation and start building your JavaScript app:</p>
<ul>
<li>Parse JavaScript Guide</li>
<li>Parse JavaScript API Documentation</li>
</ul>
<div style="display:none" class="error">
Looks like there was a problem saving the test object. Make sure you've set your application ID and javascript key correctly in the call to <code>Parse.initialize</code> in this file.
</div>
<div style="display:none" class="success">
<p>We've also just created your first object using the following code:</p>
<code>
var TestObject = Parse.Object.extend("TestObject");<br/>
var testObject = new TestObject();<br/>
testObject.save({foo: "bar"});
</code>
</div>
</div>
<script type="text/javascript">
Parse.initialize("PyMFUxyBxR8IDgndjZ378CeEXH2c6WLK1wK2JHYX", "IgiMfiuy3LFjzH0ehmyf5Rkti8AmVtwcGqc6nttN");
var TestObject = Parse.Object.extend("TestObject");
var testObject = new TestObject();
testObject.save({foo: "bar"}, {
success: function(object) {
$(".success").show();
},
error: function(model, error) {
$(".error").show();
}
});
</script>
</body>
</html>
However, when I try to serve that up using the HtmlService shown below, I get no response from Parse. Parse Core.html basically has all of the code I have above ( only thing I changed was to remove the css calls).
function doGet() {
var htmlPage = HtmlService.createTemplateFromFile('Parse Core.html')
.evaluate()
.setSandboxMode(HtmlService.SandboxMode.NATIVE)
.setTitle('Parse Core Test');
return htmlPage;
}
Link to ParseDb Library for Apps Script
Here is the key to add the library: MxhsVzdWH6ZQMWWeAA9tObPxhMjh3Sh48
Install that library and it allows you to use most of the same methods that were used by ScriptDb. As far as saving and querying go they almost identical. Make sure to read the Library's notes, how to add the applicationId and restApiKey. It is a little different that you can silo data by classes which must be defined in the call to Parse.
Bruce here is leading the way on database connection for Apps Script, he has plenty of documentation on using Parse.com, and also his own DbConncection Drive that would allow you to use a number of back-end systems.
Excel Liberation - Bruce's Site.

Resources