728x90

Troubleshooting


Problem

This article describes a problem which occurs when CURRENT does not recalculate the actual date and time when called more than once in a stored procedure.

Resolving The Problem


PROBLEM

Repeated calls to the CURRENT function within a stored procedure always returns the same value.

This problem is typically seen when the stored procedure uses a cursor that loops through large quantities of data, such that by the time the final row is reached, the actual time has moved on and CURRENT no longer hold the true system datetime.


CAUSE

If using CURRENT in a stored procedure, the datetime value is set to the current system datetime at the time the procedure is called. CURRENT is not updated while the stored procedure is running.


SOLUTION

The system table sysmaster:sysshmvals.sh_curtime stores the exact system datetime. Run the following query within your stored procedure to return the actual time and store it into the local variable current_time.

select DBINFO('utc_to_datetime', sh_curtime) into current_time
from sysmaster:sysshmvals;

The following example demonstrates the different results returned when comparing the use of the CURRENT function with that of the sysshmvals query shown above.


Example:

create database currdemo;

create table dates (text char(20),
                    time datetime year to second);

create procedure test()
define i int;
define current_time datetime year to second;


insert into dates values ("current 1st run", CURRENT);

select DBINFO('utc_to_datetime', sh_curtime) into current_time
from sysmaster:sysshmvals;
insert into dates values ("realtime 1st run", current_time);

system "sleep 5" ;

insert into dates values ("current 2nd run", CURRENT);

select DBINFO('utc_to_datetime', sh_curtime) into current_time
from sysmaster:sysshmvals;
insert into dates values ("realtime 2nd run", current_time);

end procedure;

execute procedure test();

select * from dates order by text;


The output looks as follows:

text                 time

current 1st run      2006-10-31 17:02:11
current 2nd run      2006-10-31 17:02:11
realtime 1st run     2006-10-31 17:02:11
realtime 2nd run     2006-10-31 17:02:16

 

출처 : https://www.ibm.com/support/pages/how-obtain-actual-date-and-time-stored-procedure

728x90
728x90

얼마전에 고객사에 Informix 12.10.FC14버전을 설치했었는데 기존에 실행했던 쉘스크립트가 실행이 안되더군요. 오늘 IBM My Notifications 메일을 보고 관련된 내용을 알게 되어 공유하고자 합니다.

관련된 문서는 아래 링크에서 확인하실 수 있습니다.

www.ibm.com/support/pages/when-invoking-dbinfodbspacepartnum-error-727-raised

DBINFO 함수를 호출할 때 발생하는 문제인데요. partnum 값이 작은 경우 727 오류가 발생합니다.

$ echo "select first 1 dbinfo('dbspace',partnum) from systabnames;" | dbaccess sysmaster
Database selected.
  727: Invalid or NULL TBLspace number given to dbinfo(dbspace).
Error in line 1
Near character position 56
Database closed.

이전까지는 partnum이 가장 작은 값은 1048577이었지만 12.10.xC14 버전부터는 pseudo-tables, 소위 의사 테이블이 몇가지 추가되었다고 합니다. 14버전은 14.10.xC2 부터라는군요. 아래처럼 partnum 값이 6부터 153 까지 몇개 추가되었음을 알 수 있습니다.

$ echo "select first 10 partnum from sysmaster:systabnames;" | dbaccess stores_demo
Database selected.
    partnum
          6
         10
         15
         89
        153
    1048577
    1048578
    1048579
    1048580
    1048582

따라서 DBINFO 사용시 오류를 회피하기 위해서는 partnum 값이 1048576 이상인 값을 대상으로 조회해야 오류가 발생하지 않는다고 합니다. 관리적인 목적으로 DBINFO 함수를 사용하고 있다면 조건을 추가해야겠네요. 제가 테스트한바로는 위에서 보이는 153 이상의 조건으로도 오류가 발생하지는 않지만 IBM에서 권고하는 방법을 사용하는게 좋겠죠.

IBM문서에는 DBINFO_DBSPACE_RETURN_NULL_FOR_INVALID_PARTNUM 환경변수를 설정하면 된다고 합니다만 설정 전후 동작에 차이가 없는 것 같습니다. IBM에 별도의 패치버전을 요청해야되나 봅니다.

$ export DBINFO_DBSPACE_RETURN_NULL_FOR_INVALID_PARTNUM=1
$ echo "select first 1 dbinfo('dbspace',partnum) from systabnames;" | dbaccess sysmaster
Database selected.
  727: Invalid or NULL TBLspace number given to dbinfo(dbspace).
Error in line 1
Near character position 56
Database closed.
$ dbaccess sysmaster -
Database selected.
> set environment DBINFO_DBSPACE_RETURN_NULL_FOR_INVALID_PARTNUM "1";
19840: Invalid session environment variable.
Error in line 1
Near character position 65
>

12.10.xC14 버전 이상을 사용하실 때 참고하시면 좋겠습니다.

728x90

+ Recent posts