ApplyUpdate in designtime
Posted: 02.01.2007, 19:50
if a component TZQuery created at designtime and another component TZQuery (QRY from function listed below) created at runtime, they have your property CachedUpdates set up to true, if I insert a register via QRY (QRY cahedupdates's=true) at runtime, call "Free" for QRY and call ApplyUpdates for TZQuery component´s will save the register inserted via QRY in my database?
function PreencheCamposNaTabela(Clause, Tabela, GenID: string; Campos: array of string; Chave: string;
Var Valores: array of variant; IdResult: integer): string;
var
Qry : TZQuery;
cgo, ccs,
cvl, chv, gni: string;
i: integer;
begin
gni := IntToStr(DMZ.GetIncrementValue(AnsiUpperCase(GenID), 1));
chv := '(' + AnsiUpperCase(Chave) + ' = ' + gni;
if AnsiUpperCase(Clause) = 'INSERT INTO' then
begin
ccs := AnsiUpperCase(Clause) + ' ' + AnsiUpperCase(Tabela) + ' ';
for i := 0 to High(Campos) do
cgo := cgo + IIF(Campos <> '', ', ' + Campos, '');
cgo := ccs + '(' + AnsiUpperCase(Chave) + ' ' + cgo + ') VALUES (';
for i := 0 to High(Valores) do
cvl := cvl + IIF(VarToStr(Valores) <> '', ', ' + QuotedStr(VarToStr(Valores)), 'NULL');
cgo := cgo + QuotedStr(gni) + cvl + ')';
end;
if AnsiUpperCase(Clause) = 'UPDATE' then
begin
ccs := AnsiUpperCase(Clause) + ' ' + AnsiUpperCase(Tabela) + ' SET ';
for i := 0 to High(Campos) do
cgo := cgo + IIF(Campos <> '', ', ' + Campos + ' = ' + QuotedStr(VarToStr(Valores)), '');
cgo := ccs + chv + cgo + cvl + ')';
end;
Qry := TZQuery.Create(DMZ.zHalley);
try
with Qry do
begin
Connection := DMZ.zHalley;
SQL.Add(cgo);
ExecSQL;
Connection.Commit;
end;
finally
Qry.Free;
end;
if IdResult = -1 then
Result := gni
else
Result := VarToStr(Valores[IdResult]);
end;
function PreencheCamposNaTabela(Clause, Tabela, GenID: string; Campos: array of string; Chave: string;
Var Valores: array of variant; IdResult: integer): string;
var
Qry : TZQuery;
cgo, ccs,
cvl, chv, gni: string;
i: integer;
begin
gni := IntToStr(DMZ.GetIncrementValue(AnsiUpperCase(GenID), 1));
chv := '(' + AnsiUpperCase(Chave) + ' = ' + gni;
if AnsiUpperCase(Clause) = 'INSERT INTO' then
begin
ccs := AnsiUpperCase(Clause) + ' ' + AnsiUpperCase(Tabela) + ' ';
for i := 0 to High(Campos) do
cgo := cgo + IIF(Campos <> '', ', ' + Campos, '');
cgo := ccs + '(' + AnsiUpperCase(Chave) + ' ' + cgo + ') VALUES (';
for i := 0 to High(Valores) do
cvl := cvl + IIF(VarToStr(Valores) <> '', ', ' + QuotedStr(VarToStr(Valores)), 'NULL');
cgo := cgo + QuotedStr(gni) + cvl + ')';
end;
if AnsiUpperCase(Clause) = 'UPDATE' then
begin
ccs := AnsiUpperCase(Clause) + ' ' + AnsiUpperCase(Tabela) + ' SET ';
for i := 0 to High(Campos) do
cgo := cgo + IIF(Campos <> '', ', ' + Campos + ' = ' + QuotedStr(VarToStr(Valores)), '');
cgo := ccs + chv + cgo + cvl + ')';
end;
Qry := TZQuery.Create(DMZ.zHalley);
try
with Qry do
begin
Connection := DMZ.zHalley;
SQL.Add(cgo);
ExecSQL;
Connection.Commit;
end;
finally
Qry.Free;
end;
if IdResult = -1 then
Result := gni
else
Result := VarToStr(Valores[IdResult]);
end;