I'm writing a test case in robot framework. I'm getting the response in below json string:
{"responseTimeStamp":"1970-01-01T05:30:00",
"statusCode":"200",
"statusMsg":"200",
"_object":{"id":"TS82",
"name":"newgroup",
"desc":"ttesteste",
"parentGroups":[],
"childGroups":[],
"devices":null,
"mos":null,
"groupConfigRules" {
"version":null,
"ruleContents":null
},
"applications":null,"type":0
}
}
From that I want to take "_object" using:
${reqresstr} = ${response['_object']}
... but am getting the error "No keyword with name '=' found" error
If I try the following:
${reqresstr}= ${response['_object']}
... I'm getting the error "Keyword name cannot be empty." I tried removing the '=' but still get the same error.
How can I extract '_object' from that json string?
When using the "=" for variable assignment with the space-separated format, you must make sure you have no more than a single space before the "=". Your first example shows that you've got more than one space on either side of the "=". You must have only a single space before the = and two or more after, or robot will think the spaces are a separator between a keyword and argument.
For the "keyword must not be empty" error, the first cell after a variable name must be a keyword. Unlike traditional programming languages, you cannot directly assign a string to a variable.
To set a variable to a string you need to use the Set Variable keyword (or one of the variations such as Set Test Variable). For example:
${reqresstr}= Set variable ${response['_object']}
${reqresstr}= '${response["_object"]}'
wrap it inside quotes and two spaces after =
There is a syntax error in your command. Make sure there is a space between ${reqresstr} and =.
Using your example above:
${reqresstr} = ${response['_object']}
Related
I have a variable with a value of '1617'. It is a DT_WSTR datatype currently. Sometimes I need a string, others an integer.
I am using a derived column to replace the ' values so that I can cast this value as an integer.
My replace function is not working.
REPLACE([User::schoolYear],"'","")
What am I doing wrong?
The problem with your supplied expression, is that you are not referencing the variable schoolYear. Sometimes, you can address a variable as #schoolYear but the consistent, explicit syntax I would encourage is #[User::schoolYear] That way, you can identify the namespace in case someone like me has used a custom namespace.
Your Derived Column expression then becomes
REPLACE(#[User::schoolYear],"'","")
You are having space before and after the single quote, which is causing the replace to fail.
Modify the expression as given below. I have tested it. It is working fine.
REPLACE([User::schoolYear],"'","")
I use the following code to update textvalidation with a string:
function updateform(strtokens) {
var form = FormApp.openById(#formid#);
var textItem = form.getItemById(#formid#);
var textValidation = FormApp.createTextValidation()
.requireTextMatchesPattern(strtokens)
.build();
textItem.asTextItem().setValidation(textValidation);
return form.getPublishedUrl();
}
I get error saying invalid data updating form at line textItem.asTextItem().setValidation(textValidation)
I get this issue on occasion but not all the time and i can't figure out why.
Are any of the following issues possible explanation?
strtokens is of the format: text1|text2|text3|.. etc, it can be very long. text1, etc also include special characters. note strtokens is concatenates randomly generated text of length 10 and the # of text is currently set to 10.
The text is generated by randomly sampling 10 characters from A-Z, a-z, 0-9 & special characters. please see examples below where they cause and do not cause error.
Does the form id/item id change so that it doesn't identify accurately? I got form id from the url and I got item id from inspecting the id in the html of the form.
Answer:
The pattern parameter you pass into .requireTextMatchesPattern(pattern) is a Regular Expression and the * character is a RegEx quantifier. If incorrectly used the pattern will be invalid and throws an error.
More Information:
For Regular Expressions, the * character indicates:
Zero or more occurances of the previous element.
For example:
For the expression stacko*verflow the following strings will match:
stackverflow
stackoverflow
stackooverflow
stackoooverflow
stackoooverflow
And so on, provided the string starts with stack and ends with verflow.
In the examples you provided in the above comments, you have the following Regular Expressions:
1:
WvGMkRIQf>|X2ANqg<SGu|j$aN6on**L|v5$N#z7dW!|XU5#5Ml&8Q|Bz%EzuWLiE|a&Cv!IE3E4|-IK4>#ljA8|5ytvZeRJLd|dAOe2L6-g7|P>1UQ<iMYO|yoCZrb7Tom|cuIfBUN%js|FfIq2ASpF0|gZDf8abN1p|mHV>swDHwR|rDgknKK3CS|<$dbw0TfvO|K6xCL&zqk5
2:
hFI*ek0Ypa|>O3eLWaNyI|34UGs*BGWG|4xTlqI5$1v|6J5b4hxhQB|e!UGlGUe!d|RuQgm!07UR|JSe%zMrw84|kEffwcplYp|V#EOUi9xrK|mxxLLZ9rcJ|Z8-PgwizSH|j#lPl3nt3l|q$qzansAMi|<>FOR&yGl2|O0#hIat24N|7DVrI>Oz!5|BgmHjZpoC<|Q53a0cwxw<
3:
mOU-4p%ArY|o>&cL!JMeN
4:
*<R2&$fKfz|x&c&mmNdgT
You can test these for yourself using an online Regular Expression validator but I will explain this here.
In the first example, the culprit is the third string: j$aN6on**L. A double asterisk (**) is not a valid expression as the first asterisk would need to be escaped with a \ (j$aN6on\**L).
The second example does not throw an error as it validates correctly. The same can be said about the third example.
The fourth example also throws an error - this time however it is due to the string starting with the * character. As the * character indicates zero or more occurances of the previous element, but there is no character before the *.
You can check out the basic concepts of Regular Expressions to get a more detailed understanding.
References:
Wikipedia - Regular Expression
Regular Expression - Basic concepts
i have a json field in my table(MySQL Database).
the following is the structure:
{
"article":{
"Key's 1":{
"value":"24"
}
"Key's of the something's 2":{
"value":"55"
}
}
}
i am trying to extract the "value" field of "Key's 1".
Due special character such as single quote and space, i am unable use JSON_EXTRACT function.
It give the error: Invalid JSON path expression.This error is around character position no : 10
My Query:
select
JSON_EXTRACT(analytics_json,'$.article.Key\'s 1.value')As value
from
tbl_json_data;
Even after place a backslash, i am getting the error.
You may escape each JSON path component in double quotes to handle special characters as well as spaces. The following works:
SELECT
JSON_EXTRACT(analytics_json,'$.article."Key''s 1".value') AS value
FROM tbl_json_data;
Demo
Note that your key name actually has two problems. First, it contains a literal single quote. We can handle that by just doubling up two single quotes. The key name also contains whitespace. By escaping in double quotes we may workaround this problem, but it would probably be best to avoid using JSON keys which have whitespace.
Im trying to use an expression to a sub package in SSIS however it always errors out stating that it cannot find the dtsx file. Ive copied the path to explorer and it seems to be correct.
The error also states that expression cannot be written to the property. My code is below.
#[User::vRoot] + "\Employees.dtsx" with #[User::vRoot] being a variable stored in SQL
Any Ideas
Try to escape the backslash in the expression using an additional backslash.
#[User::vRoot] + "\\Employees.dtsx"
In such a scenario where I need to concatenate folder and file name, I always do it this way. I usually create two variables named FolderPath and FileName. Let's assume FolderPath contains C:\temp\ (make sure it ends with a back slash) and FileName contains Employees.dtsx.
I will create a third variable named FilePath and will set the EvaluateAsExpression property of this variable to true. I will set the following expression in this variable so it dynamically evaluates the value.
#[User::FolderPath] + #[User::FileName]
Hope that helps.
Backslash is an escape character here, so if you want to represent a literal backslash, it's "\\".
I also suggest, as a general rule, instead of hardcoding a backslash in the string concatenation, to use this method to consider potential trailing backslashes in the first variable:
#[User::vRoot] + (RIGHT(#[User::vRoot], 1) == "\\" ? "" : "\\") + "Employees.dtsx"
I am using MySQL with MATLAB, and I want to get a name from user, and pass it to the table in mySQL, but it is rejecting a variable name in place of string
var_name=input('enter the name:');
mysql('insert into table (name) values (var_name)');
Any suggestions?
FIRST read the comments to this question - you don't want to shoot yourself in the foot with a mysql injection security problem. You have been warned. Now, to solve your current problem, without addressing the security risk of the whole approach when it comes to building SQL queries, read on...
In principle Amro has already posted two solutions for you which work, but since you have not accepted it I'll explain further.
Your problem is that you are not telling MATLAB which parts of your query it should interpret as a literal string, and which parts it should interpret as a variable name. To solve this, you can just end the literal string where appropriate, i.e. after the opening brackets, and then start them again before the closing brackets.
In between those literal strings you want to add the contents of your variables, so you need to tell MATLAB to concat your literal strings with your variables, since the mysql command probably expects the whole query as a single string. So in essence you want to take the string 'insert into table(' and the string saved in the variable name and the string ') values (' and so on and glue them into one big string. Amro and Isaac have shown you two solutions of how to do this without much explanation:
horzcat('insert into table (', name, ') values (', var_name, ')')
uses the function horzcat, while
['insert into table (' name ') values (' var_name ')']
uses the fact that MATLAB treats strings as arrays of characters so that you can just use square brackets to form a large array containing the strings one after the other.
The third solution, offered by Amro, is a bit more sublte:
sprintf('insert into table (%s) values (%s)',name,var_name)
It tells the function sprintf (which is made for that purpose) "take the string which I supply as first parameter and replace occurences of %s with the strings I supply as the following parameters. This last technique is in particular useful if you also need to insert numbers into your string, because sprintf can also convert numbers to string and allows fine control over how they are formatted. You should have a close look at the help page for sprintf to know more :-).
Try this instead:
mysql(['insert into table (' name ') values (' var_name ')']);
or even:
mysql(sprintf('insert into table (%s) values (%s)',name,var_name));
I believe the problem you are having is the same as the one in this other question. It sounds like you want to create a command string that itself contains a ' delimited string, which would require you to escape each ' with another ' when you create your command string (note the first example in this string handling documentation). Note also you may want to use the 's' option for the INPUT function:
var_name = input('Enter the name: ','s'); %# Treats input like a string
commandString = sprintf('insert into table (name) values (''%s'')', var_name);
%# Note the two apostrophes --^
mysql(commandString);
If I were to enter Ken for the input, the string commandString would contain the following:
insert into table (name) values ('Ken')
And of course, as others have already mentioned, beware injection vulnerabilities.