Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

binary

Posted on 1998-12-03
8
Medium Priority
?
287 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 160 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Integration Management Part 2

885 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