I use a function
public static object getContent(String keyword, object StartTime, object EndTime)
{
alert(StartTime);
}
set cell A1 to 18-07-2012.And when calling =getContent("africa",A1,"04-09-2012")
dispalys 41108.what it means?Why its not taking value in A1!!!
Excel has no built-in date/time data type. In Excel, date/times are formatting options for the double data type. You can declare an Excel-DNA function as taking a DateTime parameter to have the passed-in doubles converted to DateTime automatically, or you can do the conversion yourself using DateTime.FromOADate() (since the Excel double encoding matches the COM/OLE date implementation).
Related
I am creating a webhook route where I will receive a JSON, so I am converting it into an object as follows:
data = JSON.parse(request.body.read, object_class: OpenStruct)
And that generates the object I want. This object however has a property that is similar to an ENUM, which has some 'predictable' values
being: PURCHASE_APPROVED, PURCHASE_CANCELED.
They come as a string, so I tried to do the following to convert them
events = { PURCHASE_CANCELED: 0, PURCHASE_APPROVED: 1 }
So I want to take the value that came as a string and transform it into an enum, the way I managed to convert the data was:
data.event = events[data.event.to_sym]
But the data doesn't become an enum, I can't use some properties like the
data.event.PURCHASE_APPROVED?
Is there any simple way to do this within the controller? Or would I have to create a class and specify each property just to have 1 enum?
I have a Birt report with a data set that has one computed column of the type "Java Object". This column takes it's input from the surrounding application as a Java object and later uses this exact object to calculate something.
The computed column's expression:
var result;
try {
result = application.getValueFromApplication(row["id"]);
} catch (err) {
Packages.java.lang.System.out.println("Error getting value " + row["id"] + ": " + err);
result = null;
}
However... there seems to be a bug that Birt converts these values to JavaScript values. That's stupid in the best case, but it gets even worse for numbers. Because all numbers are converted to the same stupid JavaScript "number" type. Yes, even BigDecimaland Long.
So in the above example, getValueFromApplication() returns a BigDecimal, while result is a Javascript number one.
When the time comes to start the calculation, all these values are internally converted back to Double, and now the calculation fails because it requires the value to be what the application gave the report.
So somewhere there is this snippet:
application.doMagic(row["value"]);
Where Birt tries to force it's Double down the method's throat, even though it had a BigDecimal in the beginning.
How do I prevent Birt from mindlessly converting numbers to some JavaScript blob instead of using the concrete Java class?
I have looked at a number of StackOverflow questions on this issue but can't find one that makes any sense. This one comes closest but doesn't show how to get the return value from the function.
Here's my mapper call:
public Long callMyFunction(#Param("recordId") Long recordId, #Param("otherId") Long otherId, #Param("date") Date date, #Param("comments") String comments);
Here's the mapper XML:
<select id="callMyFunction" parameterType="map" statementType="CALLABLE" resultType="java.lang.Long">
{ #{resultId,javaType=java.lang.Long,jdbcType=NUMERIC,mode=OUT} = call MYSCHEMA.MYPACKAGE.my_function(
#{recordId,jdbcType=NUMERIC,mode=IN},
#{otherId,jdbcType=NUMERIC,mode=IN},
#{date,jdbcType=DATE,mode=IN},
#{comments,jdbcType=VARCHAR,mode=IN})}
</select>
The call works, but the return value (resultId) is always null.
Can anybody spot the problem?
If you want to return directly the result, then the SQL call must be:
SELECT MYSCHEMA.MYPACKAGE.my_function(...) FROM DUAL
If you want to keep with calling the function in the procedure call style, that means the result is an OUT parameter (you env declared it OUT).
The minimum change would consist in adding a parameter to the mapper method signature:
public Long callMyFunction(#Param("recordId") Long recordId, #Param("otherId") Long otherId, #Param("date") Date date, #Param("comments") String comments, #Param("resultIdContainer") Map<String, Long> resultIdContainer);
In the XML: forget the resultType, this is for selects. And the call:
{ #{resultIdContainer.resultId, javaType=java.lang.Long,jdbcType=NUMERIC,mode=OUT} = call ...
Not that I use here a map to contain the resutlId: an indirection is required: the function will write the parameter 'result' value somewhere you can read later (after your mapper call), you can also use a class with a resultId property.
i am using this code for passing datetime.
Convert.ToDateTime(textBox1.Text)
but the compiler show an error that string was not recognized as a valid datetime. so how to avoid this error and is a datetime field in my database.
Convert.ToDateTime(textBox1.Text)
This code will throw an exception if the string value in textBox1.Text doesn't represent a valid DateTime (or at least can't be parsed into one with default functionality in C#). You can add some defensive programming to handle errors like this.
The DateTime type (as well as most, if not all, common value types in .NET) has a method on it called TryParse() specifically for the purpose to attempting to parse a value into that type without throwing an exception. The method returns true if the parse was successful, false otherwise. And it accepts an out parameter to hold the resulting parsed value (or the original value if parsing is unsuccessful).
So instead of this:
var dateTimeValue = Convert.ToDateTime(textBox1.Text);
You could use something like this:
var dateTimeValue = DateTime.MinValue;
if (DateTime.TryParse(textBox1.Text, out dateTimeValue))
// use the value for something
I'm formatting a ResultSet to output to a CSV file. As such I really don't care about the Java types of the result set, beyond maybe knowing if it's text or numbers.
Does JDBC guarantee getString will always give a string representation of the values,atleast for single values (I don't need to concern myself about java.sql.Types.ARRAY,java.sql.Types.JAVA_OBJECT and a few others).
e.g. given resultSetMetaData.getColumnType(i) is a Types.FLOAT or a Types.BIGDECIMAL. will rs.GetString(i) always yield some String ?
i.e. Are there cases getString will throw an SQLException or return null when a getXXX would give me the value ?
Yup, check this : http://java.sun.com/docs/books/tutorial/jdbc/basics/retrieving.html
JDBC allows a lot of latitude as far as which getXXX methods you can use to retrieve the different SQL types. For example, the method getInt can be used to retrieve any of the numeric or character types. The data it retrieves will be converted to an int; that is, if the SQL type is VARCHAR , JDBC will attempt to parse an integer out of the VARCHAR. The method getInt is recommended for retrieving only SQL INTEGER types, however, and it cannot be used for the SQL types BINARY, VARBINARY, LONGVARBINARY, DATE , TIME, or TIMESTAMP.
But be careful, different JDBC driver may yield different result.
java.lang.String is a final class - it cannot, ever, have a subclass. So any method that returns String will either return an instance of the class java.lang.String, or a null, or throw an exception.
As for conversion, it is up to the JDBC driver if it will allow you to convert from non-String types. I suspect many will have an issue with it.
I would suggest that you do this instead:
Object item = resultSet.getObject(i);
String strValue = (item == null ? null : item.toString());
That should be more robust, since getObject() will always do the sensible thing.