Solved

binary

Posted on 1998-12-03
8
276 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now