Solved

binary

Posted on 1998-12-03
8
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month11 days, 17 hours left to enroll

623 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