summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fcl-db/src/sqldb/examples/fedittable.pp
blob: a729aa012c74d6da8d24f8e0fe567fd97819f73c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(******************************************************************************
 *                                                                            *
 *  (c) 2005 CNOC v.o.f.                                                      *
 *                                                                            *
 *  File:        fEditTable.pp                                                *
 *  Author:      Joost van der Sluis (joost@cnoc.nl)                          *
 *  Description: SQLDB example and test program                               *
 *  License:     GPL                                                          *
 *                                                                            *
 ******************************************************************************)

program fEditTable;

{$mode objfpc}{$H+}

uses
  Classes, sysutils,
  sqldb,
  SqldbExampleUnit;
  

begin
  ReadIniFile;

  CreateFConnection;
  CreateFTransaction;
  CreateFQuery;

  Fconnection.Transaction := Ftransaction; //all updates are performed in this transaction

  with Fquery do
    begin

    SQL.Clear;
    
    SQL.Add('select * from FPDEV');

// With these lines commented out, TSQLQuery creates the update, delete and insert
// queries itself.
// For more complex queries, though, it could be nessecary to provide these queries
// here

//    UpdateSQL.add('update fpdev set name=:name, birthdate=:birthdate where id=:OLD_id');
//    DeleteSQL.add('delete from fpdev where id=:OLD_id');
//    InsertSQL.add('insert into fpdev(id,name,email,birthdate) values (:id,:name,:email,:birthdate)');}

    open;

    Edit;
    FieldByName('name').AsString := FPdevNames[1];
    FieldByName('birthdate').AsDateTime := FPdevBirthDates[1];
    Post;
    
    Append;
    FieldByName('id').AsInteger := 8;
    FieldByName('name').AsString := FPdevNames[8];
    FieldByName('email').AsString := FPdevEmails[8];
    FieldByName('birthdate').AsDateTime := FPdevBirthDates[8];
    post;
    
    ApplyUpdates;

    end;
  Ftransaction.Commit;

  Fquery.Free;
  Ftransaction.Free;
  Fconnection.Free;
end.