List:Internals« Previous MessageNext Message »
From:  Date:July 1 2006 12:08am
Subject:Re: High precision time
View as plain text  
After spending much time debugging this, it seems to be a display issue.
If you select and store the result in a user variable, then query that variable, it shows
the decimal places.

devel>  select micronow() into @tmp ;
Query OK, 1 row affected (0.01 sec)

devel:browse>  select @tmp ;
+-----------------+
| @tmp            |
+-----------------+
| 1151712336.9773 |
+-----------------+
1 row in set (0.00 sec)

Also, if you select and pass a dummy variable, it shows the decimal part.

devel>  select micronow('dummyvar')  ;
+----------------------+
| micronow('dummyvar') |
+----------------------+
| 1151712369.376       |
+----------------------+
1 row in set (0.00 sec)


Only, if you call the fuction direct and without arguements does it return (what looks
like) an integer.

devel>  select micronow() ;
+------------+
| micronow() |
+------------+
| 1151712449 |
+------------+
1 row in set (0.00 sec)


---- bwillits@stripped wrote: 
> 
> Thanks Wojciech:
> 
> I was working on that approach, but you beat me to it. Your code compiled and loaded
> fine, but when I run the function in mysql, I get an integer result (similar to
> unix_timestamp()).
> 
> devel> select micronow() ;
> +------------+
> | micronow() |
> +------------+
> | 1151688170 |
> +------------+
> 1 row in set (0.01 sec)
> 
> 
> Here is the code:
> 
> #include <mysql/mysql.h>
> #include <sys/time.h>
> 
> my_bool micronow_init(UDF_INIT *initid,UDF_ARGS *args, char *message) {
> return 0;
> }
> 
> void micronow_deinit(UDF_INIT *initid) {}
> 
> double micronow(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long
> *length, char *is_null, char *error) {
> struct timeval tv;
> struct timezone tz ;
> gettimeofday(&tv,&tz);
> 
> return (double) ((double)tv.tv_usec)/1000000+tv.tv_sec;
> }
> 
> Any idea why it is doing this?
> Thanks,
> Bill Willits
> 
> ---- Wojciech Meler <wmeler@stripped> wrote:
> > Why not to use UDF ?
> >
> > #include <mysql/mysql.h>
> > #include <sys/time.h>
> >
> > my_bool hrtime_init(UDF_INIT *initid,UDF_ARGS *args, char *message) {
> > return 0;
> > }
> >
> > void hrtime_deinit(UDF_INIT *initid) {}
> >
> > double hrtime(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned
> > long *le
> > ngth, char *is_null, char *error) {
> > struct timeval tv;
> > gettimeofday(&tv,NULL);
> >
> > return ((double)tv.tv_usec)/1000000+tv.tv_sec;
> > }
> >
> >
> > oompile it:
> >
> > gcc -shared -o hrtime.so hrtime.c
> >
> > and install:
> >
> > CREATE FUNCTION hrtime RETURNS REAL SONAME 'hrtime.so'
> >
> >
> > bwillits@stripped wrote:
> > > Sorry:
> > >
> > > Language: MySQL native function (for use in a stored proc)
> > > OS: Linux (CentOS)
> > >
> > > thanks,
> > > BW
> > >
> > > ---- Rick James <rjames@stripped> wrote:
> > >
> > >>Language? OS?
> > >>
> > >>Perl has HiRes::Timer
> > >>PHP has microtimes
> > >>Windows has QueryPerformanceTimer
> > >>Java has something
> > >>
> > >>
> > >>>If the answer is no, can you point me to the code for now()
> > >>>or similar so I could investigate adding such a function?
> > >>
> > >
> > >
> >
> >
> > --
> > MySQL Internals Mailing List
> > For list archives: http://lists.mysql.com/internals
> > To unsubscribe: http://lists.mysql.com/internals?unsub=1
> >
> 
> 
> -- 
> MySQL Internals Mailing List
> For list archives: http://lists.mysql.com/internals
> To unsubscribe:    http://lists.mysql.com/internals?unsub=1
> 

Thread
High precision timebwillits29 Jun
  • RE: High precision timeRick James29 Jun
  • Re: High precision timeSergei Golubchik30 Jun
RE: High precision timebwillits29 Jun
  • Re: High precision timeWojciech Meler30 Jun
Re: High precision timebwillits30 Jun
Re: High precision timebwillits1 Jul