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
append error
Moderators: gto, cipto_kh, EgonHugeist
Re: append error
Hello!slai wrote:hy
i work with zeoslib lazarus .0.9.17 and firebird 1.5
This is my function...
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;
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;