Solved

binary

Posted on 1998-12-03
8
283 Views
Last Modified: 2010-04-06
What is the fastest way to insert a record with binary data in TQuery ?

Andrew
0
Comment
Question by:andrewyu
  • 4
  • 3
8 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1349113
how do you mean?
0
 

Author Comment

by:andrewyu
ID: 1349114
How can I select the record with a field type is binary in TQuery ?

Andrew
0
 
LVL 3

Accepted Solution

by:
williams2 earned 40 total points
ID: 1349115
This will handle the record thing, isn't that what you mean?
(Just cut'n'paste to a default unit)

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

Type

  pRecord = ^TRecord;
  TRecord = record
    S: String[123];
    BlaBla: Integer;
  End;

  TData = Array[0..SizeOf(TRecord)-1] of Byte;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

  Procedure BinToRecord(pRec: pRecord; var Data: TData);
  var
    p: pByteArray;
    i: Integer;
  Begin
    p:= Pointer(pRec);
    For i:= 0 to SizeOf(TData)-1 do p[i]:= Data[i];
  End;

  Procedure RecordToBin(pRec: pRecord; var Data: TData);
  var
    p: pByteArray;
    i: Integer;
  Begin
    p:= Pointer(pRec);
    For i:= 0 to SizeOf(TData)-1 do Data[i]:= p[i];
  End;

procedure TForm1.FormCreate(Sender: TObject);
Var
  Rec1,Rec2: TRecord;
  Data: TData;
begin
  Rec1.BlaBla:= 7;
  Rec1.S:= 'Test me';
  RecordToBin(@Rec1,Data);
  BinToRecord(@Rec2,Data);
  ShowMessage(Rec2.S+' : '+IntToStr(Rec2.BlaBla));
end;

end.

0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:andrewyu
ID: 1349116
Actually, I want to know how can I locate the record by the binary field in SQL select command ?

Anyway, thank you very much !

Andrew
0
 
LVL 3

Expert Comment

by:williams2
ID: 1349117
Oh, I think I misuderstood your question then.

Under these circumstances you normally don't. What you do is to create a name for the record, and then select it by f.ex.:

"SELECT BinaryFieldname,BinaryField FROM BinTable WHERE BinaryFieldName='test'"

You normally don't want to search for a stream with the stream as a criteria. Even if it could be done, the query would be very slow. If You do not want to use names, number indexes works even better.

Cheers
Williams
0
 

Author Comment

by:andrewyu
ID: 1349118
So, do you mean the 'test' can be any ASCII code from 0-255 ?

Andrew
0
 
LVL 3

Expert Comment

by:williams2
ID: 1349119
'test' can be any name from 'A','AAA' to 'Anders', but!!!! ..SQL is NOT case-sensitive, so if you are working with strings, you should not rely on ASCII values, only if you deal with strict Char types (not ANSI, they are WideChars!)

But I ment, you should be able to index the table by some kind of primarykey, which is a unique number or name identified with the table entry, it works the same way as the handle system works in windows.

If you need any help doing it, just say so. I've done it with severel types of databases.

Regards
Williams
0
 

Author Comment

by:andrewyu
ID: 1349120
I understand and I think I will use the TTable in this case ! But, is TTable much slower than the TQuery when I use it on the Oracle, Sybase, Interbase or MS-SQL ?

Anyway, thank you very much !

Andrew
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Performance of SQL statement 37 128
Firemonkey webbrowser scrollbars ? 1 50
RESTRequest Parameter 4 43
Typecasting TBytes to Integer in Delphi XE8 2 11
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question