mysugar / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

Add Oracle-compatible TO_CHAR function #528

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
It would be nice if H2 offered an Oracle-compatible TO_CHAR function:

TO_CHAR(datetime): 
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions180.htm
TO_CHAR(number): 
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions181.htm
TO_CHAR(character): 
http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions179.htm

This is currently on the H2 roadmap (secondary priority):

http://www.h2database.com/html/roadmap.html

I'm hoping to submit a patch in the not-too-distant future.

Original issue reported on code.google.com by djgred...@gmail.com on 22 Nov 2013 at 6:12

GoogleCodeExporter commented 9 years ago
Attaching patch. I wrote the code, it's mine, and I'm contributing it to H2 for 
distribution multiple-licensed under the H2 License, version 1.0, and under the 
Eclipse Public License, version 1.0 (http://h2database.com/html/license.html).

Some notes:

The implementation accepts the optional third parameter (NLS param), but 
currently this parameter has no effect on the behavior of the function.

I removed TO_CHAR from the roadmap HTML file, and I also removed some other 
items that have already been implemented.

I put all the logic in a separate ToChar util class -- it just seemed like too 
much code to simply add to the Function class.

There are a ton of tests to verify that the function is compatible with 
Oracle's TO_CHAR (99% code coverage, I think).

I fixed a small bug in TestBase where if two strings were asserted to be equal 
but weren't, then one of the reported lengths was incorrect.

Original comment by djgred...@gmail.com on 26 Nov 2013 at 10:18

Attachments:

GoogleCodeExporter commented 9 years ago
Awesome! Patch committed in revision 5317

Original comment by noelgrandin on 3 Dec 2013 at 11:57