fedittable.pp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. (******************************************************************************
  2. * *
  3. * (c) 2005 CNOC v.o.f. *
  4. * *
  5. * File: fEditTable.pp *
  6. * Author: Joost van der Sluis ([email protected]) *
  7. * Description: SQLDB example and test program *
  8. * License: GPL *
  9. * *
  10. ******************************************************************************)
  11. program fEditTable;
  12. {$mode objfpc}{$H+}
  13. uses
  14. Classes, sysutils,
  15. sqldb,
  16. SqldbExampleUnit;
  17. begin
  18. ReadIniFile;
  19. CreateFConnection;
  20. CreateFTransaction;
  21. CreateFQuery;
  22. Fconnection.Transaction := Ftransaction; //all updates are performed in this transaction
  23. with Fquery do
  24. begin
  25. SQL.Clear;
  26. SQL.Add('select * from FPDEV');
  27. // With these lines commented out, TSQLQuery creates the update, delete and insert
  28. // queries itself.
  29. // For more complex queries, though, it could be nessecary to provide these queries
  30. // here
  31. // UpdateSQL.add('update fpdev set name=:name, birthdate=:birthdate where id=:OLD_id');
  32. // DeleteSQL.add('delete from fpdev where id=:OLD_id');
  33. // InsertSQL.add('insert into fpdev(id,name,email,birthdate) values (:id,:name,:email,:birthdate)');}
  34. open;
  35. Edit;
  36. FieldByName('name').AsString := FPdevNames[1];
  37. FieldByName('birthdate').AsDateTime := FPdevBirthDates[1];
  38. Post;
  39. Append;
  40. FieldByName('id').AsInteger := 8;
  41. FieldByName('name').AsString := FPdevNames[8];
  42. FieldByName('email').AsString := FPdevEmails[8];
  43. FieldByName('birthdate').AsDateTime := FPdevBirthDates[8];
  44. post;
  45. ApplyUpdates;
  46. end;
  47. Ftransaction.Commit;
  48. Fquery.Free;
  49. Ftransaction.Free;
  50. Fconnection.Free;
  51. end.