Is it any solution to get default values for a field on new record ?
For a field that must be not null, the server default values is never used.
PS: I use zeos with postgres.
10x
Marius
Default values on new record
Moderators: gto, cipto_kh, EgonHugeist
Yes I can do this.
But is better that the default value to be set to a field and the customer
can modify this value. It is an ellegant solution for sequences too.
I found in ZDbcCachedResultSet.pas a method: CalculateRowDefaults.
How can I use this to set fields values to default when a new record is created.
But is better that the default value to be set to a field and the customer
can modify this value. It is an ellegant solution for sequences too.
I found in ZDbcCachedResultSet.pas a method: CalculateRowDefaults.
How can I use this to set fields values to default when a new record is created.
change the TZAbstractRODataset.DoOnNewRecord (in ZAbstractRODataset.pas) for the using of TField.DefaultExpresson:
Code: Select all
procedure TZAbstractRODataset.DoOnNewRecord;
var
I: Integer;
MasterField, DetailField: TField;
Temp: Int64;
// start new code
vStr : String;
function StringInArray(const pStr : String; const pArray : array of String) : Boolean;
var
ii : Integer;
begin
Result := False;
for ii := Low(pArray) to High(pArray) do
begin
Result := pStr = pArray[ii];
if Result then Exit;
end;
end;
begin
for I := 0 to Fields.Count - 1 do
begin
with Fields[I] do
begin
vStr := UpperCase(Trim(DefaultExpression));
if vStr <> '' then
begin
if Fields[I] is TDateTimeField then
begin
if StringInArray(vStr, ['NOW', 'CURRENT_TIME', 'CURRENT_TIMESTAMP']) then
begin
AsDateTime := Now;
end
else if StringInArray(vStr, ['TODAY', 'CURRENT_DATE']) then
begin
AsDateTime := Trunc(Now);
end
else if (vStr = 'TOMORROW') then
begin
AsDateTime := Trunc(Now) + 1;
end
else if (vStr = 'YESTERDAY') then
begin
AsDateTime := Trunc(Now) - 1;
end
else if vStr <> 'NULL' then
begin
AsString := DefaultExpression;
end;
end
else if vStr <> 'NULL' then
begin
AsString := DefaultExpression;
end;
end;
end;
end;
// end new code
if MasterLink.Active and (MasterLink.Fields.Count > 0) then
begin
for I := 0 to MasterLink.Fields.Count - 1 do
maybe this can help:
http://seegernet.koolhost.de/zeosforum/ ... .php?t=298
it removes Required property in columns with default values, then Zeos
uses default values.
http://seegernet.koolhost.de/zeosforum/ ... .php?t=298
it removes Required property in columns with default values, then Zeos
uses default values.
In fact the Filed.DefaultExpression is allways emty.krluigo wrote:change the TZAbstractRODataset.DoOnNewRecord (in ZAbstractRODataset.pas) for the using of TField.DefaultExpresson:
Code: Select all
............... begin for I := 0 to Fields.Count - 1 do begin with Fields[I] do begin vStr := UpperCase(Trim(DefaultExpression)); if vStr <> '' then ................
Is it a bug ?
If not, how can I set DefaultExpression when the query is open.
Thx
Marius