CsvToBean treat string value as null - opencsv

Is there a way for CsvToBean to treat a specific string or character as null when it maps into a Bean class?
For example I have a CSV that has a quoted value of "-". I know that when creating a CsvToBean you can specify
.withFieldAsNull(CSVReaderNullFieldIndicator)
which handles cases when a value is not present in CSV data. Just can't find a way to treat a character value as null.

No OpenCSV does not do data translation like that. You will have to change your the setters in your bean to translate the value as you are setting it.

Related

PeopleCode reflection for variables

Does PeopleCode have something similar to reflection in C# whereby I can access a variable with the variable name stored in a string? I am aware of the # operator but I think it only applies to fields and records (correct me if I am wrong. I tried and couldn't get it to work.)
Basically, I need to access a Component variable by name with the name itself being variable.
You can do it by # :
Local string &sValue1 = "var1";
getting the value :
winmessage(#(&sValue1));

Reading dates from Sqlite with Delphi / Firedac

When reading date fields from Sqlite into Firedac, I get conversion errors. The fields are called dates but with string entries (yyyy-mm-dd). I set the option for Datetime Format = string, but I've discovered that while null values are handled OK, empty values (= '') produce an error which I can't figure out how to handle.
You can enable StrsEmpty2Null option, which will automatically convert all empty strings to NULL state. But it's for all values and parameters handled by the data component. So it's not the cure.
I'm not sure what you're doing, but in general, NULL is a state and you cannot convert NULL state to a value because it's a state indicating no value. So as you cannot convert empty string to date.
So try to describe more about your value to string conversion, so we can suggest a proper way to deal with it. For SQLite, I'd suggest using DATE pseudo data type and convert values through the built-in formatting expressions.

How to escape characters for dictionary key values in Robot Framework?

I am trying to assign value to a dictionary key but getting an error
"ValueError: Adding data to a dictionary failed. There should be even number of key-value-pairs."
Here is the code
set to dictionary ${cParamsDict} cust_params v=classifieds&cpage=browseads&article-id=65207
I believe the "=" in the value is causing issue. How do I resolve this? I have to pass this dictionary to a keyword for further verification
Set To Dictionary ${cParamsDict} cust_params v\=classifieds&cpage\=browseads&article-id\=65207
or
${value} Set Variable v=classifieds&cpage=browseads&article-id=65207
Set To Dictionary ${cParamsDict} cust_params ${value}
Docu: http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#creating-variables
Just to clarify - you've already created a dictionary using the Create Dictionary keyword (from Built-in)?
If so, then yes - likely as not your issue is not escaping embedded equals signs. Your line should read like this:
Set To Dictionary ${cParamsDict} cust_params=v\=classifieds&cpage\=browseads&article-id\=65207
Read up on escaping in the documentation.

How can I update a database string value from a TextBox?

I cant update my database through textbox.in the case of numeric value i can update but cant with a string value.
my coding is...
SqlCommand cmdup= new SqlCommand("UPDATE [port1] SET [prt1]=#prt1 WHERE [no]= 1",cn);
cmdup.Parameters.Add("#prt1", TextBox1.Text);
cmdup.ExecuteNonQuery();
if any one know the ans: reply me
I'd recommend explicitly defining the parameter type to match the type in the DB, and passing the value to Parameters.Add as the appropriate type.
e.g. at the moment, you are passing a string typed value to Parameters.Add, and not defining the type explicitly. Therefore, it will assume the data type from the type of value supplied...so the #prt1 type will be passed in to the DB as NVARCHAR I believe.
If the prt1 field is an INTEGER for example, much safer IMHO to do something like:
cmd.Parameters.Add("#prt", SqlDbType.Int,4).Value = Int32.Parse(TextBox1.Text);
or
cmd.Parameters.AddWithValue("#prt", Int32.Parse(TextBox1.Text));
I always like to fully define the type of the parameters I pass in to SQL to rule out any potential, unexpected issues.
Check the datatype for the #prt1 to see if it is a Int value because you are setting to the same column two different values.
Parse the textBox to Integer as you want to insert a numeric value i.e. Int64.Parse("Textbox1.Text"); well with string it does have problems.
Just a wild guess: Does prt maybe only accept numeric values?

Handling null strings and ints in Json

JSON ignores any parameters with null values. So, when I create a string using JsonConverter.ExportToString these properties are missing. Also any integers with null values are replaced with -2147483648
This becomes an issue when I try to deserialize this string (I am writing my own deserializer and not using Json.Import)
What's the best way of handling this?
I am not sure that I understand the question. JSON is just a subset of javascript and properties with null values can be represented like so:
{"property1": 1, "property2": null}
In this case, property1 is a numeric and had value 1, while property2 has value null. I'm not sure from which library the Json.Import and JsonConverter.ExportToString calls are coming. Anyway, assigning a null value to an integer is typical "strong-typed speak". In javascript, assigning null to a numeric (no such thing as integer in js) would just make that variable stop being numeric.
So maybe you should give us more context: libraries used, language you are using the data from (apparently not javascript).
Could you use an empty string i.e. "" instead of null, and use a placeholder number e.g. -2147483648 to indicate a null integer value?

Resources