append error

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
slai
Senior Boarder
Senior Boarder
Posts: 53
Joined: 07.07.2006, 10:45
Location: office

append error

Post by slai »

hy

i work with zeoslib lazarus .0.9.17 and firebird 1.5

This is my function

function appendrecord(sTablename : String; SLFieldentrys : TStringList):boolean;
var
dbtbl : TZTable;
slFieldlist : TStringList;
i : integer;
begin
slFieldlist := TStringList.Create;
dbtbl := getTable(sTablename);
dbtbl.GetFieldNames(slFieldlist);
dbtbl.Append;
for i := 0 to slFieldlist.Count -1 do begin
if SLFieldentrys <> '#1' then begin
dbtbl.FieldByName(slFieldlist).AsString := SLFieldentrys;
end else begin
dbtbl.FieldByName(slFieldlist).AsInteger := dbtbl.Sequence.GetNextValue;
end;
end;
try
dbtbl.Post;
result := true;
except
result := false;
dbtbl.Cancel;
end;
dbtbl := nil;
slFieldlist.Free;
end;


on append it comes an error:

SQL Error: validation error for column ICONFIGMASKENID, value ''***null***''.Error Code:-625. The instert failed because a column definition includes validation constraints. The SQL: INSERT INTO CON###(gdb unparsed remainder:...)###

i fild the id field on SLFieldentrys = '#1'

can someone help me?

thanks
gto
Zeos Dev Team
Zeos Dev Team
Posts: 278
Joined: 11.11.2005, 18:35
Location: Porto Alegre / Brasil

Re: append error

Post by gto »

slai wrote:hy

i work with zeoslib lazarus .0.9.17 and firebird 1.5

This is my function...
Hello!
Here's a hint, when posting code (like your function), post it into BBCode "code" tags. It will look like this:

Code: Select all

function AppendRecord(sTablename: string; SLFieldEntrys: TStringList): boolean;
var
   DbTbl: TZTable;
   slFieldList: TStringList;
   i: integer;
begin
   slFieldList := TStringList.Create;
   DbTbl := getTable(sTablename);
   try
      DbTbl.GetFieldNames(slFieldList);
      DbTbl.Append;
      for i := 0 to slFieldlist.Count - 1 do
         if SLFieldEntrys[i] <> '#1' then
            DbTbl.FieldByName(slFieldList[i]).AsString := SLFieldEntrys[i]
         else
            DbTbl.FieldByName(slFieldList[i]).AsInteger := DbTbl.Sequence.GetNextValue;
      try
         DbTbl.Post;
         result := true;
      except
         result := false;
         DbTbl.Cancel;
      end;
   finally
      DbTbl := nil;
      slFieldList.Free;
   end;
end;
Much more readable :)

About your function: I've changed it a bit, just estetic things. The error that you're getting refers to a field called ICONFIGMASKENID which is constrained into database by not null or another validation mechanism.

My suggestion: Debug Function!

Code: Select all

function DebugAppendRecord(sTablename: string; SLFieldEntrys: TStringList): boolean;
var
   DbTbl: TZTable;
   slFieldList: TStringList;
   str: string;
   i: integer;
begin
   slFieldList := TStringList.Create;
   DbTbl := getTable(sTablename);
   try
      DbTbl.GetFieldNames(slFieldList);
      if (slFieldList.Count <> SLFieldEntrys.Count) then
         ShowMessage('Problem! Fields and Values number does not match!' + #10 +
            'Field count: ' + IntToStr(slFieldList.Count) +
            'Values count: ' + IntToStr(SLFieldEntrys.Count));
      str := '';
      for i := 0 to slFieldlist.Count - 1 do
         if SLFieldEntrys[i] <> '#1' then
            str := str + slFieldList[i] + ' will receive -> ' + SLFieldEntrys[i] + #10
         else
            str := str + slFieldList[i] + ' will receive -> the next sequence number' + #10;
   finally
      DbTbl := nil;
      slFieldList.Free;
   end;
end;
Use the FU!!!!!IN Google !

gto's Zeos Quick Start Guide

Te Amo Taís!
slai
Senior Boarder
Senior Boarder
Posts: 53
Joined: 07.07.2006, 10:45
Location: office

Post by slai »

Thank you for your answer.

i searched at the false position i thought that the sequence doesnt work but the ICONFIGMASKENID field was fill with 0.

thank you very much.

greez andi
Post Reply