Solved

binary

Posted on 1998-12-03
8
282 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

803 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