Delphi (Tuxedo, BDE, ADO) three-in-one dataset component HsTxQuery

Source: Internet
Author: User
I. Background Why is this three-in-one dataset component required? In the past, most of the systems developed by our company using delphi were connected to databases using ADO and BDE. These two sets of components were very convenient and flexible to use and cost control friendly, from the usage in the past 10 years, it seems that the problem is not big, and users do not have a three-tier architecture requirement. However, this year's bidding for large companies

I. Background Why is this three-in-one dataset component required? In the past, most of the systems developed by our company using delphi were connected to databases using ADO and BDE. These two sets of components were very convenient and flexible to use and cost control friendly, from the usage in the past 10 years, it seems that the problem is not big, and users do not have a three-tier architecture requirement. However, this year's bidding for large companies

I. background

Why is this three-in-one dataset component required? In the past, most of the systems developed by our company using delphi were connected to databases using ADO and BDE. These two sets of components were very convenient and flexible to use and cost control friendly, from the usage in the past 10 years, it seems that the problem is not big, and users do not have a three-tier architecture requirement. However, when bidding for large companies this year, the project is often blocked by technical requirements. Why? Party A's bidding documents contain a three-tier architecture, which is a headache for us. Currently, our company uses Tuxedo as the middle layer. If it is transformed, the cost is expected to be one year, the maintenance cost of the two versions is also very high. In the face of this situation, I propose a three-in-one approach, that is, building a new dataset component. The new component is compatible with all the attributes and methods of the previous Query. You only need to use the UE editor to replace the previous Query Class and switch between the Tuxedo, BDE, and ADO connection methods, the system does not need to maintain another version. I hope you will be grateful for your advice.

Ii. Component Structure

From the structure diagram, we can see that the decoration mode is used. HsTxQuery places the user's access object behind it and forwards it to different objects based on the connection mode. It accesses Tuxedo through HsTxQuery. dll, with a layer of conversion in the middle, while BDE and ADO are directly connected.

Iii. Design

Iv. Example

1. Open

Procedure TForm1.Button7Click (Sender: TObject );

Begin

HsQuery2.close;

HsQuery2. SQL. Text: = 'select * from users ';

HsQuery2.Open;

End;

2. Execute

Procedure TForm1.Button7Click (Sender: TObject );

Begin

HsQuery2.close;

HsQuery2. SQL. Text: = 'insert test value (1, 2, 3 )';

HsQuery2. ExecSQL;

End;

3. insert records

Procedure TForm1.Button9Click (Sender: TObject );

Var

MS: TMemoryStream;

Begin

MS: = TMemoryStream. Create;

Image2.Picture. Graphic. SaveToStream (MS );

With HsQuery2 do

Begin

Database. StartTransaction;

Append;

HsQuery2.FieldByName ('f1'). AsString: = FormatDateTime ('yyyymmddhhmmss ', now );

HsQuery2.FieldByName ('F2'). AsString: = FormatDateTime ('yyyymmdd', now );

HsQuery2.FieldByName ('f3 '). AsString: = FormatDateTime ('hhmmss', now );

HsQuery2.FieldByName ('F4'). AsString: = 'chic go ';

HsQuery2.FieldByName ('f5'). AsString: = '1 ';

HsQuery2.FieldByName ('f6 '). AsString: = '000000 ';

HsQuery2.FieldByName ('f7 '). AsString: = '1 ';

HsQuery2.SetBlobStream (HsQuery2.FieldByName ('fphoto '), MS );

Post;

ApplyUpdates;

CommitUpdates;

Database. Commit;

End;

Ms. Free;

End;

4. update records

Procedure TForm1.Button10Click (Sender: TObject );

Var

Ms: TMemoryStream;

Begin

Ms: = TMemoryStream. Create;

Image2.Picture. Graphic. SaveToStream (MS );

HsQuery2.Edit;

HsQuery2.Fields. Fields [0]. AsString: = '6 ';

HsQuery2.Fields. Fields [1]. AsInteger: = 198;

HsQuery2.Fields. Fields [2]. AsString: = '';

HsQuery2.Fields. Fields [3]. AsString: = 'roy ';

HsQuery2.Fields. Fields [4]. AsString: = '1 ';

HsQuery2.Fields. Fields [5]. AsString: = '2 ';

HsQuery2.SetBlobStream (HsQuery2.Fields. Fields [6], MS );

HsQuery2.Post;

HsQuery2.ApplyUpdates;

HsQuery2.CommitUpdates;

Ms. Free;

End;

5. delete records

HsQuery2.Delete;

6. Save/retrieve Blob Data

To view the insert example.

Procedure TForm1.Button8Click (Sender: TObject );

Var

Stream: TMemoryStream;

Jpg: tsf-image;

Begin

Stream: = HsQuery2.GetBlobStream (HsQuery2.FieldByName ('data '));

Jpg: = tsf-image. Create;

Stream. Position: = 0;

Jpg. LoadFromStream (Stream); // load the image

Image2.Picture. Assign (Jpg );

End;

7. Obtain the field value

Procedure TForm1.Button15Click (Sender: TObject );

Begin

ShowMessage (hsQuery2.FieldByName ('userid'). AsString );

ShowMessage (hsQuery2.Fields. Fields [0]. AsString );

End;

8. Filter

// Filter

HsQuery2.Filter: = 'userid = 102 ';

HsQuery2.Filtered: = true;

// The following is anti-Filtering

HsQuery2.Filter: = '';

HsQuery2.Filtered: = true;

9. Parameters

/

Procedure TForm1.Button16Click (Sender: TObject );

Begin

With hsquery2 do

Begin

Close;

SQL. clear;

SQL. Text: = 'select * From users where USERID =: id ';

ParamByName ('id'). value: = 106;

Open;

End;

End;

10. Dynamic switching of Tuxedo, BDE, and ADO Modes

/

Procedure TForm1.ComboBox1Change (Sender: TObject );

Begin

Case combobox1.ItemIndex

0:

Begin

HsQuery2.DatasetType: = dtTuxedo;

HsQuery2.ConnectionString: = '// 192.168.1.121: 8887 ';

End;

1:

Begin

HsQuery2.DatasetType: = dtBDE;

HsQuery2.ConnectionString: = 'orcl ';

HsQuery2.Connection: = Database1;

End;

2:

Begin

HsQuery2.DatasetType: = dtADO;

HsQuery2.ConnectionString: = 'provider = OraOLEDB. Oracle.1; Password = gf; Persist Security Info = True; User ID = gf; Data Source = orcl; Extended Properties = ""';

HsQuery2.Connection: = ADOConnection1;

End;

End;

End;

V. Outlook

Many data-exchange middleware (such as various MQ) can be encapsulated into easy-to-use components to make the developer's life better.

Control Address: https://sourceforge.net/projects/hstxqueryfordelphi/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.