Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (8)
    As of 2014-09-20 21:23 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (163 votes), past polls