Page 1 of 1

Problems with exceptions

Posted: Tue 15 Mar 2005 19:21
by jorgus
I have the next table

Code: Select all

TABLE1
    ID           NUMBER,
    NAME      VARCHAR(20),
    DATE_N   DATE,
    SAL         NUMBER
The insertion I do with OraQuery
SQLInsert

Code: Select all

insert into ADRH.TABLE1
     (ID, NAME, DATE_N,SAL)
values
  (:ID, :NAME, :DATE_N, :SAL )

Code: Select all

//
implementation
function ExceptionCode(AException: Exception): String;
begin
  Result := Copy(AException.Message,  4, 6);
end;

function IsOracleException(AException: Exception): Boolean;
begin
  Result := Copy(AException.Message, 1, 4) = 'ORA-';
end;

Code: Select all

procedure TConceptos.ACEPTClick(Sender: TObject);
begin
  try
    OraQuery1.Open;
    OraQuery1.Append;
    OraQuery1.FieldByName('ID').AsInteger:= strtoint(trim(Maskedit1.Text));
    OraQuery1.FieldByName('NAME').AsString:= Maskedit2.Text;
    OraQuery1.FieldByName('DATE_N').AsDateTime:= strtodate(trim(Maskedit3.Text));
    OraQuery1.FieldByName('SAL').AsInteger:= strtoint(trim(Maskedit4.Text));
    OraQuery1.Post;
    OraQuery1.Session.StartTransaction;
    OraQuery1.ApplyUpdates;
    OraQuery1.Session.Commit;
    OraQuery1.CommitUpdates;
  except
    on E: Exception do
    begin
      if IsOracleException(E) then
      begin
        if ExceptionCode(E) = '-01400' then
          E.Message := 'cannot insert NULL';
      end;
      raise;
    end;
  end;
end;

inserted NULL in fields NOT NULL with SQL Plus It gives me the error:
ORA-01400: It is not possible to realize an insertion NULL in ("ADRH"."TABLA1"."ID"), But in the delphi says to me Project Project1.exe raised exception class EConvertError with message "" is not a valid integer value' and with Field type DATE The same thing happens......

Can help me to solve my problem??

Posted: Wed 16 Mar 2005 08:55
by Alex
It is not an ODAC problem pls. read carefully StrToInt and StrToDate Delphi help, your exception raises when You try to convert string "" to integer or datetime type. If You need to send Null value You can use OraQuery1.FieldByName('SAL').Value := Null.