Recent

Author Topic: Zeos components & TZUpdateSQL  (Read 15079 times)

warcode

  • New Member
  • *
  • Posts: 36
Zeos components & TZUpdateSQL
« on: August 05, 2010, 10:24:24 pm »
Hi all i have some trouble to make working the TZUpdateSQL, im usin zeos version 7.0.0-dev and i'm using mssql for now ...

if i understand correcly TZUpdateSQL depend on a  TZQuery
you need to set UpdateObject propriety to your TZUpdateSQL

and this is my code ...

  tmp_sql := 'insert into tReceptions (fkFournisseur,PO,DatePrevu,NbPalettePrevu,NbPaletteRecu,Note) values ( ' + QuotedStr(four) + ' , ' + QuotedStr(po) + ' , ' + QuotedStr(start_date) + ' , ' + QuotedStr(pal_prevu) + ' , ' + QuotedStr(pal_recu) + ' , ' + QuotedStr(note) + ' )';


ZQuery.UpdateObject := Zup;
ZUp.InsertSQL.Text := tmp_sql;

ZQuery.Open;
ZQuery.ExecSQL;

ZQuery.ApplyUpdates;
ZQuery.CommitUpdates;

ZQuery.Close;      


When i run this it crash with a error EdatabaseError : Operation connot be performed on an incative dataset
BTW when i dont use ZUp (TZUpdateSQL) and pass my insert sql direcly to ZQuery.SQL.text and run it its work (insert a new record ) but give me a error : Con not open a Resultset.

Some one can help my with this
Thanks for any help
Christian F

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
Re: Zeos components & TZUpdateSQL
« Reply #1 on: August 06, 2010, 12:48:07 am »
this is not the way you are supposed to use a TZUpdateSQL.

You only need to provide a TZUpdateSQL object to a TZQuery, when the TZQuery itself is not updatable (like a select from a view or from multiple tables).

When you want to execute a insterstatement directly, assign this statement to the TZQuery.SQL and use TZQuery.ExecSQL.
IIRC you can in this case also use TZConnection.ExecuteDirect('your statmement')

A usage of TZUpdateSQL is more like:
Code: Pascal  [Select]
  1.  
  2. ZQuery.SQL := 'select fieldname1, fieldname2, ... from foo';
  3. ZQuery.UpdateObject := Zup;
  4. ZUp.InsertSQL.Text := 'insert into foo (fieldname1, fieldname2, ...) values (:fieldname1, :fieldname2, ...)';
  5.  
  6. ZQuery.Open;
  7. ZQuery.Append;
  8. ZQuery.FieldByName('fieldname1').Value := 'bar';
  9. ZQuery.FieldByName('fieldname2').Value := '123';
  10. ....
  11. ZQuery.Post;
  12. ZQuery.Close;      
  13.  

BTW, In this case using a TZQuery on a form/datamudule and using persistent fields is a more usefull approach.
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

warcode

  • New Member
  • *
  • Posts: 36
Re: Zeos components & TZUpdateSQL
« Reply #2 on: August 06, 2010, 02:48:01 pm »
Hi Marc thanks for the help, i dont understand the difference in this
ZUp.InsertSQL.Text := 'insert into foo (fieldname1, fieldname2, ...) values (:fieldname1, :fieldname2, ...)'; 

and

# ZQuery.FieldByName('fieldname1').Value := 'bar'; 
# ZQuery.FieldByName('fieldname2').Value := '123';

anyway i try it ... it giving me no error but dont add the new record so i use the plan b with

TZConnection.ExecuteDirect('my insert sql')

and its work perfecly .. any disadvantage of using TZConnection direcly ?

Christian F


marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7858
Re: Zeos components & TZUpdateSQL
« Reply #3 on: August 06, 2010, 03:15:15 pm »
When I was playing with Zeos, I thought it was really useful to have a sql monitor somewhere to see what is actually sent to the DB.

For me tzupdatesqls worked fine (designtime even), except that you then need to set some event to copy values from the query (selected row) to the params of the tzupdatesql component. (typically pk's and fk's)

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2496
Re: Zeos components & TZUpdateSQL
« Reply #4 on: August 08, 2010, 02:03:24 pm »

anyway i try it ... it giving me no error but dont add the new record so i use the plan b with

TZConnection.ExecuteDirect('my insert sql')

and its work perfecly .. any disadvantage of using TZConnection direcly ?

there is no disadvantage since IIRC, internally, after a TZquey is parsed etc, zeas uses the same
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker