Mocking time with SQLiteby jaldhar (Vicar)
|on Dec 26, 2010 at 12:10 UTC||Need Help??|
jaldhar has asked for the
wisdom of the Perl Monks concerning the following question:
Normally when I test an application that makes use of times, I turn to Test::MockTime which works wonderfully for setting Perls notions of the current time to arbitrary values. In this app, however it doesn't work because the database has the following fields:
Modules like Test::MockTime work by intercepting Perls time related functions but here the time is being set by the SQLite library (calling down to libc functions no doubt) and so this approach does not work. I can think of two possible alternatives:
There are C preload libraries like faketime which intercept C library time functions. Can something like that be used from within a Perl script?
DBD::SQlite lets you use sqlite_create_function. Could this be used to override SQLites time related functions? If so which ones?
Comments welcome on whether either of these ideas are feasable or if there are better solutions.