Just a different look at it ... sort of a "trace" file approach ... and not really thought through to any depth ... just add a few SP calls at points in the relevant places in the stored procedure in question and then review the trace file:
Original Message:
Sent: Fri February 07, 2025 08:56 AM
From: Andreas Legner
Subject: An accurate timestamp in a stored procedure
Hi Art,
I don't think it depends on USEOSTIME, it works well also with USEOSTIME 0.
And careful with the microseconds: e.g. a value of 153 first had to be left padded to full six digits 000153 before any decision on how many digits after the dot you're interested in.
Also: OUT instead of INOUT would of course be good enough in this case.
Andreas
------------------------------
Andreas Legner
Informix Dev
HCL Software
------------------------------
Original Message:
Sent: Fri February 07, 2025 08:28 AM
From: Art Kagel
Subject: An accurate timestamp in a stored procedure
Andreas:
Very cool function, but the underlying _ostime() function is an undocumented internal function. Also, it requires USEOSTIME to be set to 1 (and a server restart if it is not already set).
FWIW, here's a version of your "test" program that returns only five subsecond digits so it can be cast to a datetime for other uses and resolutions:
CREATE PROCEDURE IF NOT EXISTS ostime ()
-- returning integer, integer;
returning varchar(255);
define secs integer;
define usecs integer;
define rets varchar(255);
let secs = 0;
let usecs = 0;
call ostime(secs, usecs);
-- works:
-- return secs, usecs;
-- convert to string:
let rets = dbinfo('utc_to_datetime', secs) || '.' || lpad(usecs, 5, '0');
return rets;
end procedure;
So:
> select ostime()::datetime year to fraction(5), (ostime()::datetime year to fraction(5))::datetime hour to fraction(2);
(expression) (expression)
2025-02-07 08:27:34.82682 08:27:34.82
1 row(s) retrieved.
Art
------------------------------
Art S. Kagel, President and Principal Consultant
ASK Database Management Corp.
www.askdbmgt.com
Original Message:
Sent: Fri February 07, 2025 07:27 AM
From: Andreas Legner
Subject: An accurate timestamp in a stored procedure
Hi Andrew,
how about this guy:
create procedure ostime(inout integer, inout integer) external name '(_ostime)' language C;
Through its two inout params it will give you seconds and micro-seconds immediately from a call to gettimeofday().
To demonstrate:
create procedure test_ostime()
-- returning integer, integer;
returning varchar(255);
define secs integer;
define usecs integer;
define rets varchar(255);
let secs = 0;
let usecs = 0;
call ostime(secs, usecs);
-- works:
-- return secs, usecs;
-- convert to string:
let rets = dbinfo('utc_to_datetime', secs) || '.' || lpad(usecs, 6, '0');
return rets;
end procedure;
execute procedure test_ostime();
HTH,
Andreas
------------------------------
Andreas Legner
Informix Dev
HCL Software