Subject Re: [firebird-support] Fake error "arithmetic exception, numeric overflow..." on stored procedure or trigger
Author marco andreolli
2018-02-22 16:29 GMT+01:00 Mark Rotteveel mark@... [firebird-support] <firebird-support@yahoogroups.com>:
 

On 21-2-2018 12:29, marco andreolli drazde@... [firebird-support]
wrote:
> Recently I have found the error /arithmetic exception, numeric overflow,
> or string truncation/
> /string right truncation
> At trigger 'XXXXX'
> /
> on different trigger or stored procedure.
> The strange thing is that are not true, in the trigger or procedure
> there isn't any operation that coud produce this exception!
>
> I "recompile" the trigger or procedure that are affected and the error
> disappear!.
> It could be a bug in my relase of Firebird?

AFAIK, this can happen if you changed the definition of a column to be
wider, but did not recompile the triggers or stored procedures. Those
are still using the older, smaller size and then break when confronted
with a value that is wider.

Mh, This exception happened also on this utility procedure, that I don't use directly comumn....

CREATE PROCEDURE TOKENIZE (
    INPUT BLOB SUB_TYPE 1 SEGMENT SIZE 80,
    TOKEN VARCHAR(1))
RETURNS (
    RESULT VARCHAR(255))
AS
DECLARE VARIABLE TROVATO VARCHAR(1);
DECLARE VARIABLE NEWPOS INTEGER;
DECLARE VARIABLE OLDPOS INTEGER;
DECLARE VARIABLE APPO INTEGER;
DECLARE VARIABLE STR_APPO BLOB SUB_TYPE 1 SEGMENT SIZE 80;
BEGIN
  oldpos = 1;
  newpos = 1;
  WHILE (not(INPUT = '')) DO BEGIN
    INPUT = SUBSTRING(INPUT FROM oldpos);

    appo = 0;
    newpos = 0;
    trovato = 'F';
    while (trovato = 'F') do begin
      appo = appo + 1;
        if (SUBSTRING(INPUT FROM appo FOR 1) = token)
        then begin
          trovato = 'T';
          newpos = appo;
        end
      if (appo > CHAR_LENGTH(INPUT))
        then begin
          trovato = 'T';
          newpos = appo;
        end
    end

    IF (newpos > 0)
      THEN BEGIN
        result = SUBSTRING(INPUT FROM 1 FOR newpos -1);
        IF (CHAR_LENGTH(TRIM(result)) >= 1)
          THEN SUSPEND;
        oldpos = newpos + 1;
      END
      ELSE IF (oldpos > 1)
             THEN BEGIN
               result = SUBSTRING(INPUT FROM 1);
               IF (CHAR_LENGTH(TRIM(result)) >= 1)
                 THEN SUSPEND;
               BREAK;
             END
            ELSE BREAK;
  END
END


Mark
--
Mark Rotteveel