Solve the problem that UNIDAC cannot pass cursor refcursor to PostgreSQL in disguise

Source: Internet
Author: User

Don't say it, first on the code.

Pg:

--Establishment of T1 tableCREATE TABLE  Public. T1 (F1INTEGER  not NULL, F2VARCHAR( -), F3VARCHAR( -)[][] [],  CONSTRAINTT1_pkeyPRIMARY KEY(F1)) with(OIDs=false);--Create an array of T1 table behavior elements to replace RefcursorCREATE OR REPLACE FUNCTION  Public. FUN1 (P1 Public. t1[])RETURNS varchar [] []  as$body $DECLARERow1 Public. t1%RowType; ARR1VARCHAR [ ];BEGINFOREACH Row1incharray P1 loop arr1:=array_append (ARR1,ROW1.F2); EndLOOP; RETURNarr1;END; $body $language'Plpgsql'

Delphi:

//The table field is passed to the string in the array structure of the PG, of course, you can select the field to pass, not the fields, directly add a "," on the line.functionDataserecordtoarraystring (Acds:tdataset):string;varI:integer; Srecord:string;begin   forI: =0  toAcds.fieldcount-1  Do  begin    ifAcds.fields[i]. IsNull ThenResult:= Result +','    Else    beginSrecord:=Acds.fields[i].      asstring; ifAcds.fields[i]. DataTypeinch[Ftblob, Ftobject, Ftdataset, Ftgraphic] ThenResult:= Result +','+SrecordElse      begin
Handles escape characters If normal text can be commented out to speed up
ifSrecord.contains('"') ThenSrecord:= Srecord.replace ('"','\"\"', [Rfreplaceall]); ifSrecord.indexofany ([',',' ','{','"']) >=0 ThenSrecord:='\"'+ Srecord +'\"'; Result:= Result +','+Srecord; End; End; End; Result:='{"('+ result.substring (1) +')"}';End;//TestprocedureTform1.button1click (sender:tobject);vars, s1, S2:string;beginUniQuery1.SQL.Text:='SELECT * from T1'; Uniquery1.open; Uniquery1.first; S:=dataserecordtoarraystring (UniQuery1); Uniquery1.next; S1:=dataserecordtoarraystring (UniQuery1); Uniquery1.next; S2:=dataserecordtoarraystring (UniQuery1); withUniStoredProc1 Do beginClose; Parambyname ('P1'). Asstring: = Format ('{%s,%s,%s}', [S, S1, S2]); TryExecproc; exceptOn e:exception Do beginShowMessage (e.message); Exit; End; End; ShowMessage (fields[0]. asstring); End;End;

Solve the problem that UNIDAC cannot pass cursor refcursor to PostgreSQL in disguise

Related Article

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.