InfluxDB placeholder "Empty bound parameter" - sql

I'm struggling to format a InfluxDB query using placeholders.
Here I query with multiple placeholders.
The values are defined in the placeholders object, as seen below,
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $<label> and time >= $<from> - $<interval>`;
const placeholders = {label: 'person', from: 'now()', interval: '5m'};
const resp = await influx.query(query, { placeholders });
Once sent, an error 400 - error parsing query: empty bound parameter
In the error I can see the GET request, where it appears that the Influx library has correctly formatted the placeholders under "params".
/query?p=root&u=root&db=heatmap&epoch=&q=SELECT grid_ref_x, grid_ref_y, label FROM position WHERE label = $<label> and time >= $<from> - $<interval>&rp=&params={"from":"now()","interval":"5h","label":"person"}
How do I correctly format my query?

Have you tried changing
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $<label> and time >= $<from> - $<interval>`;
TO
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $label and time >= $from - $interval`;
The difference is that you reference the Placeholders or bind parameters using $variable_name instead of $<variable_name>. Assuming you're using node_influx, you can remove the double quotes on your tags and it'll still work.
I used this PR as reference https://github.com/node-influx/node-influx/issues/587

Related

How can I save part of a string in an alias using Cypress?

I'm trying to save just a number from a string I get from a paragraph but when I try to asign an alias to it and then check the value it returns undefined. I've tried a few solutions I found but none of those seem to work for me. These are two ways I tried (I tried another one similar to the second one but using split, had same result). The console.log inside of the 'then' doesn't show in the console, and when I try the alias after the code is when I get undefined.
cy.get('p')
.eq(1)
.should('have.text', '/[0-9]+/g')
.as('solNumber')
cy.get('p')
.eq(1)
.invoke('text')
.then((text)=>{
var fullText = text;
var pattern = /[0-9]+/g;
var number = fullText.match(pattern);
console.log(number);
})
.as('solNumber')
Please convert with + operator and return the numeric value if you want numeric type to be stored.
cy.get('p').eq(1)
.invoke('text')
.then(fullText => {
const number = fullText.match(/[0-9]+/);
return +number // text to numeric
})
.as('solNumber')
cy.get('#solNumber')
.should('eq', 42) // numeric type
});
Running your 2nd code on this,
<p>21</p>
<p>42</p>
gives the correct outcome
cy.get('p')
.eq(1)
.invoke('text')
.then((text)=>{
var fullText = text;
var pattern = /[0-9]+/g;
var number = fullText.match(pattern);
console.log(number); // logs 42
})
.as('solNumber')
cy.get('#solNumber')
.should('eq', '42') // passes
So, you need to inspect the DOM, it looks like it's not what you expect.
The first attempt you were passing a jquery element to the .should() and although some chainers change the subject yours did not so it saved the jquery element as solNumber.
The second attempt invokes the .text() which was passed to the .then() it logs the number correctly. However, you did not return anything at the end of the .then() block, therefore, solNumber should hold the entire paragraph.
This should help you out to extract the specific number and save it as an alias.
cy.get('p')
.invoke('text')
.invoke('trim')
.then(paragraph => {
const matcher = /some/
expect(paragraph).to.match(matcher) // check number is there
const indexOfText = paragraph.match(matcher) // get index of match text
return paragraph.substring(indexOfText.index, indexOfText.index + indexOfText[0].length) // return substring
})
.as('savedText')
cy.get('#savedText')
.then(cy.log) // will print out the number you seek

How to add a dynamic variable value inside a param field as a String in Karate?

I have an API, wherein the Param field, I need to pass the current date as a string.
And param filter = 'ORDER_DATE:"2021-01-31"'
I am trying to pass the current date for the ORDER_DATE field form a java method:
* def todaysDate = helper.getTodaysDate()
And print todaysDate // Prints 2021-02-04
Now I need to pass this "todaysDate " valuein the param filter field.
Following what I have tried so far:
And param filter = 'ORDER_DATE:#(todaysDate )'
And param filter = 'ORDER_DATE:<todaysDate>'
From example table value.
In Both cases, it printed "todaysDate " instead of its value "2021-02-04"
It is just JavaScript:
And param filter = 'ORDER_DATE:"' + todaysDate + '"'
This can improve in the 1.0 version BTW:
And param filter = `ORDER_DATE:"${todaysDate}"`
Further reading: https://github.com/intuit/karate#rules-for-embedded-expressions

I am trying to set a series name dynamicallly in amcharts

I passing data into a line series but I cannot dynamically add anything to series.name I just get the string rather that teh variable.
I tried using .dataFields.name but this is teh incorrect syntax.
Please advise?
J
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueY = "value"+ seriesId;
series.dataFields.dateX = "date";
series.name = "BrandNM"+ seriesId;
series.strokeWidth = 2;

Get the value of selectbox in cocoascript

I'm developing a sketch plugin. In the modal window I'm using to get user input there is a select. I can access the value of textField but I can't access value of the select.
Here is where I create the select:
var chooseFormatOptions = ['.png', '.jpg', '.pdf'];
var chooseFormatSelect = NSComboBox.alloc().initWithFrame(NSMakeRect(0, 250, viewWidth, 30));
chooseFormatSelect.addItemsWithObjectValues(chooseFormatOptions);
Here is where I try to get the combo box value
if (response == "1000"){
var projectName = projectField.stringValue();
var deviceName1 = firstDevicefield.stringValue();
var deviceDim1 = firstDimfield.stringValue();
var deviceName2 = secondDevicefield.stringValue();
var deviceDim2 = secondDimfield.stringValue();
var format = chooseFormatSelect.objectValues.indexOfSelectedItem(),
//var scale = chooseScaleOptions.stringValue();
//var pathOption = choosePathOptions.stringValue();
}
The error that it gives me when I run the plugin (if response == 1000) is: can't find variable chooseFormatSelect.
Do you know why I can get values of input fields (so it can find variables) but not that of the select one?
What about access text field 'text' variable while observing changes?
You may find this link helpfull (to add observe).
For NSComboBox follow this
Simply implement delegate then access value through following method

"update" query - error invalid input synatx for integer: "{39}" - postgresql

I'm using node js 0.10.12 to perform querys to postgreSQL 9.1.
I get the error error invalid input synatx for integer: "{39}" (39 is an example number) when I try to perform an update query
I cannot see what is going wrong. Any advise?
Here is my code (snippets) in the front-end
//this is global
var gid=0;
//set websockets to search - works fine
var sd = new WebSocket("ws://localhost:0000");
sd.onmessage = function (evt)
{
//get data, parse it, because there is more than one vars, pass id to gid
var received_msg = evt.data;
var packet = JSON.parse(received_msg);
var tid = packet['tid'];
gid=tid;
}
//when user clicks button, set websockets to send id and other data, to perform update query
var sa = new WebSocket("ws://localhost:0000");
sa.onopen = function(){
sa.send(JSON.stringify({
command:'typesave',
indi:gid,
name:document.getElementById("typename").value,
}));
sa.onmessage = function (evt) {
alert("Saved");
sa.close;
gid=0;//make gid 0 again, for re-use
}
And the back -end (query)
var query=client.query("UPDATE type SET t_name=$1,t_color=$2 WHERE t_id = $3 ",[name, color, indi])
query.on("row", function (row, result) {
result.addRow(row);
});
query.on("end", function (result) {
connection.send("o");
client.end();
});
Why this not work and the number does not get recognized?
Thanks in advance
As one would expect from the initial problem, your database driver is sending in an integer array of one member into a field for an integer. PostgreSQL rightly rejects the data and return an error. '{39}' in PostgreSQL terms is exactly equivalent to ARRAY[39] using an array constructor and [39] in JSON.
Now, obviously you can just change your query call to pull the first item out of the JSON array. and send that instead of the whole array, but I would be worried about what happens if things change and you get multiple values. You may want to look at separating that logic out for this data structure.