Henrik Grubbstr?m (Lysator) @ Pike (-) developers forum wrote:
In Pike 8.1 I checked in a few new native Sql types. This allows for faster, easier and lossless manipulation of dates/times/intervals. It also facilitates binary transfer to and from the database.
Ok.
I currently implemented all this for the pgsql driver. The new code still needs documentation. Reviews welcome.
Did you take a look at the similar support in Sql.odbc?
Actually, I did. But that approach has some drawbacks: - The TOD type stores as separate values for hour/minute/second/nanos. This would require conversion calculations for every value arriving from the database, and conversion calculations for every value going to the database. That sounds like undesirable overhead. - Then there is timestamp_factory(), which uses Calendar. It produces something, and I'm sure it's correct, but it's very far from anything that can go in and out the database without a lot of conversions. - I'm not sure what scale_numeric() does in that list.
On the positive side: - The user_defined_factory() might be nice to use, it allows for dynamic creation and handling of user defined types. But this is more a convenience for user defined types, than that it is efficient to handle SQL-native types with this.
I do notice that I used microseconds, whereas nanoseconds are being used here. Since some databases handle up to nanosecond resolution, I'll change the generic interface to accept nanoseconds instead of microseconds.