Problem with time
Posted in 2015
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
Good Morning I have the following configuration: UnixWare 7.1.4 (virtualized with VMware) Informix Dynamic Server Version 7.30.UC2 I have a problem with time with informix 4gl, if running the program below, in random situations what happens is that the time is the same for about an hour. The program sleeps for 1 secund, if this sleep is made by informix it block's, if the sleep is made by calling system, it advance. In both cases the time is the same. Anyone ever had a similar problem, if so how to solve Thank you. Pedro Bizarro ############################################################## # SLEEP SEGUNDO A SEGUINDO PARA VER A DIFERENCA DE HORAS ############################################################## MAIN define str_1,str_11 char(50) define hora,minuto,segundo char(2) define hStart,hEnd datetime year to fraction define contador integer define test,test3 char(60) let test = "sleep 1" let test3 = "sleep 3" let count = 1 while not int_flag if count >= 10 then let hStart=current year to fraction run test3 let contador = 1 let hEnd=current year to fraction let hEnd="2015-09-04 18:10:25.000" else let hStart=current year to fraction run test let hEnd=current year to fraction end if let str_11 = extend(hStart, year to fraction) - extend(hEnd, year to fraction) let hora=str_11[11,12] let minuto=str_11[14,15] let segundo=str_11[17,18] #display hora, " " ,minuto," " , segundo if hora > 0 then display "ERROR Hour " , str_11 else if minuto > 0 then display "ERROR MINUTE " , str_11 else if segundo >= 2 then display "ERROR SECUND " , str_11 else display hStart," - ",hEnd," - ",str_11 end if end if end if if hEnd = hStart Then display "HOUR THE SAME: ",hStart," - ",hEnd," - ",str_11 end if end while exit program end main
Unless this text has typos in it versus the real code, this will not compile, so you may be running a different executable than you think you are. In the code below you define a variable named <contador> but you are testing and also assigning to an undefined variable named <count>. I also note that there is logic to note the time different "if count >= 10" but you never assign anything but "1" to count. Clean up the program and try again. Note that CURRENT will return the same value whenever it is called within a transaction, that being the time the transaction was started. If your database is an ANSI mode database there would be an implied transaction started when you connected to the database (yes I do note that this program has not database or connect statements). Also, I don't know what you mean by "if this sleep is made by informix" and "if the sleep is made by calling system". Please elaborate. Art Art S. Kagel, President and Principal Consultant ASK Database Management www.askdbmgt.com Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Mon, Sep 7, 2015 at 7:24 AM, PEDRO BIZARRO <pedro@gba.pt> wrote: > Good Morning > I have the following configuration: > UnixWare 7.1.4 (virtualized with VMware) > Informix Dynamic Server Version 7.30.UC2 > > I have a problem with time with informix 4gl, if running the program > below, in > random situations what happens is that the time is the same for about an > hour. > > The program sleeps for 1 secund, if this sleep is made by informix it > block's, > if the sleep is made by calling system, it advance. In both cases the time > is > the same. > > Anyone ever had a similar problem, if so how to solve > Thank you. > Pedro Bizarro > > ############################################################## > # SLEEP SEGUNDO A SEGUINDO PARA VER A DIFERENCA DE HORAS > ############################################################## > MAIN > define str_1,str_11 char(50) > define hora,minuto,segundo char(2) > define hStart,hEnd datetime year to fraction > define contador integer > define test,test3 char(60) > let test = "sleep 1" > let test3 = "sleep 3" > let count = 1 > while not int_flag > > if count >= 10 then > > let hStart=current year to fraction > > run test3 > > let contador = 1 > > let hEnd=current year to fraction > > let hEnd="2015-09-04 18:10:25.000" > > else > > let hStart=current year to fraction > > run test > > let hEnd=current year to fraction > > end if > > let str_11 = extend(hStart, year to fraction) > > - extend(hEnd, year to fraction) > > let hora=str_11[11,12] > > let minuto=str_11[14,15] > > let segundo=str_11[17,18] > > #display hora, " " ,minuto," " , segundo > > if hora > 0 then > > display "ERROR Hour " , str_11 > > else if minuto > 0 then > > display "ERROR MINUTE " , str_11 > > else if segundo >= 2 then > > display "ERROR SECUND " , str_11 > > else > > display hStart," - ",hEnd," - ",str_11 > > end if > > end if > > end if > > if hEnd = hStart Then > > display "HOUR THE SAME: ",hStart," - ",hEnd," - ",str_11 > > end if > end while > exit program > end main > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --001a1141bd52580fde051f27ba5c
hello Art Thanks for the quick response, actually existed error in the code when trying to translation to English , so the code that follows is already fixed. What I meant with informix of sleep is to use the of 4gl function , or run the sleep of the operating system. Pedro Bizarro ############################################################## # SLEEP SEGUNDO A SEGUINDO PARA VER A DIFERENCA DE HORAS ############################################################## MAIN define lixo,lixo1 char(50) define hora,minuto,segundo char(2) define hStart,hEnd datetime year to fraction define count integer define teste,teste3 char(60) let count = 1 while not int_flag let hStart=current year to fraction let teste = "sleep 1" run teste { with the next command the error occours sleep 1 } let hEnd=current year to fraction let lixo1 = extend(hStart, year to fraction) - extend(hEnd, year to fraction) let hora=lixo1[11,12] let minuto=lixo1[14,15] let segundo=lixo1[17,18] #display hora, " " ,minuto," " , segundo if hora > 0 then display "ERROR HOUR " , lixo1 else if minuto > 0 then display "ERROR MINUTE " , lixo1 else if segundo >= 2 then display "ERROR SECOND " , lixo1 else display hStart," - ",hEnd," - ",lixo1 end if end if end if if hEnd = hStart Then display "ERROR Time the Same: ",hStart," - ",hEnd," - ",lixo1 end if end while exit program end main
Pedro: So if you replace these two lines: let teste = "sleep 1" run teste with these two: with the next command the error occours sleep 1 the time does not advance, but either way you are getting the timestamp from the 4GL CURRENT verb. Correct? From the 4GL manual: If CURRENT is executed more than once in a statement, identical values might be returned at each call... What seems to be happening is that if you sleep using the 4GL SLEEP verb the internal timer is reusing the last time it got from the OS rather than reading the time again. However, if you use the RUN verb to execute the OS's sleep utility which calls the sleep() system call that triggers 4GL to reread the system clock. I would suggest two solutions: 1. Use the database server to get the time: SELECT CURRENT YEAR TO FRACTION(3) INTO hEnd FROM sysmaster:sysdual; or: SELECT dbinfo( 'utc_to_datetime', sh_curtime )::DATETIME YEAR TO SECOND INTO hEnd FROM sysmaster:sysshmvals; or: 2. Write a little 4GL callable function in "C" to call gettimeofday() and convert that into a datetime and return it. It would be easiest to return the seconds and microseconds parts of the return from gettimeofday() to 4GL and convert them to a datetime in 4GL with: CALL my_time_func() RETURNING h_sec, h_usec SELECT dbinfo( 'utc_to_datetime, hsec )::YEAR TO FRACTION(3) + INTERVAL ((h_usec/1000)) FRACTION(3) TO FRACTION INTO hEnd FROM sysmaster:sysdual; Art Art S. Kagel, President and Principal Consultant ASK Database Management www.askdbmgt.com Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Mon, Sep 7, 2015 at 10:05 AM, PEDRO BIZARRO <pedro@gba.pt> wrote: > hello Art > Thanks for the quick response, actually existed error in the code when > trying > to translation to English , so the code that follows is already fixed. > What I meant with informix of sleep is to use the of 4gl function , or run > the > sleep of the operating system. > > Pedro Bizarro > > ############################################################## > # SLEEP SEGUNDO A SEGUINDO PARA VER A DIFERENCA DE HORAS > ############################################################## > MAIN > define lixo,lixo1 char(50) > define hora,minuto,segundo char(2) > define hStart,hEnd datetime year to fraction > define count integer > define teste,teste3 char(60) > let count = 1 > while not int_flag > > let hStart=current year to fraction > > let teste = "sleep 1" > > run teste > > { > > with the next command the error occours > > sleep 1 > > } > > let hEnd=current year to fraction > > let lixo1 = extend(hStart, year to fraction) - extend(hEnd, year to > fraction) > > let hora=lixo1[11,12] > > let minuto=lixo1[14,15] > > let segundo=lixo1[17,18] > > #display hora, " " ,minuto," " , segundo > > if hora > 0 then > > display "ERROR HOUR " , lixo1 > > else if minuto > 0 then > > display "ERROR MINUTE " , lixo1 > > else if segundo >= 2 then > > display "ERROR SECOND " , lixo1 > > else > > display hStart," - ",hEnd," - ",lixo1 > > end if > > end if > > end if > > if hEnd = hStart Then > > display "ERROR Time the Same: ",hStart," - ",hEnd," - ",lixo1 > > end if > end while > exit program > end main > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --001a1141bd52e9fc97051f2a294a
Of course, if your purpose is just to time some operations within your program, a set of 4GL callable time functions, written in "C" that handle the timeval structure that gettimeofday() returns directly and calculate the difference in time in fractional seconds would be most beneficial. Not hard to implement either. Art Art S. Kagel, President and Principal Consultant ASK Database Management www.askdbmgt.com Blog: http://informix-myview.blogspot.com/ Disclaimer: Please keep in mind that my own opinions are my own opinions and do not reflect on the IIUG, nor any other organization with which I am associated either explicitly, implicitly, or by inference. Neither do those opinions reflect those of other individuals affiliated with any entity with which I am affiliated nor those of the entities themselves. On Mon, Sep 7, 2015 at 11:47 AM, Art Kagel <art.kagel@gmail.com> wrote: > Pedro: > > So if you replace these two lines: > > let teste = "sleep 1" > > run teste > > with these two: > > with the next command the error occours > > sleep 1 > > the time does not advance, but either way you are getting the timestamp > from the 4GL CURRENT verb. Correct? > > >From the 4GL manual: > > If CURRENT is executed more than once in a statement, identical values > might be returned at each call... > > What seems to be happening is that if you sleep using the 4GL SLEEP verb > the internal timer is reusing the last time it got from the OS rather than > reading the time again. However, if you use the RUN verb to execute the > OS's sleep utility which calls the sleep() system call that triggers 4GL to > reread the system clock. I would suggest two solutions: > > 1. Use the database server to get the time: > > SELECT CURRENT YEAR TO FRACTION(3) INTO hEnd FROM sysmaster:sysdual; > > or: > > SELECT dbinfo( 'utc_to_datetime', sh_curtime )::DATETIME YEAR TO SECOND > > INTO hEnd FROM sysmaster:sysshmvals; > > or: > > 2. Write a little 4GL callable function in "C" to call gettimeofday() > > and convert that into a datetime and return it. > > It would be easiest to return the seconds and microseconds parts of the > > return from gettimeofday() to 4GL and convert them to a datetime in 4GL > > with: > > CALL my_time_func() RETURNING h_sec, h_usec > > SELECT dbinfo( 'utc_to_datetime, hsec )::YEAR TO FRACTION(3) + INTERVAL > > ((h_usec/1000)) FRACTION(3) TO FRACTION > > INTO hEnd > > FROM sysmaster:sysdual; > > Art > > Art S. Kagel, President and Principal Consultant > ASK Database Management > www.askdbmgt.com > > Blog: http://informix-myview.blogspot.com/ > > Disclaimer: Please keep in mind that my own opinions are my own opinions > and do not reflect on the IIUG, nor any other organization with which I am > associated either explicitly, implicitly, or by inference. Neither do > those opinions reflect those of other individuals affiliated with any > entity with which I am affiliated nor those of the entities themselves. > > On Mon, Sep 7, 2015 at 10:05 AM, PEDRO BIZARRO <pedro@gba.pt> wrote: > > > hello Art > > Thanks for the quick response, actually existed error in the code when > > trying > > to translation to English , so the code that follows is already fixed. > > What I meant with informix of sleep is to use the of 4gl function , or > run > > the > > sleep of the operating system. > > > > Pedro Bizarro > > > > ############################################################## > > # SLEEP SEGUNDO A SEGUINDO PARA VER A DIFERENCA DE HORAS > > ############################################################## > > MAIN > > define lixo,lixo1 char(50) > > define hora,minuto,segundo char(2) > > define hStart,hEnd datetime year to fraction > > define count integer > > define teste,teste3 char(60) > > let count = 1 > > while not int_flag > > > > let hStart=current year to fraction > > > > let teste = "sleep 1" > > > > run teste > > > > { > > > > with the next command the error occours > > > > sleep 1 > > > > } > > > > let hEnd=current year to fraction > > > > let lixo1 = extend(hStart, year to fraction) - extend(hEnd, year to > > fraction) > > > > let hora=lixo1[11,12] > > > > let minuto=lixo1[14,15] > > > > let segundo=lixo1[17,18] > > > > #display hora, " " ,minuto," " , segundo > > > > if hora > 0 then > > > > display "ERROR HOUR " , lixo1 > > > > else if minuto > 0 then > > > > display "ERROR MINUTE " , lixo1 > > > > else if segundo >= 2 then > > > > display "ERROR SECOND " , lixo1 > > > > else > > > > display hStart," - ",hEnd," - ",lixo1 > > > > end if > > > > end if > > > > end if > > > > if hEnd = hStart Then > > > > display "ERROR Time the Same: ",hStart," - ",hEnd," - ",lixo1 > > > > end if > > end while > > exit program > > end main > > > > > > > > > > ******************************************************************************* > > Forum Note: Use "Reply" to post a response in the discussion forum. > > > > > > --001a1141bd52e9fc97051f2a294a > > > > ******************************************************************************* > Forum Note: Use "Reply" to post a response in the discussion forum. > > --089e0122e6e8342395051f2a9f68