I have made the following change in Operation.optimize(Session session),
and it is working fine now.
The change is to consider datatype as DECIMAL when:
a) one side is integer and other is unknown (1 + ?)
b) one side is integer and other is String (1 + '0.5')
Following is the change (added an else-if block for math operators case,
just after the case where ? + ? is handled)
--------------------------------------
} else if ((l == Value.INT && (r == Value.NULL || r ==
Value.UNKNOWN || r == Value.STRING)) || (r == Value.INT && (l == Value.NULL
|| l == Value.UNKNOWN || l == Value.STRING))) {
// (1 + ?) - one side is int, other is unknown or string,
use decimal by default (the most safe data type) or
// string when text concatenation with + is enabled
if (opType == PLUS &&
session.getDatabase().getMode().allowPlusForStringConcat) {
dataType = Value.STRING;
opType = CONCAT;
} else {
dataType = Value.DECIMAL;
}
--------------------------------------
It still works well for the cases with integers in string:
SELECT 8 - '5' FROM DUAL // output=3
Will update if I face any issues.
Thanks,
Vinod
On Wednesday, June 27, 2012 8:46:19 PM UTC-4, Vinod wrote:
>
> I understand that my queries are more inclined towards oracle side as we
> have been using that. Now we are trying to execute dual queries in memory
> using H2.
> Also as there are thousands of existing queries, so it will not be
> feasible to changes those and perform testing again.
> For newly added queries, yes I can use as per your suggestion of using 1.0.
>
> For now, the only thing that is going to work is patching the code.
> Can you please give me some pointers for making this change to convert
> value into a double when convert to integer fails.
>
> Thanks,
> Vinod
>
> On Wednesday, June 27, 2012 3:50:59 PM UTC-4, Thomas Mueller wrote:
>>
>> Hi,
>>
>> > I am sure, that I will not be able to modify these queries.
>>
>> If you write code that only works with Oracle and no other database,
>> then well, you need to use Oracle. It seems only Oracle works they way
>> you want it, and no other database I have tested (PostgreSQL, Apache
>> Derby, HSQLDB, H2). It is not my plan to make H2 100% compatible with
>> Oracle.
>>
>> If you know that you want to calculate with a given precision, you
>> should use that precision in the calculation. In your case that seems
>> to be (1.0 - ?) and not (1 - ?). That way the database knows it's a
>> decimal when compiling (preparing) the statement.
>>
>> Regards,
>> Thomas
>>
>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/h2-database/-/4fHhltJzapcJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en.