Delphi (Tuxedo,bde,ado) Triad Data Set component Hstxquery
I. BACKGROUND
Why do you want to do this triad data set component? Before our company with Delphi developed systems mostly in Ado,bde way to connect the database, the two sets of components use is very convenient and flexible, the cost control is also very friendly, from the previous more than 10 years of use, the problem is not very small, the user does not have three-tier architecture requirements. But when bidding for big companies this year, they tend to be blocked by technical requirements. Party A's bid on the three-storey structure, which makes us very headache, at present, our company is using tuxedo to do the middle tier, if the transformation, then the cost is expected to be a year, two versions of the maintenance costs are very high. In the face of this situation, I put forward the idea of building a new dataset component. The new component is compatible with all of the previous query's properties and methods, just use the UE editor to replace the previous query class, and can switch between Tuxedo,bde,ado three connections, and the system does not have to maintain a different version. Thought sparse only shallow, hoped everybody many advice, grateful.
Second, the component structure diagram
From the structure diagram, you can see that the decorative mode is used, hstxquery the user's access objects behind their own, and forwarded to different objects according to the connection method. It accesses tuxedo through HsTxQuery.dll access, in the middle there is a layer of conversion, while BDE, ADO is directly connected.
Third, the design class
Iv. examples
1. Open
Procedure Tform1.button7click (Sender:tobject); Begin Hsquery2.close; HsQuery2.SQL.Text: = ' select * from users '; Hsquery2.open; End |
2. Implementation
Procedure Tform1.button7click (Sender:tobject); Begin Hsquery2.close; HsQuery2.SQL.Text: = ' Insert test value '; HsQuery2. Execsql; End |
3. Inserting 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: = ' dashing elder brother '; Hsquery2.fieldbyname (' F5 '). Asstring: = ' 1 '; Hsquery2.fieldbyname (' F6 '). Asstring: = ' 330102199001164317 '; Hsquery2.fieldbyname (' F7 '). Asstring: = ' 1 '; Hsquery2.setblobstream (Hsquery2.fieldbyname (' Fphoto '), MS); Post; Applyupdates; Commitupdates; Database.commit; End Ms. Free; End |
4. Update record
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
6, save/Fetch BLOB data
Save and view the insert example.
Procedure Tform1.button8click (Sender:tobject); Var Stream:tmemorystream; Jpg:tjpegimage; Begin Stream:=hsquery2.getblobstream (Hsquery2.fieldbyname (' DATA ')); Jpg:=tjpegimage.create; Stream.position: = 0; Jpg. Loadfromstream (Stream); Loading pictures Image2. Picture.assign (JPG); End |
7. Get field values
Procedure Tform1.button15click (Sender:tobject); Begin ShowMessage (Hsquery2.fieldbyname (' userid '). asstring); ShowMessage (Hsquery2.fields.fields[0]. asstring); End |
8. Filter
Here is the filter Hsquery2.filter: = ' userid=102 '; Hsquery2.filtered: = true; Here is the 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, Tuxedo, BDE and ADO mode dynamic switching
/ Procedure Tform1.combobox1change (Sender:tobject); Begin Case ComboBox1. ItemIndex of 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 middleware for data exchange, such as various MQ, can be packaged into easy-to-use components to make life better for developers.
Control address: https://sourceforge.net/projects/hstxqueryfordelphi/
Delphi (Tuxedo,bde,ado) Triad Data Set component Hstxquery