.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 > Blobs In Sql Delphi Example

Absolute Database

Overview | Features | Requirements | Testimonials | SQL Samples | Code Samples | Screenshots | See Also | Download | Order
Blobs In Sql Delphi Example
Illustrates how to use SQL query to add binary data using SQL MimeToBin function

Download Absolute Database | Learn more

unit uMain;

interface
{$I CompVer.inc}

uses
{$IFDEF D6H}
  Variants,
{$ENDIF}
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBCtrls, Grids, DBGrids, ABSMain, ABSDecUtil;

type
  TForm1 = class(TForm)
    tblImages: TABSTable;
    DBGrid1: TDBGrid;
    DBImage1: TDBImage;
    dsImages: TDataSource;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    memQuery: TMemo;
    tblImagesID: TAutoIncField;
    tblImagesFilePath: TStringField;
    tblImagesImage: TBlobField;
    Label2: TLabel;
    Label3: TLabel;
    btnCreateQuery: TButton;
    btnExecuteQuery: TButton;
    Label4: TLabel;
    qryAddImage: TABSQuery;
    dlgOpen: TOpenDialog;
    procedure FormCreate(Sender: TObject);
    procedure btnCreateQueryClick(Sender: TObject);
    procedure btnExecuteQueryClick(Sender: TObject);
    procedure memQueryChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  ImagePath: string;
begin
  dlgOpen.InitialDir := ExtractFilePath(Application.ExeName) + 'Images';
  // create in-memory table using FieldDefs set at design-time
  tblImages.CreateTable;
  // append sample records
  tblImages.Open;
  tblImages.Append;
  ImagePath := ExtractFilePath(Application.ExeName) + 'Images\vampire.bmp';
  tblImagesFilePath.Value := ImagePath;
  tblImagesImage.LoadFromFile(ImagePath);
  tblImages.Post;
  tblImages.Append;
  ImagePath := ExtractFilePath(Application.ExeName) + 'Images\lord.bmp';
  tblImagesFilePath.Value := ImagePath;
  tblImagesImage.LoadFromFile(ImagePath);
  tblImages.Post;
  tblImages.First;

end;

procedure TForm1.btnCreateQueryClick(Sender: TObject);
var
  MimeCoder: TStringFormat_MIME64;
  S: TMemoryStream;
begin
  if dlgOpen.Execute then
  begin
    MimeCoder := TStringFormat_MIME64.Create;
    S := TMemoryStream.Create;
    S.LoadFromFile(dlgOpen.FileName);
    try
      memQuery.Lines.Text := 'INSERT INTO Images (FilePath, Image) ' + #10 + 'VALUES (''' +
        dlgOpen.FileName + ''', ' + #10 +
        'MimeToBin(''' + MimeCoder.StrTo(S.Memory, S.Size) + '''))';
      btnExecuteQuery.Enabled := True;
    finally
      MimeCoder.Free;
      S.Free;
    end;
  end;
end;

procedure TForm1.btnExecuteQueryClick(Sender: TObject);
begin
  qryAddImage.SQL := memQuery.Lines;
  qryAddImage.ExecSQL;
  tblImages.Refresh;
end;

procedure TForm1.memQueryChange(Sender: TObject);
begin
  btnExecuteQuery.Enabled := memQuery.Text <> '';
end;

end.



Blobs In Sql Delphi Example
Download Absolute Database | Learn more


Product Info


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

downloadorder


Our Customers



Testimonials

Thanks again for the superb tech support, I was worried I'd hit a brick wall this close to the finish line. Even working on the weekend... you guys rock!!!

Bob Boyd

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