.NET Zip component, Delphi Zip component, Barcode .NET, BDE Replacement and other .NET and Delphi components from ComponentAce
Products Download Order Contact us

Search
 

Delphi/C++ Components
.NET Components
ActiveX Controls
Kylix Components

Download

Download
Download Commercial
Trial Limitations

Support

Submit Request
Support Options

Order

Purchase
Competitive Upgrade
Premium Support
Sales Policy
Upgrade Policy
License Types

Info

News
Mailing List
Articles
Testimonials



About Us
Partners
Links
Contact Us
Link to Us





Home > Delphi/C++ Components > Absolute Database > Transaction Delphi Example

Absolute Database

Overview | Features | Requirements | Testimonials | SQL Samples | Code Samples | Screenshots | See Also | Download | Order
Transaction Delphi Example
Illustrates how to insert data in transaction.

Download Absolute Database | Learn more

unit Main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Buttons, ExtCtrls, Grids, DBGrids, Db, ABSMain, DBCtrls;

const
  DataBaseFileName: String = '..\..\Data\Demos.abs';

type
  TMainForm = class(TForm)
    DataSource1: TDataSource;
    ABSTable1: TABSTable;
    ABSQuery1: TABSQuery;
    dbDemos: TABSDatabase;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    btTransactionWithTable: TButton;
    btTransactionWithQuery: TButton;
    cbFlush: TCheckBox;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    procedure btTransactionWithTableClick(Sender: TObject);
    procedure btTransactionWithQueryClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;

implementation


{$R *.DFM}

procedure TMainForm.btTransactionWithTableClick(Sender: TObject);
begin
  dbDemos.StartTransaction;
  try
    AbsTable1.Insert;
    AbsTable1.FieldByName('name').AsString := 'Kelly';
    AbsTable1.Post;
    dbDemos.Commit(cbFlush.Checked);
  except
    dbDemos.Rollback;
  end;
end;

procedure TMainForm.btTransactionWithQueryClick(Sender: TObject);
begin
  with ABSQuery1 do
    begin
      SQL.Text := 'START TRANSACTION; INSERT INTO friends (name) values ("Junior");';
      if cbFlush.Checked then
        SQL.Text := SQL.Text + 'COMMIT;'
      else
        SQL.Text := SQL.Text + 'COMMIT NOFLUSH;';
      try
        ExecSQL;
      except
        SQL.Text := 'ROLLBACK';
        ExecSQL;
      end;
    end;
  ABSTable1.Refresh;
end;

procedure TMainForm.FormCreate(Sender: TObject);
var q: TABSQuery;
begin
  dbDemos.DatabaseFileName := ExtractFilePath(Application.ExeName) + DataBaseFileName;
  dbDemos.Open;

  q := TABSQuery.Create(nil);
  try
    q.DatabaseName := dbDemos.DatabaseName;
    q.SQL.Clear;
    q.SQL.Append('drop table friends;');
    q.SQL.Append('create table friends (id AutoInc, name varchar(20));');
    q.SQL.Append('insert into friends (name) values ("Kim");');
    q.SQL.Append('insert into friends (name) values ("Scott");');
    q.ExecSQL;
  finally
    q.Free;
  end;

  ABSTable1.Open;
end;

procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ABSTable1.Close;
  ABSTable1.DeleteTable;
end;

end.



Transaction Delphi Example
Download Absolute Database | Learn more


Product Info


Current version: 7.95
Released: February 08, 2023
Price: $ 149

downloadorder


Our Customers



Testimonials

The other people in the office didn't believe me when I said that all I had to do was document the problem and you would probably give me a fix overnight. Unbelievable! Keep up the great work. I hope you guys all make a fortune out of this product because it is truly fantastic and the support is the best I have ever encountered.

Mark Kefford

        © 2003 - 2024 ComponentAce  | .net zip component | barcode for .net | delphi zip component | delphi database Oct 07, 2024