What is the MinValue of Byte[] in C# - max

We represent MinValue of DateTime as DateTime.MinValue but how is it represented for Byte[]?
When I gave the below,
DALImage.TwinImage = Convert.IsDBNull(reader["TwinImage"]) ?
Byte[].MinValue :
(Byte[])reader["TwinImage"];
I get the error as 'byte' is a type but use like a variable
syntax error value expected (in '[]' part of Byte[])
Please Help as am a newbie to C# programming

An array of bytes doesn't have a minimum value - it doesn't make sense as a concept. It's like asking "What's the minimum value of a shopping list".
I think what you are trying to do is get an empty Byte array.
DALImage.TwinImage = Convert.IsDBNull(reader["TwinImage"]) ?
new Byte[0] :
(Byte[])reader["TwinImage"];
EDIT:
Your comment suggests that what you actually want is a byte array with 1 element in it, where that element is the minimum value of a byte.
That would be the following code:
DALImage.TwinImage = Convert.IsDBNull(reader["TwinImage"]) ?
new Byte[1] { Byte.MinValue } :
(Byte[])reader["TwinImage"];
However, this could also be written using default, which is probably semantically cleaner.
DALImage.TwinImage = Convert.IsDBNull(reader["TwinImage"]) ?
new Byte[1] { default(Byte) } :
(Byte[])reader["TwinImage"];

Related

Fetch value from XML using dynamic tag in ESQL

I have an xml
<family>
<child_one>ROY</child_one>
<child_two>VIC</child_two>
</family>
I want to fetch the value from the XML based on the dynamic tag in ESQL. I have tried like this
SET dynamicTag = 'child_'||num;
SET value = InputRoot.XMLNSC.parent.(XML.Element)dynamicTag;
Here num is the value received from the input it can be one or two. The result should be value = ROY if num is one and value is VIC if num is two.
The chapter ESQL field reference overview describes this use case:
Because the names of the fields appear in the ESQL program, they must be known when the program is written. This limitation can be avoided by using the alternative syntax that uses braces ( { ... } ).
So can change your code like this:
SET value = InputRoot.XMLNSC.parent.(XMLNSC.Element){dynamicTag};
Notice the change of the element type as well, see comment of #kimbert.

Codeigniter 4 - how to get the first row and the last row of a result

I am trying to get the first row and the last row of a query result. I see from Ci4's docs, there are two methods to help, namley, getFirstRow([$type = 'object']) and getLastRow([$type = 'object']) but I am having difficulty using them. Here is my method so far:
function getLoginFailCount($login_fail_ip, $max_login_attempts = 3, $within_seconds = 320){
$builder = $this->builder('login_fail');
$builder->where('login_fail_ip', $login_fail_ip);
$builder->orderBy('login_fail_created_at','DESC');
$query = $builder->get(3);
print_r($query->getFirstRow($query));
}
I get an error at getFirstRow as follows;
Argument 1 passed to CodeIgniter\Database\BaseResult::getFirstRow() must be
of the type string, object given
How can I get getFirstRow() to work? Doesn't this doc definition say I need to pass it an object? Why does the error say it my be of type string
Well in the documentation for getFirstRow() it states that you can use
$row = $query->getFirstRow() // which will give you an object
OR
$row = $query->getFirstRow(‘array’) // which will give you an Array
So your error message, which states...
Argument 1 passed to CodeIgniter\Database\BaseResult::getFirstRow()
must be of the type string, object given
Would make you look and say to yourself, I had better go and read the documentation. So you can either pass in nothing, or a String 'array'.
So now can you see why
$query->getFirstRow($query))
does not make any sense! Why would you pass in the $query object as parameter.
You may have misread the documentation. I see you stated getFirstRow([$type = 'object'])
You might have got a little confused by that...
[$type = 'object'] means that the $type is defaulted to be the string 'object' so the returned type is an object by default with No Parameter being passed in.
If you want it to return an array, then you would specify the string 'array'. So then the $type parameter would be set to the string 'array' and return an array instead of an object.
Does that help!

How to get value from a column referenced by a number, from JDBC Response object of Jmeter?

I know they advice to get a cell value this way:
columnValue = vars.getObject("resultObject").get(0).get("Column Name");
as stated on jMeter doc : component reference : JDBC_Request.
But: How to access the same RS cell value by just a number of the column?
RS.get(0).get(4);
...instead of giving it a String of column Name/Label.
edit 1: Lets use Groovy/Java, instead of BeanShell. Thanks.
edit 2: The original motivation was the difference between column Name / Label, as these seem to be not fully guaranteed (? seems to be not clear here, not to me), especially due case-sensitivity ("id"/"ID", "name"/"Name"/"NAME" ..)
It should be something like:
String value = (new ArrayList<String>(vars.getObject("resultObject").get(0).values())).get(4)
More information: Debugging JDBC Sampler Results in JMeter
Be aware that according to HashMap documentation:
This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.
So the order of columns might be a big question mark.
The row itself is a HashMap, defined in source code as:
HashMap<String, Object> row
So using BeanShell syntax, you could get it as
row = vars.getObject("resultObject").get(0); // returns HashMap
In HashMap, you cannot access item (column) by ID. You could, however, apply one of the methods described here, but HashMap doesn't guarantee order, so you cannot be sure what "column 4" will contain.
If you want to be able to loop through all columns, it's better to do it in a Map style, not by index. For example using entrySet() with BeanShell:
for(Map.Entry entry : row.entrySet())
{
log.info(entry.getKey() + "=" + entry.getValue());
}
See various ways to iterate through Map here.

'StartsWith' not working in Linq-To-EF

I have implemented a Linq-to-EF expression using the sting comparison 'StartsWith', but it is behaving like the string comparison 'Contains'... my code is:
string ubi = '12';
return (from u in _dataContext.Notice
where u.UB.StartsWith(ubi)
select new AutoCompleteData { Value = u.UB }).Distinct().Take(50);
I would expect the data returned to be only values that start with '12'...but it returns values like '44412' and '312' as well as '1245' and '1299'.
Am I missing something ?

How to return localized content from WebAPI? Strings work but not numbers

Given this ApiController:
public string TestString() {
return "The value is: " + 1.23;
}
public double TestDouble() {
return 1.23;
}
With the browser's language set to "fr-FR", the following happens:
/apiController/TestString yields
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">The value is: 1,23</string>
/apiController/TestDouble yields
<double xmlns="http://schemas.microsoft.com/2003/10/Serialization/">1.23</double>
I would expect TestDouble() to yield 1,23 in the XML. Can anyone explain why this isn't the case and, more importantly, how to make it so that it does?
It is because the conversion from double to string happens at different stage for each API. For the TestString API, double.ToString() is used to convert the number to a string using CurrentCulture of the current thread and it happens when the TestString method is called. Meanwhile, the double number which is returned by TestDouble is serialized to string during the serialization step which uses GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Culture.
In my opinion, both should use InvariantCulture. On the consumer side, the values will be parsed and be formatted with the correct culture.
Update: this is only used for JsonFormatter. XmlFormatter doesn't have such a setting.
Update 2:
It seems (decimal) numbers need special converter to make it culture-aware:
Handling decimal values in Newtonsoft.Json
Btw, if you want o change data format per action/request, you can try the last piece of code of the following link: http://tostring.it/2012/07/18/customize-json-result-in-web-api/

Resources