Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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:

created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

and...

CREATE TRIGGER IF NOT EXISTS update_modification_time AFTER UPDATE OF title, body ON items FOR EACH ROW BEGIN UPDATE items SET modified = DATETIME('NOW') WHERE id = new +.id; END;

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.

--
જલધર


In reply to Mocking time with SQLite by jaldhar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2022-08-16 08:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?